Spaces:
Runtime error
Runtime error
Upload my_agent.py
Browse files- my_agent.py +56 -0
my_agent.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import yaml
|
| 2 |
+
from smolagents import OpenAIServerModel, VisitWebpageTool
|
| 3 |
+
from smolagents import CodeAgent, FinalAnswerTool, WikipediaSearchTool, Tool
|
| 4 |
+
from langchain_community.tools import DuckDuckGoSearchRun
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
# Load environment variables from .env file
|
| 9 |
+
with open('.env') as f:
|
| 10 |
+
for line in f:
|
| 11 |
+
if line.strip() and not line.startswith('#'):
|
| 12 |
+
key, value = line.strip().split('=', 1)
|
| 13 |
+
os.environ[key] = value
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
model = OpenAIServerModel(
|
| 18 |
+
model_id="GEMINI_15_PRO", # Replace with the desired model ID
|
| 19 |
+
api_base=os.getenv("BASE_URL"), # Base URL for the API
|
| 20 |
+
api_key=os.getenv("OKTA_ACCESS_TOKEN"), # API key for authentication
|
| 21 |
+
custom_role_conversions=None,
|
| 22 |
+
temperature=0.5,
|
| 23 |
+
client_kwargs={
|
| 24 |
+
"default_headers": {"Subscription-Key": os.getenv("SUBSCRIPTION_KEY")}, # Additional headers,
|
| 25 |
+
},
|
| 26 |
+
web_search_options={
|
| 27 |
+
"enabled": True,
|
| 28 |
+
"dynamic_threshold": 0.5
|
| 29 |
+
}
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
# Load system prompt from prompt.yaml file
|
| 33 |
+
with open("prompts.yaml", 'r') as stream:
|
| 34 |
+
prompt_templates = yaml.safe_load(stream)
|
| 35 |
+
|
| 36 |
+
final_answer = FinalAnswerTool()
|
| 37 |
+
|
| 38 |
+
ddg_tool = Tool.from_langchain(DuckDuckGoSearchRun())
|
| 39 |
+
|
| 40 |
+
agent = CodeAgent(
|
| 41 |
+
tools=[final_answer, VisitWebpageTool(), WikipediaSearchTool(), ddg_tool],
|
| 42 |
+
add_base_tools=True,
|
| 43 |
+
max_steps=6,
|
| 44 |
+
verbosity_level=1,
|
| 45 |
+
grammar=None,
|
| 46 |
+
planning_interval=None,
|
| 47 |
+
name=None,
|
| 48 |
+
description=None,
|
| 49 |
+
prompt_templates=prompt_templates,
|
| 50 |
+
model=model)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
#
|
| 55 |
+
# res = agent.run("Can you find any information about the latest news on AI?")
|
| 56 |
+
# print(res)
|