Spaces:
Sleeping
Sleeping
Commit
·
4cad7a4
1
Parent(s):
0a04e0d
prompt changed
Browse files
app.py
CHANGED
@@ -29,6 +29,7 @@ OPENAI_MODEL = os.getenv ('OPENAI_MODEL')
|
|
29 |
########## ----- DEFINING TOOLS -----##########
|
30 |
|
31 |
# --- TOOL 1: Web Search Tool (DuckDuckGo) ---
|
|
|
32 |
@tool
|
33 |
def search_tool(query: str) -> str:
|
34 |
"""Answer general knowledge or current events queries using DuckDuckGo."""
|
@@ -43,7 +44,7 @@ def search_tool(query: str) -> str:
|
|
43 |
return "no_answer"
|
44 |
except Exception:
|
45 |
return "error"
|
46 |
-
|
47 |
# when you use the @tool decorator from langchain.tools, the tool.name and tool.description are automatically extracted from your function
|
48 |
# tool.name is set to the function name (e.g., `search_tool`), and
|
49 |
# tool.description is set to the docstring of the function (the triple-quoted string right under def ...) (e.g., "Answer general knowledge or current events queries using DuckDuckGo.").
|
@@ -119,7 +120,7 @@ def get_date(input: str) -> str:
|
|
119 |
@tool
|
120 |
def wikipedia_summary(query: str) -> str:
|
121 |
"""
|
122 |
-
Answer questions from Wikipedia,
|
123 |
"""
|
124 |
|
125 |
# Heuristic: If the query looks data-driven, extract tables/lists
|
@@ -331,7 +332,7 @@ def audio_to_text(audio_url: str) -> str:
|
|
331 |
@tool
|
332 |
def python_executor(code: str) -> str:
|
333 |
"""
|
334 |
-
Safely execute simple Python code and return the result.
|
335 |
Only supports expressions and basic statements (no imports, file I/O, or system access).
|
336 |
"""
|
337 |
try:
|
@@ -347,8 +348,8 @@ def python_executor(code: str) -> str:
|
|
347 |
@tool
|
348 |
def python_excel_audio_video_attached_file_tool(input_str: str) -> str:
|
349 |
"""
|
350 |
-
Processes an input attachment (audio, image, video, Excel, or Python file) and returns extracted text or a summary suitable for LLM input.
|
351 |
-
This function accepts a JSON string with keys: 'file_bytes' (base64), and 'filename'. For unsupported file types the function returns an error message.
|
352 |
"""
|
353 |
import pandas as pd
|
354 |
|
@@ -653,7 +654,7 @@ def audio_video_url_transcript_tool(youtube_url: str) -> str:
|
|
653 |
# tools_list = get_all_tools()
|
654 |
tools_list = [
|
655 |
python_excel_audio_video_attached_file_tool,
|
656 |
-
search_tool,
|
657 |
get_weather,
|
658 |
calculator,
|
659 |
convert_units,
|
@@ -698,6 +699,9 @@ If there is a file (image, audio, or video) attached to the question, you should
|
|
698 |
In general, you must use tools only if needed for the question and only if the question can be answered by one of the provided tools. Otherwise provide the answer based on your knowledge. You must not use multiple tools in a single call. Don't hallucinate.
|
699 |
If you cannot answer, respond with "no_answer".
|
700 |
|
|
|
|
|
|
|
701 |
"""
|
702 |
|
703 |
# system_prompt = f"""
|
@@ -767,7 +771,7 @@ agent = initialize_agent(
|
|
767 |
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
768 |
agent_kwargs={"system_message": system_prompt},
|
769 |
verbose=True,
|
770 |
-
max_iterations=
|
771 |
max_execution_time=4000, # Increase as needed
|
772 |
early_stopping_method="generate",
|
773 |
handle_parsing_errors=True
|
|
|
29 |
########## ----- DEFINING TOOLS -----##########
|
30 |
|
31 |
# --- TOOL 1: Web Search Tool (DuckDuckGo) ---
|
32 |
+
'''
|
33 |
@tool
|
34 |
def search_tool(query: str) -> str:
|
35 |
"""Answer general knowledge or current events queries using DuckDuckGo."""
|
|
|
44 |
return "no_answer"
|
45 |
except Exception:
|
46 |
return "error"
|
47 |
+
'''
|
48 |
# when you use the @tool decorator from langchain.tools, the tool.name and tool.description are automatically extracted from your function
|
49 |
# tool.name is set to the function name (e.g., `search_tool`), and
|
50 |
# tool.description is set to the docstring of the function (the triple-quoted string right under def ...) (e.g., "Answer general knowledge or current events queries using DuckDuckGo.").
|
|
|
120 |
@tool
|
121 |
def wikipedia_summary(query: str) -> str:
|
122 |
"""
|
123 |
+
Answer questions from Wikipedia related to world information, facts, sports, olympics, history, facts, general knowledge etc.
|
124 |
"""
|
125 |
|
126 |
# Heuristic: If the query looks data-driven, extract tables/lists
|
|
|
332 |
@tool
|
333 |
def python_executor(code: str) -> str:
|
334 |
"""
|
335 |
+
Safely execute simple Python code and return the result if the code is in the question. If the question has .py file attached, use 'python_excel_audio_video_attached_file_tool' tool first.
|
336 |
Only supports expressions and basic statements (no imports, file I/O, or system access).
|
337 |
"""
|
338 |
try:
|
|
|
348 |
@tool
|
349 |
def python_excel_audio_video_attached_file_tool(input_str: str) -> str:
|
350 |
"""
|
351 |
+
Processes an input attachment (audio, image, video, Excel, or Python .py file) and returns extracted text or a summary suitable for LLM input.
|
352 |
+
This function accepts a JSON string 'input_str' with keys: 'file_bytes' (base64), and 'filename'. So input the file and filename as json strings. For unsupported file types the function returns an error message.
|
353 |
"""
|
354 |
import pandas as pd
|
355 |
|
|
|
654 |
# tools_list = get_all_tools()
|
655 |
tools_list = [
|
656 |
python_excel_audio_video_attached_file_tool,
|
657 |
+
# search_tool,
|
658 |
get_weather,
|
659 |
calculator,
|
660 |
convert_units,
|
|
|
699 |
In general, you must use tools only if needed for the question and only if the question can be answered by one of the provided tools. Otherwise provide the answer based on your knowledge. You must not use multiple tools in a single call. Don't hallucinate.
|
700 |
If you cannot answer, respond with "no_answer".
|
701 |
|
702 |
+
If your final answer is something like 'there were 5 studio albums published between 2000 and 2009' then modify YOUR FINAL ANSWER as: '5'
|
703 |
+
If your final answer is something like 'b, e' then YOUR FINAL ANSWER be: 'b, e'
|
704 |
+
|
705 |
"""
|
706 |
|
707 |
# system_prompt = f"""
|
|
|
771 |
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
772 |
agent_kwargs={"system_message": system_prompt},
|
773 |
verbose=True,
|
774 |
+
max_iterations=7, # Increase as needed
|
775 |
max_execution_time=4000, # Increase as needed
|
776 |
early_stopping_method="generate",
|
777 |
handle_parsing_errors=True
|