diff --git a/literalai/api/__init__.py b/literalai/api/__init__.py index 286734e..e30a09d 100644 --- a/literalai/api/__init__.py +++ b/literalai/api/__init__.py @@ -182,7 +182,6 @@ def raise_error(error): raise Exception(error) variables = self._prepare_variables(variables) - with httpx.Client() as client: response = client.post( self.graphql_endpoint, @@ -191,8 +190,10 @@ def raise_error(error): timeout=10, ) - if response.status_code >= 400: - raise_error(response.text) + try: + response.raise_for_status() + except httpx.HTTPStatusError: + raise_error(f"Failed to {description}: {response.text}") json = response.json() @@ -232,7 +233,13 @@ def make_rest_call(self, subpath: str, body: Dict[str, Any]) -> Dict: timeout=20, ) - response.raise_for_status() + try: + response.raise_for_status() + except httpx.HTTPStatusError: + message = f"Failed to call {subpath}: {response.text}" + logger.error(message) + raise Exception(message) + json = response.json() return json @@ -1217,7 +1224,9 @@ def add_generation_to_dataset( # Prompt API - def get_or_create_prompt_lineage(self, name: str, description: Optional[str] = None): + def get_or_create_prompt_lineage( + self, name: str, description: Optional[str] = None + ): """ Creates a prompt lineage with the specified name and optional description. If the prompt lineage with that name already exists, it is returned. @@ -1298,7 +1307,7 @@ def get_prompt( return self.gql_helper(*get_prompt_helper(self, name=name, version=version)) else: raise ValueError("Either the `id` or the `name` must be provided.") - + def promote_prompt(self, name: str, version: int) -> str: """ Promotes the prompt with name to target version. @@ -1315,7 +1324,6 @@ def promote_prompt(self, name: str, version: int) -> str: return self.gql_helper(*promote_prompt_helper(lineage_id, version)) - # Misc API def get_my_project_id(self): @@ -1364,8 +1372,10 @@ def raise_error(error): timeout=10, ) - if response.status_code >= 400: - raise_error(response.text) + try: + response.raise_for_status() + except httpx.HTTPStatusError: + raise_error(f"Failed to {description}: {response.text}") json = response.json() @@ -1405,7 +1415,13 @@ async def make_rest_call(self, subpath: str, body: Dict[str, Any]) -> Dict: timeout=20, ) - response.raise_for_status() + try: + response.raise_for_status() + except httpx.HTTPStatusError: + message = f"Failed to call {subpath}: {response.text}" + logger.error(message) + raise Exception(message) + json = response.json() return json @@ -2406,10 +2422,14 @@ async def add_generation_to_dataset( # Prompt API - async def get_or_create_prompt_lineage(self, name: str, description: Optional[str] = None): + async def get_or_create_prompt_lineage( + self, name: str, description: Optional[str] = None + ): return await self.gql_helper(*create_prompt_lineage_helper(name, description)) - get_or_create_prompt_lineage.__doc__ = LiteralAPI.get_or_create_prompt_lineage.__doc__ + get_or_create_prompt_lineage.__doc__ = ( + LiteralAPI.get_or_create_prompt_lineage.__doc__ + ) @deprecated('Please use "get_or_create_prompt_lineage" instead.') async def create_prompt_lineage(self, name: str, description: Optional[str] = None): @@ -2476,4 +2496,3 @@ async def get_my_project_id(self): return response["projectId"] get_my_project_id.__doc__ = LiteralAPI.get_my_project_id.__doc__ - diff --git a/literalai/version.py b/literalai/version.py index ea9f970..19b910f 100644 --- a/literalai/version.py +++ b/literalai/version.py @@ -1 +1 @@ -__version__ = "0.0.603" +__version__ = "0.0.604" diff --git a/setup.py b/setup.py index bda0286..61def25 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="literalai", - version="0.0.603", # update version in literalai/version.py + version="0.0.604", # update version in literalai/version.py description="An SDK for observability in Python applications", author="Literal AI", package_data={"literalai": ["py.typed"]},