luke9705 commited on
Commit
698b66e
·
1 Parent(s): 7e6a4a7

Enhance agent call method to include conversation history and update system prompt for image handling

Browse files
Files changed (2) hide show
  1. app.py +9 -5
  2. system_prompt.txt +1 -1
app.py CHANGED
@@ -148,27 +148,31 @@ class Agent:
148
 
149
  #print("System prompt:", self.agent.prompt_templates["system_prompt"])
150
 
151
- def __call__(self, message: str, images: Optional[list[Image.Image]] = None, files: Optional[str] = None) -> str:
152
- answer = self.agent.run(message, images = images, additional_args={"files": files})
 
 
 
153
  return answer
154
 
155
  ## gradio functions
156
  def respond(message: str, history : dict):
157
 
158
  # input
 
159
  text = message.get("text", "")
160
  if not message.get("files"): # no files uploaded
161
  print("No files received.")
162
- message = agent(text)
163
  else:
164
  files = message.get("files", [])
165
  print(f"files received: {files}")
166
  if is_image_extension(files[0]):
167
  image = load_file(files[0]) # assuming only one file is uploaded at a time (gradio default behavior)
168
- message = agent(text, images=image)
169
  else:
170
  file = load_file(files[0])
171
- message = agent(text, files=file)
172
 
173
  # output
174
  print("Agent response:", message)
 
148
 
149
  #print("System prompt:", self.agent.prompt_templates["system_prompt"])
150
 
151
+ def __call__(self, message: str,
152
+ images: Optional[list[Image.Image]] = None,
153
+ files: Optional[str] = None,
154
+ conversation_history: Optional[dict] = None) -> str:
155
+ answer = self.agent.run(message, images = images, additional_args={"files": files, "conversation_history": conversation_history})
156
  return answer
157
 
158
  ## gradio functions
159
  def respond(message: str, history : dict):
160
 
161
  # input
162
+ print("history:", history)
163
  text = message.get("text", "")
164
  if not message.get("files"): # no files uploaded
165
  print("No files received.")
166
+ message = agent(text, conversation_history=history) # conversation_history is a dict with the history of the conversation
167
  else:
168
  files = message.get("files", [])
169
  print(f"files received: {files}")
170
  if is_image_extension(files[0]):
171
  image = load_file(files[0]) # assuming only one file is uploaded at a time (gradio default behavior)
172
+ message = agent(text, images=image, conversation_history=history)
173
  else:
174
  file = load_file(files[0])
175
+ message = agent(text, files=file, conversation_history=history)
176
 
177
  # output
178
  print("Agent response:", message)
system_prompt.txt CHANGED
@@ -323,7 +323,7 @@ It is MANDATORY to use these rules for the 'final_answer' tool:
323
  • [gr.Image(value=“output.png”), “Here is the chart.”]
324
  • [gr.File(value=“report.pdf”), “Download the report.”]
325
  7. Any deviation (returning a dict, tuple, raw PIL image, etc.) is invalid.
326
- 8. Always put the images in the list, do NOT generate external link.
327
 
328
  Now Begin!
329
 
 
323
  • [gr.Image(value=“output.png”), “Here is the chart.”]
324
  • [gr.File(value=“report.pdf”), “Download the report.”]
325
  7. Any deviation (returning a dict, tuple, raw PIL image, etc.) is invalid.
326
+ 8. Always put generated images in the list, do NOT create external link.
327
 
328
  Now Begin!
329