add google.
Browse files- basic_agent.py +42 -17
- requirements.txt +2 -1
basic_agent.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import os
|
2 |
import logging
|
3 |
import sys
|
|
|
4 |
|
5 |
import smolagents
|
6 |
|
@@ -9,12 +10,12 @@ LOG = logging.getLogger(__name__)
|
|
9 |
SYSTEM_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 |
Take the time to plan the steps to reach the solution. Show the steps and then execute the steps.
|
13 |
"""
|
14 |
|
15 |
|
16 |
-
# --- Basic Agent Definition ---
|
17 |
-
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
18 |
class BasicAgent:
|
19 |
|
20 |
def __init__(self, model_id=None):
|
@@ -22,26 +23,46 @@ class BasicAgent:
|
|
22 |
# Logs appear to be swallowed.
|
23 |
LOG.warning("logging BasicAgent initialized.")
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
if model_id:
|
26 |
self.model_id = model_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
else:
|
28 |
-
#self.model_id = "HuggingFaceTB/SmolLM2-1.7B-Instruct"
|
29 |
-
#self.model_id = "Qwen/Qwen3-4B-FP8"
|
30 |
self.model_id = "Qwen/Qwen3-32B"
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
self.
|
40 |
-
|
41 |
-
temperature=0.3,
|
42 |
-
model_id=self.model_id,
|
43 |
-
custom_role_conversions=None,
|
44 |
-
)
|
45 |
self.tools = [
|
46 |
smolagents.DuckDuckGoSearchTool(),
|
47 |
smolagents.VisitWebpageTool(),
|
@@ -73,6 +94,10 @@ class BasicAgent:
|
|
73 |
managed_agents=[self.search_agent])
|
74 |
|
75 |
def __call__(self, question: str) -> str:
|
|
|
|
|
|
|
|
|
76 |
print(f"NEW Agent received question (first 50 chars): {question[:50]}...")
|
77 |
prompt = f"{SYSTEM_PROMPT}\n\n{question}"
|
78 |
answer = self.manager_agent.run(prompt)
|
|
|
1 |
import os
|
2 |
import logging
|
3 |
import sys
|
4 |
+
import time
|
5 |
|
6 |
import smolagents
|
7 |
|
|
|
10 |
SYSTEM_PROMPT = """
|
11 |
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.
|
12 |
|
13 |
+
The current date is April 30, 2025.
|
14 |
+
|
15 |
Take the time to plan the steps to reach the solution. Show the steps and then execute the steps.
|
16 |
"""
|
17 |
|
18 |
|
|
|
|
|
19 |
class BasicAgent:
|
20 |
|
21 |
def __init__(self, model_id=None):
|
|
|
23 |
# Logs appear to be swallowed.
|
24 |
LOG.warning("logging BasicAgent initialized.")
|
25 |
|
26 |
+
# Force google for now.
|
27 |
+
model_id = "google"
|
28 |
+
|
29 |
+
# Assume we will use the default model creation
|
30 |
+
self.model = None
|
31 |
+
|
32 |
if model_id:
|
33 |
self.model_id = model_id
|
34 |
+
|
35 |
+
# Handle the special cases
|
36 |
+
if model_id.lower() == "google":
|
37 |
+
self.model_id = "google"
|
38 |
+
|
39 |
+
# Use Google gemini free tier
|
40 |
+
GEM_KEY=os.environ["GOOGLE_API_KEY"]
|
41 |
+
self.model = smolagents.OpenAIServerModel(
|
42 |
+
model_id="gemini-2.0-flash",
|
43 |
+
api_base="https://generativelanguage.googleapis.com/v1beta/openai/",
|
44 |
+
api_key=GEM_KEY,
|
45 |
+
temperature=0.3)
|
46 |
+
elif model_id.lower() == "local":
|
47 |
+
self.model_id = "Qwen/Qwen3-4B-FP8"
|
48 |
+
# Run locally.
|
49 |
+
self.model = smolagents.TransformersModel(
|
50 |
+
model_id=self.model_id,
|
51 |
+
max_new_tokens=32000,
|
52 |
+
temperature=0.3
|
53 |
+
)
|
54 |
else:
|
|
|
|
|
55 |
self.model_id = "Qwen/Qwen3-32B"
|
56 |
|
57 |
+
if not self.model:
|
58 |
+
self.model = smolagents.HfApiModel(
|
59 |
+
max_tokens=32000,
|
60 |
+
temperature=0.3,
|
61 |
+
model_id=self.model_id,
|
62 |
+
custom_role_conversions=None,
|
63 |
+
)
|
64 |
+
print(f"NEW2: BasicAgent {self.model_id=} {self.model=}")
|
65 |
+
|
|
|
|
|
|
|
|
|
66 |
self.tools = [
|
67 |
smolagents.DuckDuckGoSearchTool(),
|
68 |
smolagents.VisitWebpageTool(),
|
|
|
94 |
managed_agents=[self.search_agent])
|
95 |
|
96 |
def __call__(self, question: str) -> str:
|
97 |
+
# Avoid rate limiting issues
|
98 |
+
if self.model_id == "google":
|
99 |
+
time.sleep(1)
|
100 |
+
|
101 |
print(f"NEW Agent received question (first 50 chars): {question[:50]}...")
|
102 |
prompt = f"{SYSTEM_PROMPT}\n\n{question}"
|
103 |
answer = self.manager_agent.run(prompt)
|
requirements.txt
CHANGED
@@ -1,8 +1,9 @@
|
|
1 |
gradio
|
2 |
requests
|
|
|
3 |
smolagents
|
|
|
4 |
|
5 |
# Only needed for running locally
|
6 |
#compressed-tensors
|
7 |
-
#huggingface_hub[hf_xet]
|
8 |
#smolagents[transformers]
|
|
|
1 |
gradio
|
2 |
requests
|
3 |
+
huggingface_hub[hf_xet]
|
4 |
smolagents
|
5 |
+
smolagents[openai]
|
6 |
|
7 |
# Only needed for running locally
|
8 |
#compressed-tensors
|
|
|
9 |
#smolagents[transformers]
|