Spaces:
Runtime error
Runtime error
Commit
·
858f874
1
Parent(s):
59f14fa
add code interpreter in tools
Browse files
app.py
CHANGED
@@ -111,7 +111,7 @@ code_2 = """
|
|
111 |
!pip install python-pptx
|
112 |
"""
|
113 |
|
114 |
-
def Code_Runner(code_raw: str
|
115 |
# interpreter = CodeInterpreter(language="python", debug_mode=True)
|
116 |
if '!pip' in code_raw:
|
117 |
code_raw=code_raw.replace('!pip', 'pip')
|
@@ -525,7 +525,8 @@ def UpdateDb():
|
|
525 |
print(index.describe_index_stats())
|
526 |
|
527 |
ListAgentWithRemoteGPT = ['Zero Short React 2','Zero Short Agent 2',
|
528 |
-
'OpenAI Multi 2', 'Conversation Agent'
|
|
|
529 |
|
530 |
def SummarizeDoc():
|
531 |
global vectordb_p
|
@@ -738,6 +739,13 @@ python_tool2 = Tool(
|
|
738 |
description = "Useful when you need python script to answer questions. You should input python code."
|
739 |
)
|
740 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
741 |
|
742 |
|
743 |
# tools = [DB_Search(), wikipedia_tool, duckduckgo_tool, python_tool]
|
@@ -785,7 +793,7 @@ tools = [DB_Search(), duckduckgo_tool, python_tool, math_tool, Text2Sound_tool]
|
|
785 |
|
786 |
tools2 = [DB_Search2(), duckduckgo_tool2, wikipedia_tool2, python_tool2, math_tool, Text2Sound_tool2]
|
787 |
|
788 |
-
tools_remote = [DB_Search2(), duckduckgo_tool2, wikipedia_tool2,
|
789 |
|
790 |
# tools = load_tools(["Vector Database Search","Wikipedia Search","Python REPL","llm-math"], llm=llm)
|
791 |
|
@@ -1012,6 +1020,29 @@ agent_ZEROSHOT_REACT_2 = initialize_agent(tools_remote, GPTfake,
|
|
1012 |
|
1013 |
)
|
1014 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1015 |
agent_CONVERSATION = initialize_agent(tools_remote, GPTfake,
|
1016 |
# agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
1017 |
agent=AgentType.CONVERSATIONAL_REACT_DESCRIPTION,
|
@@ -1118,6 +1149,11 @@ def SetAgent(Choice):
|
|
1118 |
elif Choice =='Conversation Agent':
|
1119 |
agent = agent_CONVERSATION
|
1120 |
print("Set to:", Choice)
|
|
|
|
|
|
|
|
|
|
|
1121 |
|
1122 |
global agent
|
1123 |
Choice = os.environ["agent_type"]
|
@@ -1636,7 +1672,8 @@ with gr.Blocks() as demo:
|
|
1636 |
|
1637 |
agentchoice = gr.Dropdown(
|
1638 |
choices=['Zero Short Agent','Zero Short React','OpenAI Multi',
|
1639 |
-
'Zero Short React 2','Zero Short Agent 2','None','Conversation Agent'
|
|
|
1640 |
label="SELECT AI AGENT",
|
1641 |
scale= 2,
|
1642 |
show_label = True,
|
|
|
111 |
!pip install python-pptx
|
112 |
"""
|
113 |
|
114 |
+
def Code_Runner(code_raw: str):
|
115 |
# interpreter = CodeInterpreter(language="python", debug_mode=True)
|
116 |
if '!pip' in code_raw:
|
117 |
code_raw=code_raw.replace('!pip', 'pip')
|
|
|
525 |
print(index.describe_index_stats())
|
526 |
|
527 |
ListAgentWithRemoteGPT = ['Zero Short React 2','Zero Short Agent 2',
|
528 |
+
'OpenAI Multi 2', 'Conversation Agent',
|
529 |
+
'Code Interpreter']
|
530 |
|
531 |
def SummarizeDoc():
|
532 |
global vectordb_p
|
|
|
739 |
description = "Useful when you need python script to answer questions. You should input python code."
|
740 |
)
|
741 |
|
742 |
+
python_tool3 = Tool(
|
743 |
+
name = "Code Runner",
|
744 |
+
func = Code_Runner,
|
745 |
+
description = "Code Interpreter which is able to run code block in local machine.\
|
746 |
+
It is capable to treat any task by running the code and output the result. (i.e. analyzer data, modify/creat documents ...)\
|
747 |
+
You should input python code."
|
748 |
+
)
|
749 |
|
750 |
|
751 |
# tools = [DB_Search(), wikipedia_tool, duckduckgo_tool, python_tool]
|
|
|
793 |
|
794 |
tools2 = [DB_Search2(), duckduckgo_tool2, wikipedia_tool2, python_tool2, math_tool, Text2Sound_tool2]
|
795 |
|
796 |
+
tools_remote = [DB_Search2(), duckduckgo_tool2, wikipedia_tool2, python_tool3, math_tool_2, Text2Sound_tool_loc]
|
797 |
|
798 |
# tools = load_tools(["Vector Database Search","Wikipedia Search","Python REPL","llm-math"], llm=llm)
|
799 |
|
|
|
1020 |
|
1021 |
)
|
1022 |
|
1023 |
+
agent_CODE_INTERPRETER = initialize_agent(tools_remote, GPTfake,
|
1024 |
+
# agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
1025 |
+
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
1026 |
+
verbose = True,
|
1027 |
+
handle_parsing_errors = True,
|
1028 |
+
max_iterations = int(os.environ["max_iterations"]),
|
1029 |
+
early_stopping_method="generate",
|
1030 |
+
memory = memory2,
|
1031 |
+
agent_kwargs={
|
1032 |
+
'prefix': PREFIX_2,
|
1033 |
+
'format_instructions': FORMAT_INSTRUCTIONS_3,
|
1034 |
+
'suffix': SUFFIX2,
|
1035 |
+
'input_variables': input_variables,
|
1036 |
+
|
1037 |
+
},
|
1038 |
+
# input_variables = input_variables,
|
1039 |
+
# agent_kwargs={
|
1040 |
+
# 'prompt': prompt,
|
1041 |
+
# }
|
1042 |
+
|
1043 |
+
)
|
1044 |
+
|
1045 |
+
|
1046 |
agent_CONVERSATION = initialize_agent(tools_remote, GPTfake,
|
1047 |
# agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
1048 |
agent=AgentType.CONVERSATIONAL_REACT_DESCRIPTION,
|
|
|
1149 |
elif Choice =='Conversation Agent':
|
1150 |
agent = agent_CONVERSATION
|
1151 |
print("Set to:", Choice)
|
1152 |
+
elif Choice =='Code Interpreter':
|
1153 |
+
agent = agent_CODE_INTERPRETER
|
1154 |
+
print("Set to:", Choice)
|
1155 |
+
|
1156 |
+
|
1157 |
|
1158 |
global agent
|
1159 |
Choice = os.environ["agent_type"]
|
|
|
1672 |
|
1673 |
agentchoice = gr.Dropdown(
|
1674 |
choices=['Zero Short Agent','Zero Short React','OpenAI Multi',
|
1675 |
+
'Zero Short React 2','Zero Short Agent 2','None','Conversation Agent',
|
1676 |
+
'Code Interpreter'],
|
1677 |
label="SELECT AI AGENT",
|
1678 |
scale= 2,
|
1679 |
show_label = True,
|