Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix fstring #111

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions literalai/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ def raise_error(error):
json = response.json()
except ValueError as e:
raise_error(
f"Failed to parse JSON response: {e}, content: {response.content!r}"
f"""Failed to parse JSON response: {
e}, content: {response.content!r}"""
)

if json.get("errors"):
Expand All @@ -238,7 +239,8 @@ def raise_error(error):
for key, value in json["data"].items():
if value and value.get("ok") is False:
raise_error(
f"Failed to {description}: {value.get('message')}"
f"""Failed to {description}: {
value.get('message')}"""
)

return json
Expand Down Expand Up @@ -277,7 +279,8 @@ def make_rest_call(self, subpath: str, body: Dict[str, Any]) -> Dict:
return response.json()
except ValueError as e:
raise ValueError(
f"Failed to parse JSON response: {e}, content: {response.content!r}"
f"""Failed to parse JSON response: {
e}, content: {response.content!r}"""
)

def gql_helper(
Expand Down Expand Up @@ -695,14 +698,15 @@ def upload_file(
fields: Dict = request_dict.get("fields", {})
object_key: Optional[str] = fields.get("key")
upload_type: Literal["raw", "multipart"] = cast(
Literal["raw", "multipart"], request_dict.get("uploadType", "multipart")
Literal["raw", "multipart"], request_dict.get(
"uploadType", "multipart")
)
signed_url: Optional[str] = json_res.get("signedUrl")

# Prepare form data
form_data = (
{}
) # type: Dict[str, Union[Tuple[Union[str, None], Any], Tuple[Union[str, None], Any, Any]]]
) # type: Dict[str, Union[Tuple[Union[str, None], Any], Tuple[Union[str, None], Any, Any]]]
for field_name, field_value in fields.items():
form_data[field_name] = (None, field_value)

Expand Down Expand Up @@ -772,7 +776,8 @@ def create_attachment(
if active_steps := active_steps_var.get([]):
step_id = active_steps[-1].id
else:
raise Exception("No step_id provided and no active step found.")
raise Exception(
"No step_id provided and no active step found.")

(
query,
Expand All @@ -794,7 +799,8 @@ def create_attachment(
)

if content:
uploaded = self.upload_file(content=content, thread_id=thread_id, mime=mime)
uploaded = self.upload_file(
content=content, thread_id=thread_id, mime=mime)

if uploaded["object_key"] is None or uploaded["url"] is None:
raise Exception("Failed to upload file")
Expand Down Expand Up @@ -1002,7 +1008,7 @@ def send_steps(self, steps: List[Union[StepDict, "Step"]]):
Sends a list of steps to be processed.

Args:
steps (List[Union[StepDict, "Step"]]): A list of steps or step dictionaries to send.
steps (List[Union[StepDict, Step]]): A list of steps or step dictionaries to send.

Returns:
The result of the GraphQL helper function for sending steps.
Expand Down Expand Up @@ -1448,7 +1454,8 @@ def raise_error(error):
json = response.json()
except ValueError as e:
raise_error(
f"Failed to parse JSON response: {e}, content: {response.content!r}"
f"""Failed to parse JSON response: {
e}, content: {response.content!r}"""
)

if json.get("errors"):
Expand All @@ -1459,7 +1466,8 @@ def raise_error(error):
for key, value in json["data"].items():
if value and value.get("ok") is False:
raise_error(
f"Failed to {description}: {value.get('message')}"
f"""Failed to {description}: {
value.get('message')}"""
)

return json
Expand Down Expand Up @@ -1498,7 +1506,8 @@ async def make_rest_call(self, subpath: str, body: Dict[str, Any]) -> Dict:
return response.json()
except ValueError as e:
raise ValueError(
f"Failed to parse JSON response: {e}, content: {response.content!r}"
f"""Failed to parse JSON response: {
e}, content: {response.content!r}"""
)

async def gql_helper(
Expand Down Expand Up @@ -1943,14 +1952,15 @@ async def upload_file(
fields: Dict = request_dict.get("fields", {})
object_key: Optional[str] = fields.get("key")
upload_type: Literal["raw", "multipart"] = cast(
Literal["raw", "multipart"], request_dict.get("uploadType", "multipart")
Literal["raw", "multipart"], request_dict.get(
"uploadType", "multipart")
)
signed_url: Optional[str] = json_res.get("signedUrl")

# Prepare form data
form_data = (
{}
) # type: Dict[str, Union[Tuple[Union[str, None], Any], Tuple[Union[str, None], Any, Any]]]
{}
) # type: Dict[str, Union[Tuple[Union[str, None], Any], Tuple[Union[str, None], Any, Any]]]
for field_name, field_value in fields.items():
form_data[field_name] = (None, field_value)

Expand Down Expand Up @@ -2231,7 +2241,7 @@ async def send_steps(self, steps: List[Union[StepDict, "Step"]]):
Asynchronously sends a list of steps to be processed.

Args:
steps (List[Union[StepDict, "Step"]]): A list of steps or step dictionaries to send.
steps (List[Union[StepDict, Step]]): A list of steps or step dictionaries to send.

Returns:
The result of the GraphQL helper function for sending steps.
Expand Down
Loading