Spaces:
Runtime error
Runtime error
Update my_agent.py
Browse files1234567891011121314151617184 unmodified lines232425262728293031323334352 unmodified lines383940414243444546474849505152535455import yamlfrom smolagents import OpenAIServerModel, VisitWebpageToolfrom smolagents import CodeAgent, FinalAnswerTool, WikipediaSearchTool, Toolfrom langchain_community.tools import DuckDuckGoSearchRunimport os# Load environment variables from .env file# with open('.env') as f:# for line in f:# if line.strip() and not line.startswith('#'):# key, value = line.strip().split('=', 1)# os.environ[key] = valuemodel = OpenAIServerModel(model_id="CLAUDE_3_SONNET_35", # Replace with the desired model ID4 unmodified linesclient_kwargs={"default_headers": {"Subscription-Key": os.getenv("SUBSCRIPTION_KEY")}, # Additional headers,},# web_search_options={# "enabled": True,# "dynamic_threshold": 0.5# })# Load system prompt from prompt.yaml filewith open("prompts.yaml", 'r') as stream:prompt_templates = yaml.safe_load(stream)2 unmodified linesddg_tool = Tool.from_langchain(DuckDuckGoSearchRun())agent = CodeAgent(tools=[final_answer, VisitWebpageTool(), WikipediaSearchTool(), ddg_tool],add_base_tools=True,max_steps=10,verbosity_level=1,grammar=None,planning_interval=None,name=None,description=None,prompt_templates=prompt_templates,additional_authorized_imports=['pandas', 'numpy', 'openpyxl', 'xlrd', 'os'],model=model)#12345678910111213141516171819202122232425262728293031323334353637383940414 unmodified lines464748495051525354555657582 unmodified lines6162636465666768697071727374757677787980from typing import BinaryIOimport yamlfrom smolagents import OpenAIServerModel, VisitWebpageTool, PythonInterpreterTool, SpeechToTextToolfrom smolagents import CodeAgent, FinalAnswerTool, WikipediaSearchTool, Tool, toolfrom langchain_community.tools import DuckDuckGoSearchRunimport os# Load environment variables from .env filewith open('.env') as f:for line in f:if line.strip() and not line.startswith('#'):key, value = line.strip().split('=', 1)os.environ[key] = value@tooldef get_file_from_documents(file_name: str) -> BinaryIO:"""opens and returns a file as a BinaryIO object from the 'documents' directory provided the file name.Args:file_name (str): The name of the file to read.Returns:BinaryIO: A file-like object containing the content of the file.Raises:FileNotFoundError: If the file does not exist in the 'documents' directory."""documents_dir = os.path.join(os.getcwd(), "documents")file_path = os.path.join(documents_dir, file_name)if not os.path.exists(file_path):raise FileNotFoundError(f"The file '{file_name}' does not exist in the 'documents' directory.")file = open(file_path, "rb")return filemodel = OpenAIServerModel(model_id="CLAUDE_3_SONNET_35", # Replace with the desired model ID4 unmodified linesclient_kwargs={"default_headers": {"Subscription-Key": os.getenv("SUBSCRIPTION_KEY")}, # Additional headers,},web_search_options={"enabled": True,"dynamic_threshold": 0.5})#Load system prompt from prompt.yaml filewith open("prompts.yaml", 'r') as stream:prompt_templates = yaml.safe_load(stream)2 unmodified linesddg_tool = Tool.from_langchain(DuckDuckGoSearchRun())agent = CodeAgent(tools=[final_answer, VisitWebpageTool(), WikipediaSearchTool(), ddg_tool, get_file_from_documents, PythonInterpreterTool(), SpeechToTextTool()],add_base_tools=True,max_steps=6,verbosity_level=1,grammar=None,planning_interval=None,name=None,description=None,prompt_templates=prompt_templates,additional_authorized_imports=['pandas', 'numpy', 'openpyxl', 'xlrd', 'os', ],model=model)#agent.run("""What is the final numeric output from the attached Python code? (File Name: f918266a-b3e0-4914-865d-4faa564f1aef.py) """)#
my_agent.py+40-15