Spaces:
Runtime error
Runtime error
Delete my_agent.py
Browse files- my_agent.py +0 -82
my_agent.py
DELETED
|
@@ -1,82 +0,0 @@
|
|
| 1 |
-
from typing import BinaryIO
|
| 2 |
-
|
| 3 |
-
import yaml
|
| 4 |
-
from smolagents import OpenAIServerModel, VisitWebpageTool, PythonInterpreterTool, SpeechToTextTool
|
| 5 |
-
from smolagents import CodeAgent, FinalAnswerTool, WikipediaSearchTool, Tool, tool
|
| 6 |
-
from langchain_community.tools import DuckDuckGoSearchRun
|
| 7 |
-
|
| 8 |
-
import os
|
| 9 |
-
|
| 10 |
-
# Load environment variables from .env file
|
| 11 |
-
# with open('.env') as f:
|
| 12 |
-
# for line in f:
|
| 13 |
-
# if line.strip() and not line.startswith('#'):
|
| 14 |
-
# key, value = line.strip().split('=', 1)
|
| 15 |
-
# os.environ[key] = value
|
| 16 |
-
|
| 17 |
-
@tool
|
| 18 |
-
def get_file_from_documents(file_name: str) -> BinaryIO:
|
| 19 |
-
"""
|
| 20 |
-
opens and returns a file as a BinaryIO object from the 'documents' directory provided the file name.
|
| 21 |
-
|
| 22 |
-
Args:
|
| 23 |
-
file_name (str): The name of the file to read.
|
| 24 |
-
|
| 25 |
-
Returns:
|
| 26 |
-
BinaryIO: A file-like object containing the content of the file.
|
| 27 |
-
|
| 28 |
-
Raises:
|
| 29 |
-
FileNotFoundError: If the file does not exist in the 'documents' directory.
|
| 30 |
-
"""
|
| 31 |
-
documents_dir = os.path.join(os.getcwd(), "documents")
|
| 32 |
-
file_path = os.path.join(documents_dir, file_name)
|
| 33 |
-
|
| 34 |
-
if not os.path.exists(file_path):
|
| 35 |
-
raise FileNotFoundError(f"The file '{file_name}' does not exist in the 'documents' directory.")
|
| 36 |
-
|
| 37 |
-
file = open(file_path, "rb")
|
| 38 |
-
return file
|
| 39 |
-
|
| 40 |
-
model = OpenAIServerModel(
|
| 41 |
-
model_id="CLAUDE_3_SONNET_35", # Replace with the desired model ID
|
| 42 |
-
api_base=os.getenv("BASE_URL"), # Base URL for the API
|
| 43 |
-
api_key=os.getenv("OKTA_ACCESS_TOKEN"), # API key for authentication
|
| 44 |
-
custom_role_conversions=None,
|
| 45 |
-
temperature=0.5,
|
| 46 |
-
client_kwargs={
|
| 47 |
-
"default_headers": {"Subscription-Key": os.getenv("SUBSCRIPTION_KEY")}, # Additional headers,
|
| 48 |
-
},
|
| 49 |
-
web_search_options={
|
| 50 |
-
"enabled": True,
|
| 51 |
-
"dynamic_threshold": 0.5
|
| 52 |
-
}
|
| 53 |
-
)
|
| 54 |
-
|
| 55 |
-
#Load system prompt from prompt.yaml file
|
| 56 |
-
with open("prompts.yaml", 'r') as stream:
|
| 57 |
-
prompt_templates = yaml.safe_load(stream)
|
| 58 |
-
|
| 59 |
-
final_answer = FinalAnswerTool()
|
| 60 |
-
|
| 61 |
-
ddg_tool = Tool.from_langchain(DuckDuckGoSearchRun())
|
| 62 |
-
|
| 63 |
-
agent = CodeAgent(
|
| 64 |
-
tools=[final_answer, VisitWebpageTool(), WikipediaSearchTool(), ddg_tool, get_file_from_documents, PythonInterpreterTool(), SpeechToTextTool()],
|
| 65 |
-
add_base_tools=True,
|
| 66 |
-
max_steps=6,
|
| 67 |
-
verbosity_level=1,
|
| 68 |
-
grammar=None,
|
| 69 |
-
planning_interval=None,
|
| 70 |
-
name=None,
|
| 71 |
-
description=None,
|
| 72 |
-
prompt_templates=prompt_templates,
|
| 73 |
-
additional_authorized_imports=['pandas', 'numpy', 'openpyxl', 'xlrd', 'os', ],
|
| 74 |
-
model=model)
|
| 75 |
-
|
| 76 |
-
#agent.run("""What is the final numeric output from the attached Python code? (File Name: f918266a-b3e0-4914-865d-4faa564f1aef.py) """)
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
#
|
| 81 |
-
# res = agent.run("Can you find any information about the latest news on AI?")
|
| 82 |
-
# print(res)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|