trying groq
Browse files
agent.py
CHANGED
|
@@ -1,19 +1,29 @@
|
|
| 1 |
import os
|
| 2 |
-
from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel, VisitWebpageTool
|
| 3 |
from tools.attached_files import csv_reader, download_file_from_url, excel_reader
|
| 4 |
from tools.basic_math import *
|
| 5 |
from tools.browser import arvix_search, wiki_search
|
| 6 |
from tools.media import transcribe_audio
|
| 7 |
|
| 8 |
-
def get_agent() -> CodeAgent:
|
| 9 |
search_tool = DuckDuckGoSearchTool(max_results=5)
|
| 10 |
web_page_tool = VisitWebpageTool(max_output_length=1_000_000)
|
| 11 |
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
model =
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
return CodeAgent(tools=[search_tool, web_page_tool, add, subtract, multiply, divide, modulus, rounder, power, square_root, download_file_from_url, csv_reader, excel_reader, transcribe_audio, wiki_search, arvix_search], model=model, additional_authorized_imports=['random', 'time'], add_base_tools=True)
|
|
|
|
| 1 |
import os
|
| 2 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel, VisitWebpageTool, LiteLLMModel
|
| 3 |
from tools.attached_files import csv_reader, download_file_from_url, excel_reader
|
| 4 |
from tools.basic_math import *
|
| 5 |
from tools.browser import arvix_search, wiki_search
|
| 6 |
from tools.media import transcribe_audio
|
| 7 |
|
| 8 |
+
def get_agent(provider:str) -> CodeAgent:
|
| 9 |
search_tool = DuckDuckGoSearchTool(max_results=5)
|
| 10 |
web_page_tool = VisitWebpageTool(max_output_length=1_000_000)
|
| 11 |
|
| 12 |
+
codestral_key = os.getenv('CODESTRAL_API_KEY')
|
| 13 |
+
groq_key = os.getenv('GROQ_API_KEY')
|
| 14 |
|
| 15 |
+
model = None
|
| 16 |
+
|
| 17 |
+
if provider=='groq':
|
| 18 |
+
model = LiteLLMModel(
|
| 19 |
+
model="qwen-qwq-32b",
|
| 20 |
+
api_base="https://api.groq.com/openai/v1/chat/completions",
|
| 21 |
+
api_key=groq_key)
|
| 22 |
+
|
| 23 |
+
else:
|
| 24 |
+
model = OpenAIServerModel(
|
| 25 |
+
model_id='codestral-latest',
|
| 26 |
+
api_base="https://codestral.mistral.ai/v1/chat/completions",
|
| 27 |
+
api_key=codestral_key)
|
| 28 |
|
| 29 |
return CodeAgent(tools=[search_tool, web_page_tool, add, subtract, multiply, divide, modulus, rounder, power, square_root, download_file_from_url, csv_reader, excel_reader, transcribe_audio, wiki_search, arvix_search], model=model, additional_authorized_imports=['random', 'time'], add_base_tools=True)
|
app.py
CHANGED
|
@@ -12,7 +12,7 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
-
self.agent = agent.get_agent()
|
| 16 |
print("BasicAgent initialized.")
|
| 17 |
def __call__(self, question: str) -> str:
|
| 18 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
|
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
+
self.agent = agent.get_agent(provider='groq')
|
| 16 |
print("BasicAgent initialized.")
|
| 17 |
def __call__(self, question: str) -> str:
|
| 18 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|