@@ -91,18 +91,28 @@ def format_user_info_to_flattened_json(user_info_list: List[dict]) -> List[dict]
91
91
92
92
def create_google_sheets_agent (composio_api_key : str , openai_api_key : str ) -> Agent :
93
93
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' ])
95
95
96
96
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 ),
98
98
tools = [google_sheets_tool ],
99
99
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." ,
101
101
markdown = True
102
102
)
103
103
return google_sheets_agent
104
104
105
105
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
+
106
116
google_sheets_agent = create_google_sheets_agent (composio_api_key , openai_api_key )
107
117
108
118
try :
@@ -115,17 +125,27 @@ def write_to_google_sheets(flattened_data: List[dict], composio_api_key: str, op
115
125
116
126
create_sheet_response = google_sheets_agent .run (message )
117
127
128
+ # Add debugging output to see the actual response
129
+ st .write ("Google Sheets API Response:" , create_sheet_response .content )
130
+
118
131
if "https://docs.google.com/spreadsheets/d/" in create_sheet_response .content :
119
132
google_sheets_link = create_sheet_response .content .split ("https://docs.google.com/spreadsheets/d/" )[1 ].split (" " )[0 ]
120
133
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
+
123
143
return None
124
144
125
145
def create_prompt_transformation_agent (openai_api_key : str ) -> Agent :
126
146
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.
129
149
Your task is to extract the core business/product focus in 3-4 words.
130
150
131
151
Examples:
0 commit comments