Spaces:
Build error
Build error
python code tool added
Browse filesFiles changed (4)
- app.py+1-1
- requirements.txt+1
- system_prompt.txt+1
- unit4agent.py+41-1
18 unmodified lines192021222223242518 unmodified lines def __call__(self, question: str) -> str: print(f"Agent received question (first 50 chars): {question[:50]}...") fixed_answer = "This is a default answer." response = self.ai_unit.invoke({"messages": [HumanMessage(question)]}, {"recursion_limit": 45}) response = self.ai_unit.invoke({"messages": [HumanMessage(question)]}, {"recursion_limit": 70}) fixed_answer = response['messages'][-1].content print(f"Agent returning fixed answer: {fixed_answer}") return fixed_answer39 unmodified lines4041424344454639 unmodified lineslangchain==0.3.25langchain-community==0.3.24langchain-core==0.3.60langchain-experimental==0.3.4langchain-openai==0.3.17langchain-tavily==0.1.6langchain-text-splitters==0.3.82 unmodified lines34567892 unmodified linesIf there is an image attached (file name and file URL) use tool for automatic image download and analysis with precise question.If there is an Excel file attached (file name and file URL) use tool for getting content of the Excel file from URL.If there is an MP3 file attached (file name and file URL) use tool for getting content by transcribing text out of file URL.If there is an Python code file attached (file name and file URL) use tool for execution of Python code file URL and getting back output.
Format of your answer - [ANSWER]. [ANSWER] can be a number, list of items divided by comma or a string. Be very concise and clear with the answer.Do not include any plans, thoughts and explanations into the answer. Just provide concise and unambiguous answer in the format above.13 unmodified lines1415161718192021222324252627140 unmodified lines16816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620716820820921021113 unmodified linesimport requestsimport pandas as pdfrom openai import OpenAIfrom langchain_experimental.utilities import PythonREPLimport ioimport sysimport runpyimport subprocess
llm = ChatOpenAI(model="gpt-4.1")python_repl = PythonREPL()
# tools ///////////////////////////////////
140 unmodified lines # return the content return transcription
@tooldef execute_python_code(python_code_file_url: str) -> str: """Download python code from URL and execute it"""
# download the file using requests library response = requests.get(python_code_file_url)
# save the file to a temporary location temp_file_path = "/tmp/temp.py" with open(temp_file_path, "wb") as file: file.write(response.content)
# output = runpy.run_path(temp_file_path)
# python_code = open(temp_file_path).read()
# original_stdout = sys.stdout
# # Create a StringIO buffer # buffer = io.StringIO() # sys.stdout = buffer # Redirect stdout to the buffer
# # exec("python " python_code) # exec("python " + temp_file_path)
# sys.stdout = original_stdout
# # Get the output from the buffer # output = buffer.getvalue()
result = subprocess.run(["python", temp_file_path], capture_output=True, text=True)
return result.stdout
def compile_agent():
tools = [multiply, divide, add, subtract, square_root, web_search_tool, arxiv_search, wikidata_search, wikipedia_search, download_image_and_analyze, get_excel_file_content, transcribe_audio_mp3_file] wikipedia_search, download_image_and_analyze, get_excel_file_content, transcribe_audio_mp3_file, execute_python_code]
# HUGGINGFACEHUB_API_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")
app.py+1-1
requirements.txt+1
system_prompt.txt+1
unit4agent.py+41-1