Skip to content

Commit fc4c890

Browse files
committed
composiio error
1 parent fc02a7f commit fc4c890

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

Diff for: ai_agent_tutorials/ai_lead_generation_agent/ai_lead_generation_agent.py

+27-7
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,28 @@ def format_user_info_to_flattened_json(user_info_list: List[dict]) -> List[dict]
9191

9292
def create_google_sheets_agent(composio_api_key: str, openai_api_key: str) -> Agent:
9393
composio_toolset = ComposioToolSet(api_key=composio_api_key)
94-
google_sheets_tool = composio_toolset.get_tools(actions=[Action.GOOGLESHEETS_SHEET_FROM_JSON])[0]
94+
google_sheets_tool = composio_toolset.get_tools(actions=['GOOGLESHEETS_SHEET_FROM_JSON'])
9595

9696
google_sheets_agent = Agent(
97-
model=OpenAIChat(id="gpt-4o-mini", api_key=openai_api_key),
97+
model=OpenAIChat(id="gpt-4o", api_key=openai_api_key),
9898
tools=[google_sheets_tool],
9999
show_tool_calls=True,
100-
system_prompt="You are an expert at creating and updating Google Sheets. You will be given user information in JSON format, and you need to write it into a new Google Sheet.",
100+
description="You are an expert at creating and updating Google Sheets. You will be given user information in JSON format, and you need to write it into a new Google Sheet.",
101101
markdown=True
102102
)
103103
return google_sheets_agent
104104

105105
def write_to_google_sheets(flattened_data: List[dict], composio_api_key: str, openai_api_key: str) -> str:
106+
# Add data validation
107+
if not flattened_data:
108+
st.warning("No data to write to Google Sheets.")
109+
return None
110+
111+
# Debug the data structure
112+
st.write(f"Data to write: {len(flattened_data)} records")
113+
if len(flattened_data) > 0:
114+
st.write("Sample record:", flattened_data[0])
115+
106116
google_sheets_agent = create_google_sheets_agent(composio_api_key, openai_api_key)
107117

108118
try:
@@ -115,17 +125,27 @@ def write_to_google_sheets(flattened_data: List[dict], composio_api_key: str, op
115125

116126
create_sheet_response = google_sheets_agent.run(message)
117127

128+
# Add debugging output to see the actual response
129+
st.write("Google Sheets API Response:", create_sheet_response.content)
130+
118131
if "https://docs.google.com/spreadsheets/d/" in create_sheet_response.content:
119132
google_sheets_link = create_sheet_response.content.split("https://docs.google.com/spreadsheets/d/")[1].split(" ")[0]
120133
return f"https://docs.google.com/spreadsheets/d/{google_sheets_link}"
121-
except Exception:
122-
pass
134+
else:
135+
# If the link format is different, log the entire response
136+
st.error(f"Could not find Google Sheets link in response: {create_sheet_response.content}")
137+
except Exception as e:
138+
# Improve error handling to see what's going wrong
139+
st.error(f"Error creating Google Sheet: {str(e)}")
140+
import traceback
141+
st.error(traceback.format_exc())
142+
123143
return None
124144

125145
def create_prompt_transformation_agent(openai_api_key: str) -> Agent:
126146
return Agent(
127-
model=OpenAIChat(id="gpt-4o-mini", api_key=openai_api_key),
128-
system_prompt="""You are an expert at transforming detailed user queries into concise company descriptions.
147+
model=OpenAIChat(id="gpt-4o", api_key=openai_api_key),
148+
description="""You are an expert at transforming detailed user queries into concise company descriptions.
129149
Your task is to extract the core business/product focus in 3-4 words.
130150
131151
Examples:

0 commit comments

Comments
 (0)