felixmortas commited on
Commit
610ca2c
·
1 Parent(s): b66056e

System prompt improving

Browse files
Files changed (3) hide show
  1. app.py +4 -4
  2. react_agent.py +19 -8
  3. requirements.txt +0 -1
app.py CHANGED
@@ -81,7 +81,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
81
 
82
  try:
83
  # Build new client with other provider and retry
84
- agent = ReActAgent(provider="Google", model="gemini-2.5-pro")
85
  submitted_answer = agent(str(item))
86
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
87
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
@@ -91,7 +91,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
91
  print(f"Error running agent on task {task_id}: {e}")
92
 
93
  try:
94
- agent = ReActAgent(provider="Mistral", model="mistral-large-latest")
95
  submitted_answer = agent(str(item))
96
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
97
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
@@ -127,8 +127,8 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
127
  print(f"Error running agent on task {task_id}: {e}")
128
  results_log.append({"Task ID": task_id, "Question": question_text, "Error": e})
129
 
130
- # Wait for a while to ensure the agent is not overwhelmed
131
- time.sleep(10)
132
 
133
  if not answers_payload:
134
  print("Agent did not produce any answers to submit.")
 
81
 
82
  try:
83
  # Build new client with other provider and retry
84
+ agent = ReActAgent(provider="Mistral", model="mistral-large-latest")
85
  submitted_answer = agent(str(item))
86
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
87
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
 
91
  print(f"Error running agent on task {task_id}: {e}")
92
 
93
  try:
94
+ agent = ReActAgent(provider="Google", model="gemini-2.5-flash")
95
  submitted_answer = agent(str(item))
96
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
97
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
 
127
  print(f"Error running agent on task {task_id}: {e}")
128
  results_log.append({"Task ID": task_id, "Question": question_text, "Error": e})
129
 
130
+ # Wait for a while to ensure the model API doesn't reach the rate limit
131
+ time.sleep(60)
132
 
133
  if not answers_payload:
134
  print("Agent did not produce any answers to submit.")
react_agent.py CHANGED
@@ -8,7 +8,7 @@ from langgraph.prebuilt import create_react_agent
8
  from custom_tools import custom_tools
9
 
10
  class ReActAgent:
11
- def __init__(self, provider: str="Google", model: str="gemini-2.5-flash"):
12
  print('Initializing ReActAgent...')
13
  load_dotenv()
14
 
@@ -39,13 +39,24 @@ class ReActAgent:
39
  max_retries=5
40
  )
41
 
42
- sys_prompt = "You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, DON'T use comma to write your number NEITHER use units such as $ or percent sign unless specified otherwise. If you are asked for a string, DON'T use articles, NEITHER abbreviations (e.g. for cities) capitalize the first letter, and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending, unless the first letter capitalization, whether the element to be put in the list is a number or a string.\n\n\n \
43
- \n \
44
- You will be provided with tools to help you answer questions.\n \
45
- If you are asked to make a calculation, absolutely use the tools provided to you. You should AVOID calculating by yourself and ABSOLUTELY use appropriate tools.\n \
46
- If you need to search for information, use the web_search tool rather than wiki_search, unless the question specifies searching on wikipedia. After using the web_search tool, look for the first URL provided with the url_search tool and ask yourself if the answer is in the tool response. If it is, answer the question. If not, search on other links.\n \
47
- \n \
48
- If needed, use one tool first, then use the output of that tool as an input to another thinking then to the use of another tool."
 
 
 
 
 
 
 
 
 
 
 
49
  # Build the ReAct agent
50
  self.agent = create_react_agent(
51
  model=llm,
 
8
  from custom_tools import custom_tools
9
 
10
  class ReActAgent:
11
+ def __init__(self, provider: str="Google", model: str="gemini-2.5-pro"):
12
  print('Initializing ReActAgent...')
13
  load_dotenv()
14
 
 
39
  max_retries=5
40
  )
41
 
42
+ sys_prompt = """
43
+ You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER].\n
44
+ \n
45
+ YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, DON'T use comma to write your number NEITHER use units such as $ or percent sign unless specified otherwise. If you are asked for a string, DON'T use articles, NEITHER abbreviations (e.g. for cities) capitalize the first letter, and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending, unless the first letter capitalization, whether the element to be put in the list is a number or a string.\n
46
+ \n
47
+ EXAMPLES:\n
48
+ - What is US President Obama's first name? FINAL ANSWER: Barack\n
49
+ - What are the 3 mandatory ingredients for pancakes? FINAL ANSWER: eggs, flour, milk\n
50
+ - What is the final cost of an invoice comprising a $345.00 product and a $355.00 product? Provide the answer with two decimals. FINAL ANSWER: 700.00\n
51
+ - How many pairs of chromosomes does a human cell contain? FINAL ANSWER : 23\n
52
+ \n
53
+ \n
54
+ You will be provided with tools to help you answer questions.\n
55
+ If you are asked to make a calculation, absolutely use the tools provided to you. You should AVOID calculating by yourself and ABSOLUTELY use appropriate tools.\n
56
+ If you need to search for information, use the web_search tool rather than wiki_search, unless the question specifies searching on wikipedia. After using the web_search tool, look for the first URL provided with the url_search tool and ask yourself if the answer is in the tool response. If it is, answer the question. If not, search on other links.\n
57
+ \n
58
+ If needed, use one tool first, then use the output of that tool as an input to another thinking then to the use of another tool.
59
+ """
60
  # Build the ReAct agent
61
  self.agent = create_react_agent(
62
  model=llm,
requirements.txt CHANGED
@@ -1,5 +1,4 @@
1
  beautifulsoup4==4.12.3
2
- duckduckgo-search==8.0.4
3
  gradio
4
  langchain==0.3.26
5
  langchain_community==0.3.26
 
1
  beautifulsoup4==4.12.3
 
2
  gradio
3
  langchain==0.3.26
4
  langchain_community==0.3.26