JuyeopDang commited on
Commit
54a8589
·
verified ·
1 Parent(s): 6d22931

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -54
app.py CHANGED
@@ -22,67 +22,68 @@ class BasicAgent:
22
  def __call__(self, question: str) -> str:
23
  print(f"Agent received question (first 50 chars): {question[:50]}...")
24
  try:
25
- message = [
26
- {
27
- "role": "user",
28
- "content": question
29
- }]
30
- completion = self.client.chat.completions.create(
31
- messages=message,
32
- model="compound-beta",
33
  )
34
- answer = completion.choices[0].message.content
35
- print(f"First answer: {answer}")
36
- message=[
37
- {
38
- "role": "system",
39
- "content": """
40
- You are an expert in identifying and extracting definitive answers. Your sole task is to analyze the provided text, which is an agent's response, and extract only the conclusive final answer to the original user's query.
41
-
42
- Output only this core answer. Do not include any explanations, pleasantries, introductory phrases, or any surrounding text.
43
-
44
- Here The Examples:
45
-
46
- Input: ... Final answer: 12 ...
47
- You should output: 12
48
-
49
- Input: $\\boxed{b,c,e}$
50
- Output: b, c, e
51
 
52
- Input: Jan
53
- Output: Jan
54
-
55
- Input: The Yankee with the most walks in the 1977 regular season was Reggie Jackson, with 58 walks. He had 357 at bats that season.
56
- Output: 357
57
-
58
- Input: broccoli, bell pepper, celery, fresh basil, green beans, lettuce, sweet potatoes, zucchini
59
- Output: broccoli, bell pepper, celery, fresh basil, green beans, lettuce, sweet potatoes, zucchini
60
- """
61
- },
62
- {
63
- "role": "user",
64
- "content": answer
65
- }
66
- ]
67
- completion = self.client.chat.completions.create(
68
- messages=message,
69
- model="llama-3.1-8b-instant",
70
  )
71
- response = completion.choices[0].message.content
 
72
  except Exception:
73
  try:
74
- model = LiteLLMModel(
75
- "llama-3.3-70b-versatile",
76
- api_base="https://api.groq.com/openai/v1",
77
- api_key=GROQ_KEY,
 
 
 
 
78
  )
79
- model.flatten_messages_as_text = True
 
 
 
 
 
 
 
 
80
 
81
- agent = CodeAgent(
82
- tools=[DuckDuckGoSearchTool(), FinalAnswerTool(), VisitWebpageTool(), PythonInterpreterTool()],
83
- model=model,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  )
85
- response = agent.run(question)
86
  except Exception:
87
  message = [
88
  {
@@ -131,7 +132,6 @@ class BasicAgent:
131
  model="llama-3.1-8b-instant",
132
  )
133
  response = completion.choices[0].message.content
134
-
135
  return response
136
 
137
  def run_and_submit_all( profile: gr.OAuthProfile | None):
 
22
  def __call__(self, question: str) -> str:
23
  print(f"Agent received question (first 50 chars): {question[:50]}...")
24
  try:
25
+ model = LiteLLMModel(
26
+ "llama-3.3-70b-versatile",
27
+ api_base="https://api.groq.com/openai/v1",
28
+ api_key=GROQ_KEY,
 
 
 
 
29
  )
30
+ model.flatten_messages_as_text = True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
+ agent = CodeAgent(
33
+ tools=[DuckDuckGoSearchTool(), FinalAnswerTool(), VisitWebpageTool(), PythonInterpreterTool()],
34
+ model=model,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  )
36
+ response = agent.run(question)
37
+
38
  except Exception:
39
  try:
40
+ message = [
41
+ {
42
+ "role": "user",
43
+ "content": question
44
+ }]
45
+ completion = self.client.chat.completions.create(
46
+ messages=message,
47
+ model="compound-beta",
48
  )
49
+ answer = completion.choices[0].message.content
50
+ print(f"First answer: {answer}")
51
+ message=[
52
+ {
53
+ "role": "system",
54
+ "content": """
55
+ You are an expert in identifying and extracting definitive answers. Your sole task is to analyze the provided text, which is an agent's response, and extract only the conclusive final answer to the original user's query.
56
+
57
+ Output only this core answer. Do not include any explanations, pleasantries, introductory phrases, or any surrounding text.
58
 
59
+ Here The Examples:
60
+
61
+ Input: ... Final answer: 12 ...
62
+ You should output: 12
63
+
64
+ Input: $\\boxed{b,c,e}$
65
+ Output: b, c, e
66
+
67
+ Input: Jan
68
+ Output: Jan
69
+
70
+ Input: The Yankee with the most walks in the 1977 regular season was Reggie Jackson, with 58 walks. He had 357 at bats that season.
71
+ Output: 357
72
+
73
+ Input: broccoli, bell pepper, celery, fresh basil, green beans, lettuce, sweet potatoes, zucchini
74
+ Output: broccoli, bell pepper, celery, fresh basil, green beans, lettuce, sweet potatoes, zucchini
75
+ """
76
+ },
77
+ {
78
+ "role": "user",
79
+ "content": answer
80
+ }
81
+ ]
82
+ completion = self.client.chat.completions.create(
83
+ messages=message,
84
+ model="llama-3.1-8b-instant",
85
  )
86
+ response = completion.choices[0].message.content
87
  except Exception:
88
  message = [
89
  {
 
132
  model="llama-3.1-8b-instant",
133
  )
134
  response = completion.choices[0].message.content
 
135
  return response
136
 
137
  def run_and_submit_all( profile: gr.OAuthProfile | None):