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 lines1920212223242518 unmodified linesdef __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})fixed_answer = response['messages'][-1].contentprint(f"Agent returning fixed answer: {fixed_answer}")return fixed_answer18 unmodified lines1920212223242518 unmodified linesdef __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": 70})fixed_answer = response['messages'][-1].contentprint(f"Agent returning fixed answer: {fixed_answer}")return fixed_answer
39 unmodified lines40414243444539 unmodified lineslangchain==0.3.25langchain-community==0.3.24langchain-core==0.3.60langchain-openai==0.3.17langchain-tavily==0.1.6langchain-text-splitters==0.3.839 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.8
2 unmodified lines3456782 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.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.2 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 lines1415161718192021140 unmodified lines16216316416516616716816917017113 unmodified linesimport requestsimport pandas as pdfrom openai import OpenAIllm = ChatOpenAI(model="gpt-4.1")# tools ///////////////////////////////////140 unmodified lines# return the contentreturn transcriptiondef 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]# HUGGINGFACEHUB_API_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")13 unmodified lines1415161718192021222324252627140 unmodified lines16816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021113 unmodified linesimport requestsimport pandas as pdfrom openai import OpenAIfrom langchain_experimental.utilities import PythonREPLimport ioimport sysimport runpyimport subprocessllm = ChatOpenAI(model="gpt-4.1")python_repl = PythonREPL()# tools ///////////////////////////////////140 unmodified lines# return the contentreturn transcription@tooldef execute_python_code(python_code_file_url: str) -> str:"""Download python code from URL and execute it"""# download the file using requests libraryresponse = requests.get(python_code_file_url)# save the file to a temporary locationtemp_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.stdoutdef compile_agent():tools = [multiply, divide, add, subtract, square_root, web_search_tool, arxiv_search,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