Mikkel Skovdal commited on
Commit
6138f05
·
1 Parent(s): 2fabb4e

LiteLM Update

Browse files
app.py CHANGED
@@ -8,6 +8,7 @@ from src.agent import CustomAgent
8
  # (Keep Constants as is)
9
  # --- Constants ---
10
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
11
 
12
  def run_and_submit_all( profile: gr.OAuthProfile | None):
13
  """
@@ -65,7 +66,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
65
  print(f"Running agent on {len(questions_data)} questions...")
66
  for item in questions_data:
67
  task_id = item.get("task_id")
68
- question_text = item.get("question")
69
  if not task_id or question_text is None:
70
  print(f"Skipping item with missing task_id or question: {item}")
71
  continue
 
8
  # (Keep Constants as is)
9
  # --- Constants ---
10
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
+ SYSTEM_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), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.\n"
12
 
13
  def run_and_submit_all( profile: gr.OAuthProfile | None):
14
  """
 
66
  print(f"Running agent on {len(questions_data)} questions...")
67
  for item in questions_data:
68
  task_id = item.get("task_id")
69
+ question_text = SYSTEM_PROMPT + item.get("question")
70
  if not task_id or question_text is None:
71
  print(f"Skipping item with missing task_id or question: {item}")
72
  continue
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  gradio
2
  requests
3
- smolagents
 
 
1
  gradio
2
  requests
3
+ smolagents
4
+ smolagents[litellm]
src/__pycache__/agent.cpython-310.pyc ADDED
Binary file (2.72 kB). View file
 
src/agent.py CHANGED
@@ -1,13 +1,30 @@
1
- from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool
2
- # import asyncio
3
  import datetime
 
 
 
 
4
 
5
 
 
 
 
6
  class CustomAgent:
7
  def __init__(
8
  self,
9
- model_name="Qwen/Qwen2.5-Omni-7B",
10
- authorized_imports=["wiki", "json"],
 
 
 
 
 
 
 
 
 
 
 
11
  max_steps=5,
12
  logging=False
13
  ):
@@ -16,9 +33,17 @@ class CustomAgent:
16
  If no model is provided, a default one is used.
17
  """
18
  self.logging = logging
19
- model = InferenceClientModel(model_name)
 
 
 
 
 
 
 
20
  search_tool = DuckDuckGoSearchTool()
21
 
 
22
  self.agent = CodeAgent(
23
  model = model,
24
  tools=[search_tool],
@@ -33,9 +58,12 @@ class CustomAgent:
33
  fixed_answer = self.agent.run(question)
34
 
35
  if self.logging:
 
 
 
36
  timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
37
  with open("logging/log.txt", "a") as log_file:
38
- log_file.write(f"{timestamp}: {question} -> {fixed_answer}\n")
39
 
40
  return question, fixed_answer
41
 
 
1
+ from smolagents import CodeAgent, LiteLLMModel, DuckDuckGoSearchTool
 
2
  import datetime
3
+ import os
4
+ # import asyncio
5
+ from dotenv import load_dotenv
6
+ load_dotenv()
7
 
8
 
9
+ PROMPT = """
10
+ 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), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
11
+ """
12
  class CustomAgent:
13
  def __init__(
14
  self,
15
+ model_id="gemini/gemini-2.0-flash-exp",
16
+ authorized_imports=[
17
+ "wiki",
18
+ "json",
19
+ "BeautifulSoup",
20
+ "bs4",
21
+ "requests",
22
+ "os",
23
+ "re",
24
+ "pandas",
25
+ "numpy",
26
+ "datetime",
27
+ ],
28
  max_steps=5,
29
  logging=False
30
  ):
 
33
  If no model is provided, a default one is used.
34
  """
35
  self.logging = logging
36
+
37
+ # Initialize the model
38
+ model = LiteLLMModel(
39
+ model_id=model_id,
40
+ api_key=os.getenv("GEMINI_API_KEY")
41
+ )
42
+
43
+ # Initialize tools
44
  search_tool = DuckDuckGoSearchTool()
45
 
46
+ # Initialize the agent
47
  self.agent = CodeAgent(
48
  model = model,
49
  tools=[search_tool],
 
58
  fixed_answer = self.agent.run(question)
59
 
60
  if self.logging:
61
+ # print current directory
62
+ if not os.path.exists("logging"):
63
+ os.makedirs("logging")
64
  timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
65
  with open("logging/log.txt", "a") as log_file:
66
+ log_file.write(f"{timestamp}: {question}\nAnswer: {fixed_answer}\n")
67
 
68
  return question, fixed_answer
69