Spaces:
Sleeping
Sleeping
fix: indentation
Browse files- basic_agent.py +33 -33
basic_agent.py
CHANGED
@@ -159,39 +159,39 @@ class ToolAgent:
|
|
159 |
|
160 |
def chat(self, query:str, metadata):
|
161 |
"""Perform a single step in the conversation with the tool agent executor."""
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
|
196 |
|
197 |
def invoke(self, q_data):
|
|
|
159 |
|
160 |
def chat(self, query:str, metadata):
|
161 |
"""Perform a single step in the conversation with the tool agent executor."""
|
162 |
+
if metadata is None:
|
163 |
+
metadata = {}
|
164 |
+
|
165 |
+
with_attachments = False
|
166 |
+
query_message = HumanMessage(content=query)
|
167 |
+
|
168 |
+
if "image_path" in metadata:
|
169 |
+
|
170 |
+
# Create a HumanMessage with image content
|
171 |
+
query_message = HumanMessage(
|
172 |
+
content=[
|
173 |
+
{"type": "text", "text": query},
|
174 |
+
{"type": "text", "text": f"image_path: {metadata['image_path']}"},
|
175 |
+
]
|
176 |
+
)
|
177 |
+
with_attachments = True
|
178 |
+
|
179 |
+
user_message = {'role': 'user', 'content': query if not with_attachments else query_message}
|
180 |
+
print_conversation([user_message])
|
181 |
+
|
182 |
+
response = self.executor.invoke({
|
183 |
+
"query": query if not with_attachments else query_message,
|
184 |
+
})
|
185 |
+
response_message = {'role': 'assistant', 'content': response}
|
186 |
+
print_conversation([response_message])
|
187 |
+
|
188 |
+
final_answer = generate_final_answer({
|
189 |
+
'query': query,
|
190 |
+
'response': response,
|
191 |
+
})
|
192 |
+
final_answer_message = {'role': 'Final Answer', 'content': final_answer}
|
193 |
+
print_conversation([final_answer_message])
|
194 |
+
return final_answer
|
195 |
|
196 |
|
197 |
def invoke(self, q_data):
|