From 7a8b299648e59b2168904dfed85c497e1ca4a7c5 Mon Sep 17 00:00:00 2001 From: Dan Constantini Date: Tue, 20 Aug 2024 10:28:44 +0200 Subject: [PATCH 1/2] fix fstring --- literalai/api/__init__.py | 40 +++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/literalai/api/__init__.py b/literalai/api/__init__.py index fd2413d..05ccb58 100644 --- a/literalai/api/__init__.py +++ b/literalai/api/__init__.py @@ -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"): @@ -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 @@ -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( @@ -695,14 +698,16 @@ 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) @@ -772,7 +777,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, @@ -794,7 +800,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") @@ -1002,7 +1009,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. @@ -1448,7 +1455,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"): @@ -1459,7 +1467,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 @@ -1498,7 +1507,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( @@ -1943,14 +1953,16 @@ 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) @@ -2231,7 +2243,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. From 8bb43ce668e75ae29fd45df692de940ce973fa86 Mon Sep 17 00:00:00 2001 From: Dan Constantini Date: Tue, 20 Aug 2024 15:42:28 +0200 Subject: [PATCH 2/2] fix lint --- literalai/api/__init__.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/literalai/api/__init__.py b/literalai/api/__init__.py index 05ccb58..480a185 100644 --- a/literalai/api/__init__.py +++ b/literalai/api/__init__.py @@ -706,8 +706,7 @@ def upload_file( # 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) @@ -1960,9 +1959,8 @@ async def upload_file( # 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)