-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathsmolagents_codeagent.py
More file actions
32 lines (27 loc) · 1.27 KB
/
smolagents_codeagent.py
File metadata and controls
32 lines (27 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
import azure.identity
from dotenv import load_dotenv
from smolagents import AzureOpenAIServerModel, CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel
# Setup the OpenAI client to use either Azure OpenAI or GitHub Models
load_dotenv(override=True)
API_HOST = os.getenv("API_HOST", "github")
if API_HOST == "github":
model = OpenAIServerModel(
model_id=os.getenv("GITHUB_MODEL", "gpt-4o"),
api_base="https://models.inference.ai.azure.com",
api_key=os.environ["GITHUB_TOKEN"],
)
elif API_HOST == "azure":
token_provider = azure.identity.get_bearer_token_provider(
azure.identity.DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"
)
model = AzureOpenAIServerModel(
model_id=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT"],
api_version=os.environ["AZURE_OPENAI_VERSION"],
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
client_kwargs={"azure_ad_token_provider": token_provider},
)
elif API_HOST == "ollama":
model = OpenAIServerModel(model_id="llama3.1:latest", api_base="http://localhost:11434/v1", api_key="none")
agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)
agent.run("How many seconds would it take for a leopard at full speed to run through Pont des Arts?")