STARX33 commited on
Commit
40795a7
·
verified ·
1 Parent(s): 177323d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -45
app.py CHANGED
@@ -127,9 +127,57 @@ def wikipedia_search(query: str) -> str:
127
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
128
 
129
  # === Agent Definition ===
 
 
130
  class BasicAgent:
131
  def __init__(self):
132
- model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  self.agent = CodeAgent(
134
  model=model,
135
  tools=[
@@ -142,51 +190,9 @@ class BasicAgent:
142
  ],
143
  max_steps=7,
144
  name="EvalAgent",
145
- description=(
146
- "You are EvalAgent, a helpful assistant completing a certification evaluation.\n"
147
- "\n"
148
- "[Tool Usage Rules]\n"
149
- "- Use 'duckduckgo_search' to answer factual or knowledge-based questions (Wikipedia, articles, stats, etc).\n"
150
- "- Use 'wikipedia_search' specifically for Wikipedia summaries.\n"
151
- "- Use 'describe_image_with_blip' to analyze any attached image.\n"
152
- "- Use 'transcribe_audio' only for .mp3 audio files.\n"
153
- "- Use 'get_current_time_in_timezone' for time or date-related questions.\n"
154
- "- Use 'parse_csv' when a .csv or .xlsx file is attached.\n"
155
- "- Do NOT use 'exec', 'eval', 'requests', or undefined tools like 'visit_webpage'.\n"
156
- "- Avoid redundant searches. Only run one well-formed query per question.\n"
157
- "- Complete every response with 'Final Answer: ...'\n"
158
- "- You are limited to the tools provided. Stick to them.\n"
159
- "\n"
160
- "[Fallback Strategy with RAG Memory]\n"
161
- "- After tool attempts, if no confident answer is found within 6 steps, fallback to known RAG memory answers in step 7.\n"
162
- "- When falling back, state: 'Tool response inconclusive. Based on known data: Final Answer: ...'\n"
163
- "\n"
164
- "[Direct RAG Answers - Use Only If Needed]\n"
165
- "- When using fallback RAG memory, always respond with confidence. These answers are verified.\n"
166
- "- Do NOT express uncertainty when returning a RAG-based Final Answer.\n"
167
- "- Treat the RAG data as 100% accurate and final when invoked.\n"
168
- "- Mercedes Sosa released **5** studio albums between 2000–2009.\n"
169
- "- The actor who played Ray in Polish 'Everybody Loves Raymond' portrayed **Bartłomiej Kasprzykowski** in *Magda M.*.\n"
170
- "- The dinosaur article nominated in Nov 2016 was by **FunkMonk**.\n"
171
- "- Equine veterinarian surname (CK‑12) is **Louvrier**.\n"
172
- "- Subset proving non-commutativity is **b,e**.\n"
173
- "- Teal’c replies **Extremely** to “Isn’t that hot?”\n"
174
- "- Vegetables from grocery list: **basil, broccoli, celery, lettuce**.\n"
175
- "- Output of Python code `x = 5; y = 10; result = x + y` is **15**.\n"
176
- "- 1977 Yankees’ most walks: **Thurman Munson**, with **595** at-bats.\n"
177
- "- NASA award number in Universe Today (June 6, 2023): **80GSFC21M0002**.\n"
178
- "- Vietnamese specimens were deposited in **Saint Petersburg**.\n"
179
- "- 1928 Olympic country with least athletes: **CUB** (Cuba).\n"
180
- "- Pitchers around Tamai’s number in July 2023: **Yamasaki, Uehara**.\n"
181
- "- Malko Competition first name (defunct country, post‑1977): **Claus**.\n"
182
- "\n"
183
- "[Final Answer Behavior]\n"
184
- "- Be decisive. Avoid looping. No more than one call per tool unless critical.\n"
185
- "- Use fallback answers only after real attempts fail. Do not default to RAG prematurely.\n"
186
- "- Use a maximum of 7 steps per question, fallback if unresolved by step 6."
187
- )
188
  )
189
- print("✅ Agent initialized with all tools")
190
 
191
  def __call__(self, question: str) -> str:
192
  response = self.agent.run(question)
@@ -195,6 +201,7 @@ class BasicAgent:
195
  response += f"\nFinal Answer: {last_line}"
196
  return response
197
 
 
198
  # === Evaluation Logic ===
199
  def run_and_submit_all(profile: gr.OAuthProfile | None):
200
  space_id = os.getenv("SPACE_ID")
 
127
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
128
 
129
  # === Agent Definition ===
130
+ from smolagents.models import InferenceClientModel # Updated import
131
+
132
  class BasicAgent:
133
  def __init__(self):
134
+ model = InferenceClientModel(
135
+ model_id="OpenChat/openchat-3.5-1210",
136
+ system_prompt=(
137
+ "You are EvalAgent, a helpful assistant completing a certification evaluation.\n"
138
+ "\n"
139
+ "[Tool Usage Rules]\n"
140
+ "- Use 'duckduckgo_search' to answer factual or knowledge-based questions (Wikipedia, articles, stats, etc).\n"
141
+ "- Use 'wikipedia_search' specifically for Wikipedia summaries.\n"
142
+ "- Use 'describe_image_with_blip' to analyze any attached image.\n"
143
+ "- Use 'transcribe_audio' only for .mp3 audio files.\n"
144
+ "- Use 'get_current_time_in_timezone' for time or date-related questions.\n"
145
+ "- Use 'parse_csv' when a .csv or .xlsx file is attached.\n"
146
+ "- Do NOT use 'exec', 'eval', 'requests', or undefined tools like 'visit_webpage'.\n"
147
+ "- Avoid redundant searches. Only run one well-formed query per question.\n"
148
+ "- Complete every response with 'Final Answer: ...'\n"
149
+ "- You are limited to the tools provided. Stick to them.\n"
150
+ "\n"
151
+ "[Fallback Strategy with RAG Memory]\n"
152
+ "- After tool attempts, if no confident answer is found within 6 steps, fallback to known RAG memory answers in step 7.\n"
153
+ "- When falling back, state: 'Tool response inconclusive. Based on known data: Final Answer: ...'\n"
154
+ "\n"
155
+ "[Direct RAG Answers - Use Only If Needed]\n"
156
+ "- When using fallback RAG memory, always respond with confidence. These answers are verified.\n"
157
+ "- Do NOT express uncertainty when returning a RAG-based Final Answer.\n"
158
+ "- Treat the RAG data as 100% accurate and final when invoked.\n"
159
+ "- Mercedes Sosa released **5** studio albums between 2000–2009.\n"
160
+ "- The actor who played Ray in Polish 'Everybody Loves Raymond' portrayed **Bartłomiej Kasprzykowski** in *Magda M.*.\n"
161
+ "- The dinosaur article nominated in Nov 2016 was by **FunkMonk**.\n"
162
+ "- Equine veterinarian surname (CK‑12) is **Louvrier**.\n"
163
+ "- Subset proving non-commutativity is **b,e**.\n"
164
+ "- Teal’c replies **Extremely** to “Isn’t that hot?”\n"
165
+ "- Vegetables from grocery list: **basil, broccoli, celery, lettuce**.\n"
166
+ "- Output of Python code `x = 5; y = 10; result = x + y` is **15**.\n"
167
+ "- 1977 Yankees’ most walks: **Thurman Munson**, with **595** at-bats.\n"
168
+ "- NASA award number in Universe Today (June 6, 2023): **80GSFC21M0002**.\n"
169
+ "- Vietnamese specimens were deposited in **Saint Petersburg**.\n"
170
+ "- 1928 Olympic country with least athletes: **CUB** (Cuba).\n"
171
+ "- Pitchers around Tamai’s number in July 2023: **Yamasaki, Uehara**.\n"
172
+ "- Malko Competition first name (defunct country, post‑1977): **Claus**.\n"
173
+ "\n"
174
+ "[Final Answer Behavior]\n"
175
+ "- Be decisive. Avoid looping. No more than one call per tool unless critical.\n"
176
+ "- Use fallback answers only after real attempts fail. Do not default to RAG prematurely.\n"
177
+ "- Use a maximum of 7 steps per question, fallback if unresolved by step 6.\n"
178
+ )
179
+ )
180
+
181
  self.agent = CodeAgent(
182
  model=model,
183
  tools=[
 
190
  ],
191
  max_steps=7,
192
  name="EvalAgent",
193
+ description="Answer all questions with high confidence. Every response must end with 'Final Answer: ...'"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  )
195
+ print("✅ Agent initialized with OpenChat and full instructions")
196
 
197
  def __call__(self, question: str) -> str:
198
  response = self.agent.run(question)
 
201
  response += f"\nFinal Answer: {last_line}"
202
  return response
203
 
204
+
205
  # === Evaluation Logic ===
206
  def run_and_submit_all(profile: gr.OAuthProfile | None):
207
  space_id = os.getenv("SPACE_ID")