Skip to content

Commit

Permalink
DH-4654/adding google api exceptions to the agent
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadrezaPourreza committed Sep 13, 2023
1 parent c167a43 commit 3f0a651
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion dataherald/sql_generator/dataherald_sqlagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import numpy as np
import openai
import pandas as pd
from google.api_core.exceptions import GoogleAPIError
from langchain.agents.agent import AgentExecutor
from langchain.agents.agent_toolkits.base import BaseToolkit
from langchain.agents.mrkl.base import ZeroShotAgent
Expand Down Expand Up @@ -87,7 +88,7 @@


def catch_exceptions(max_handling_list): # noqa: C901
def decorator(fn: Callable[[str], str]) -> Callable[[str], str]:
def decorator(fn: Callable[[str], str]) -> Callable[[str], str]: # noqa: C901
@wraps(fn)
def wrapper(*args: Any, **kwargs: Any) -> Any: # noqa: PLR0911
nonlocal max_handling_list
Expand Down Expand Up @@ -116,6 +117,8 @@ def wrapper(*args: Any, **kwargs: Any) -> Any: # noqa: PLR0911
return f"OpenAI API service unavailable: {e}"
except openai.error.InvalidRequestError as e:
return f"OpenAI API request was invalid: {e}"
except GoogleAPIError as e:
return f"Google API returned an error: {e}"
except SQLAlchemyError as e:
return f"Error: {e}"

Expand Down

0 comments on commit 3f0a651

Please sign in to comment.