nikhmr1235 commited on
Commit
54b0824
·
verified ·
1 Parent(s): 99f608e

try chess use-case only

Browse files
Files changed (1) hide show
  1. app.py +19 -23
app.py CHANGED
@@ -52,24 +52,32 @@ class BasicAgent:
52
  self.handle_parsing_errors: bool = handle_parsing_errors
53
  self.max_iterations: int = max_iterations
54
  self.memory: Optional[ConversationSummaryMemory] = memory
 
 
 
 
 
 
 
 
55
 
56
 
57
  def is_retriable(self, e: Exception) -> bool:
58
  # Adjust this check if your error type is different
59
  return isinstance(e, genai.errors.APIError) and getattr(e, "code", None) in {429, 503}
60
 
61
- def invoke_with_retry(self, agent_obj, question: str, max_retries: int = 5, initial_delay: float = 10.0) -> str:
62
  delay = initial_delay
63
  for attempt in range(max_retries):
64
  try:
65
- result = agent_obj.invoke(
66
  {"input": question},
67
  config={"configurable": {"session_id": "test-session"}},
68
  )
69
  return result['output']
70
  except Exception as e:
71
  if self.is_retriable(e):
72
- print(f"Quota error (attempt {attempt+1}/{max_retries}), retrying in {delay} seconds...")
73
  time.sleep(delay)
74
  delay *= 2 # Exponential backoff
75
  else:
@@ -80,22 +88,8 @@ class BasicAgent:
80
  """
81
  Allows the instance to be called directly to get an AgentExecutor.
82
  """
83
- agent_obj = self.create_agent_helper()
84
- return self.invoke_with_retry(agent_obj, question)
85
-
86
-
87
- def create_agent_helper(self) -> AgentExecutor:
88
- """
89
- Creates and returns an AgentExecutor instance.
90
- """
91
- return AgentExecutor(
92
- agent=self.agent,
93
- tools=self.tools,
94
- verbose=self.verbose,
95
- handle_parsing_errors=self.handle_parsing_errors,
96
- max_iterations=self.max_iterations,
97
- memory=self.memory
98
- )
99
 
100
 
101
 
@@ -177,7 +171,9 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
177
 
178
 
179
  If you have sufficient information and can provide a CONCISE response, or if no tool is needed, you MUST use this precise format:
180
-
 
 
181
  Thought: I have enough information, or no tool is needed.
182
  Final Answer: [your concise response here]
183
 
@@ -285,11 +281,11 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
285
  full_question_for_agent += f"\n\nAttachment '{file_name}' available at EXACT URL: {attachment_url}"
286
  #print(f"Running agent on task {task_id}: {full_question_for_agent}",flush=True)
287
 
288
- '''
289
- if task_id != "1f975693-876d-457b-a649-393859e79bf3":
290
  print("NFLUSH Skip tasks that are not the specific one we want to run", flush=True)
291
  continue # Skip tasks that are not the specific one we want to run
292
- '''
293
  try:
294
  time.sleep(5) # Add a 5 sec delay before running the agent
295
  submitted_answer = agent(full_question_for_agent)
 
52
  self.handle_parsing_errors: bool = handle_parsing_errors
53
  self.max_iterations: int = max_iterations
54
  self.memory: Optional[ConversationSummaryMemory] = memory
55
+ self.agent_obj = AgentExecutor(
56
+ agent=self.agent,
57
+ tools=self.tools,
58
+ verbose=self.verbose,
59
+ handle_parsing_errors=self.handle_parsing_errors,
60
+ max_iterations=self.max_iterations,
61
+ memory=self.memory
62
+ )
63
 
64
 
65
  def is_retriable(self, e: Exception) -> bool:
66
  # Adjust this check if your error type is different
67
  return isinstance(e, genai.errors.APIError) and getattr(e, "code", None) in {429, 503}
68
 
69
+ def invoke_with_retry(self,question: str, max_retries: int = 5, initial_delay: float = 10.0) -> str:
70
  delay = initial_delay
71
  for attempt in range(max_retries):
72
  try:
73
+ result = self.agent_obj.invoke(
74
  {"input": question},
75
  config={"configurable": {"session_id": "test-session"}},
76
  )
77
  return result['output']
78
  except Exception as e:
79
  if self.is_retriable(e):
80
+ print(f"Quota error (attempt {attempt+1}/{max_retries}), retrying in {delay} seconds...",flush=True)
81
  time.sleep(delay)
82
  delay *= 2 # Exponential backoff
83
  else:
 
88
  """
89
  Allows the instance to be called directly to get an AgentExecutor.
90
  """
91
+ #agent_obj = self.create_agent_helper()
92
+ return self.invoke_with_retry(question)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
 
95
 
 
171
 
172
 
173
  If you have sufficient information and can provide a CONCISE response, or if no tool is needed, you MUST use this precise format:
174
+ if you can use a LLM to answer the question, think step-by-step and then answer the question.
175
+ Example: given a chess board image and asked to predict the next best move, if Multi-modal LLM is available, you can use it to answer the question.
176
+
177
  Thought: I have enough information, or no tool is needed.
178
  Final Answer: [your concise response here]
179
 
 
281
  full_question_for_agent += f"\n\nAttachment '{file_name}' available at EXACT URL: {attachment_url}"
282
  #print(f"Running agent on task {task_id}: {full_question_for_agent}",flush=True)
283
 
284
+
285
+ if task_id != "cca530fc-4052-43b2-b130-b30968d8aa44":
286
  print("NFLUSH Skip tasks that are not the specific one we want to run", flush=True)
287
  continue # Skip tasks that are not the specific one we want to run
288
+
289
  try:
290
  time.sleep(5) # Add a 5 sec delay before running the agent
291
  submitted_answer = agent(full_question_for_agent)