bstraehle commited on
Commit
a9c7e42
·
verified ·
1 Parent(s): 08daa84

Update agents.py

Browse files
Files changed (1) hide show
  1. agents.py +50 -50
agents.py CHANGED
@@ -1,18 +1,18 @@
1
- import os
2
 
3
  #from langchain.agents import load_tools
4
- from openai import OpenAI
5
  #from openinference.instrumentation.smolagents import SmolagentsInstrumentor
6
  #from phoenix.otel import register
7
- from smolagents import (
8
- CodeAgent,
9
- ToolCallingAgent,
10
- OpenAIServerModel,
11
- Tool,
12
- DuckDuckGoSearchTool,
13
- WikipediaSearchTool
14
- )
15
- from tools import VisitWebpageTool
16
 
17
  ###
18
  from crewai import Agent
@@ -20,9 +20,9 @@ from langchain_openai import ChatOpenAI
20
  from tools import scrape_tool, search_tool, today_tool
21
  ###
22
 
23
- MODEL_ID_1 = "gpt-4o-mini"
24
- MODEL_ID_2 = "gpt-4o"
25
- MODEL_ID_3 = "o4-mini"
26
 
27
  #PHOENIX_PROJECT_NAME = "gaia"
28
 
@@ -38,7 +38,7 @@ MODEL_ID_3 = "o4-mini"
38
 
39
  #SmolagentsInstrumentor().instrument(tracer_provider = tracer_provider)
40
 
41
- def run_gaia(question, file_name):
42
  #search_tool = Tool.from_langchain(load_tools(["serpapi"])[0])
43
  #wikipedia_tool = Tool.from_langchain(load_tools(["wikipedia"])[0])
44
 
@@ -62,48 +62,48 @@ def run_gaia(question, file_name):
62
  # verbosity_level = 1
63
  #)
64
 
65
- manager_agent = CodeAgent(
66
- #add_base_tools = True,
67
- #additional_authorized_imports = ["json", "numpy", "pandas", "time"],
68
- #final_answer_checks = [get_final_answer],
69
- #managed_agents = [web_search_agent],
70
- #max_steps = 5,
71
- model = OpenAIServerModel(model_id = MODEL_ID_2),
72
- planning_interval=3,
73
- tools = [DuckDuckGoSearchTool(), VisitWebpageTool(), WikipediaSearchTool()],
74
- verbosity_level = 1
75
- )
76
 
77
  #return manager_agent.run(question)
78
 
79
- answer = manager_agent.run(question)
80
 
81
- return get_final_answer(question, answer)
82
 
83
- def get_final_answer(question, answer):
84
- prompt_template = """
85
- You are an expert in precise question answering. You are given a question and context. You must **precisely** answer the question based on the context and then stop.
86
- **Question:** """ + str(question) + """
87
- **Context:** """ + str(answer) + """
88
- **Example 1:** What is the capital of France? Paris
89
- **Example 2:** What is the superlative of good? Best
90
- **Example 3:** What is the opposite of left? Right
91
- **Answer:**:
92
- """
93
-
94
- client = OpenAI()
95
- completion = client.chat.completions.create(
96
- messages = [{"role": "user", "content": [{"type": "text", "text": prompt_template}]}],
97
- model = MODEL_ID_1
98
- )
99
-
100
- final_answer = completion.choices[0].message.content
101
 
102
- print(f"Question: {question}")
103
- print(f"Answer: {answer}")
104
- print(f"Final answer: {final_answer}")
105
 
106
- return final_answer
107
 
108
  ###
109
  def get_researcher_agent(model, verbose):
 
1
+ #import os
2
 
3
  #from langchain.agents import load_tools
4
+ #from openai import OpenAI
5
  #from openinference.instrumentation.smolagents import SmolagentsInstrumentor
6
  #from phoenix.otel import register
7
+ #from smolagents import (
8
+ # CodeAgent,
9
+ # ToolCallingAgent,
10
+ # OpenAIServerModel,
11
+ # Tool,
12
+ # DuckDuckGoSearchTool,
13
+ # WikipediaSearchTool
14
+ #)
15
+ #from tools import VisitWebpageTool
16
 
17
  ###
18
  from crewai import Agent
 
20
  from tools import scrape_tool, search_tool, today_tool
21
  ###
22
 
23
+ #MODEL_ID_1 = "gpt-4o-mini"
24
+ #MODEL_ID_2 = "gpt-4o"
25
+ #MODEL_ID_3 = "o4-mini"
26
 
27
  #PHOENIX_PROJECT_NAME = "gaia"
28
 
 
38
 
39
  #SmolagentsInstrumentor().instrument(tracer_provider = tracer_provider)
40
 
41
+ #def run_gaia(question, file_name):
42
  #search_tool = Tool.from_langchain(load_tools(["serpapi"])[0])
43
  #wikipedia_tool = Tool.from_langchain(load_tools(["wikipedia"])[0])
44
 
 
62
  # verbosity_level = 1
63
  #)
64
 
65
+ #manager_agent = CodeAgent(
66
+ # #add_base_tools = True,
67
+ # #additional_authorized_imports = ["json", "numpy", "pandas", "time"],
68
+ # #final_answer_checks = [get_final_answer],
69
+ # #managed_agents = [web_search_agent],
70
+ # #max_steps = 5,
71
+ # model = OpenAIServerModel(model_id = MODEL_ID_2),
72
+ # planning_interval=3,
73
+ # tools = [DuckDuckGoSearchTool(), VisitWebpageTool(), WikipediaSearchTool()],
74
+ # verbosity_level = 1
75
+ #)
76
 
77
  #return manager_agent.run(question)
78
 
79
+ #answer = manager_agent.run(question)
80
 
81
+ #return get_final_answer(question, answer)
82
 
83
+ #def get_final_answer(question, answer):
84
+ # prompt_template = """
85
+ # You are an expert in precise question answering. You are given a question and context. You must **precisely** answer the question based on the context and then stop.
86
+ # **Question:** """ + str(question) + """
87
+ # **Context:** """ + str(answer) + """
88
+ # **Example 1:** What is the capital of France? Paris
89
+ # **Example 2:** What is the superlative of good? Best
90
+ # **Example 3:** What is the opposite of left? Right
91
+ # **Answer:**:
92
+ # """
93
+
94
+ # client = OpenAI()
95
+ # completion = client.chat.completions.create(
96
+ # messages = [{"role": "user", "content": [{"type": "text", "text": prompt_template}]}],
97
+ # model = MODEL_ID_1
98
+ # )
99
+
100
+ # final_answer = completion.choices[0].message.content
101
 
102
+ # print(f"Question: {question}")
103
+ # print(f"Answer: {answer}")
104
+ # print(f"Final answer: {final_answer}")
105
 
106
+ # return final_answer
107
 
108
  ###
109
  def get_researcher_agent(model, verbose):