Spaces:
Runtime error
Runtime error
Commit
·
9a3cbb5
1
Parent(s):
fbf6894
Add current Agent
Browse files
app.py
CHANGED
|
@@ -90,11 +90,16 @@ from codeinterpreterapi import CodeInterpreterSession
|
|
| 90 |
import html2text
|
| 91 |
|
| 92 |
from interpreter.code_interpreter import CodeInterpreter
|
| 93 |
-
from interpreter.code_block import CodeBlock
|
| 94 |
|
| 95 |
import regex
|
| 96 |
|
|
|
|
|
|
|
| 97 |
class CodeBlock:
|
|
|
|
|
|
|
|
|
|
| 98 |
def __init__(self, code):
|
| 99 |
self.code = code
|
| 100 |
self.output = ""
|
|
@@ -115,7 +120,9 @@ code_2 = """
|
|
| 115 |
|
| 116 |
def Code_Runner(code_raw: str):
|
| 117 |
# interpreter = CodeInterpreter(language="python", debug_mode=True)
|
| 118 |
-
|
|
|
|
|
|
|
| 119 |
if '!pip' in code_raw:
|
| 120 |
code_raw=code_raw.replace('!pip', 'pip')
|
| 121 |
interpreter = CodeInterpreter(language="shell", debug_mode=True)
|
|
@@ -278,9 +285,9 @@ class GPTRemote(LLM):
|
|
| 278 |
if 'Action:' in output and 'Observation:' in output:
|
| 279 |
output = output.split('Observation:')[0]
|
| 280 |
|
| 281 |
-
global
|
| 282 |
# if Choice == "Structured Zero Short Agent":
|
| 283 |
-
if
|
| 284 |
try:
|
| 285 |
# temp = output.split('{')[1].split('}')[0:-2]
|
| 286 |
pattern = r'\{((?:[^{}]|(?R))*)\}'
|
|
@@ -567,6 +574,7 @@ ListAgentWithRemoteGPT = ['Zero Short React 2','Zero Short Agent 2',
|
|
| 567 |
def SummarizeDoc():
|
| 568 |
global vectordb_p
|
| 569 |
global Choice
|
|
|
|
| 570 |
# pinecone.Index(index_name).delete(delete_all=True, namespace='')
|
| 571 |
# collection = vectordb_p.get()
|
| 572 |
# split_docs = process_documents([metadata['source'] for metadata in collection['metadatas']])
|
|
@@ -576,7 +584,7 @@ def SummarizeDoc():
|
|
| 576 |
print(split_docs[tt-1])
|
| 577 |
sum_text=""
|
| 578 |
try:
|
| 579 |
-
if
|
| 580 |
sum_chain = load_summarize_chain(GPTfake, chain_type='refine', verbose=True)
|
| 581 |
else:
|
| 582 |
sum_chain = load_summarize_chain(llm, chain_type='refine', verbose=True)
|
|
@@ -1161,9 +1169,12 @@ agent_OPENAI_MULTI = AgentExecutor.from_agent_and_tools(
|
|
| 1161 |
# agent.max_execution_time = int(os.getenv("max_iterations"))
|
| 1162 |
# agent.handle_parsing_errors = True
|
| 1163 |
# agent.early_stopping_method = "generate"
|
|
|
|
|
|
|
| 1164 |
|
| 1165 |
def SetAgent(Choice):
|
| 1166 |
global agent
|
|
|
|
| 1167 |
if Choice =='Zero Short Agent':
|
| 1168 |
agent = agent_ZEROSHOT_AGENT
|
| 1169 |
print("Set to:", Choice)
|
|
@@ -1191,7 +1202,9 @@ def SetAgent(Choice):
|
|
| 1191 |
elif Choice =='Structured Zero Short Agent':
|
| 1192 |
agent = agent_STRUCTURED_ZEROSHOT_REACT
|
| 1193 |
print("Set to:", Choice)
|
| 1194 |
-
|
|
|
|
|
|
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
|
@@ -1870,12 +1883,13 @@ def QAQuery_p(question: str):
|
|
| 1870 |
global vectordb_p
|
| 1871 |
global agent
|
| 1872 |
global Choice
|
|
|
|
| 1873 |
# vectordb = Chroma(persist_directory='db', embedding_function=embeddings)
|
| 1874 |
retriever = vectordb_p.as_retriever()
|
| 1875 |
retriever.search_kwargs['k'] = int(os.environ["search_kwargs_k"])
|
| 1876 |
# retriever.search_kwargs['fetch_k'] = 100
|
| 1877 |
# if agent == agent_ZEROSHOT_REACT_2 or agent == agent_ZEROSHOT_AGENT_2:
|
| 1878 |
-
if
|
| 1879 |
print("--------------- QA with Remote --------------")
|
| 1880 |
qa = RetrievalQA.from_chain_type(llm=GPTfake, chain_type="stuff",
|
| 1881 |
retriever=retriever, return_source_documents = True,
|
|
|
|
| 90 |
import html2text
|
| 91 |
|
| 92 |
from interpreter.code_interpreter import CodeInterpreter
|
| 93 |
+
# from interpreter.code_block import CodeBlock
|
| 94 |
|
| 95 |
import regex
|
| 96 |
|
| 97 |
+
|
| 98 |
+
|
| 99 |
class CodeBlock:
|
| 100 |
+
'''
|
| 101 |
+
CodeBlock Class which is able to run in Code Runner
|
| 102 |
+
'''
|
| 103 |
def __init__(self, code):
|
| 104 |
self.code = code
|
| 105 |
self.output = ""
|
|
|
|
| 120 |
|
| 121 |
def Code_Runner(code_raw: str):
|
| 122 |
# interpreter = CodeInterpreter(language="python", debug_mode=True)
|
| 123 |
+
global CurrentAgent
|
| 124 |
+
if CurrentAgent == "Zero Short React 2":
|
| 125 |
+
code_raw = RemoveIndent(code_raw)
|
| 126 |
if '!pip' in code_raw:
|
| 127 |
code_raw=code_raw.replace('!pip', 'pip')
|
| 128 |
interpreter = CodeInterpreter(language="shell", debug_mode=True)
|
|
|
|
| 285 |
if 'Action:' in output and 'Observation:' in output:
|
| 286 |
output = output.split('Observation:')[0]
|
| 287 |
|
| 288 |
+
global CurrentAgent
|
| 289 |
# if Choice == "Structured Zero Short Agent":
|
| 290 |
+
if CurrentAgent == 'Structured Zero Short Agent':
|
| 291 |
try:
|
| 292 |
# temp = output.split('{')[1].split('}')[0:-2]
|
| 293 |
pattern = r'\{((?:[^{}]|(?R))*)\}'
|
|
|
|
| 574 |
def SummarizeDoc():
|
| 575 |
global vectordb_p
|
| 576 |
global Choice
|
| 577 |
+
global CurrentAgent
|
| 578 |
# pinecone.Index(index_name).delete(delete_all=True, namespace='')
|
| 579 |
# collection = vectordb_p.get()
|
| 580 |
# split_docs = process_documents([metadata['source'] for metadata in collection['metadatas']])
|
|
|
|
| 584 |
print(split_docs[tt-1])
|
| 585 |
sum_text=""
|
| 586 |
try:
|
| 587 |
+
if CurrentAgent in ListAgentWithRemoteGPT:
|
| 588 |
sum_chain = load_summarize_chain(GPTfake, chain_type='refine', verbose=True)
|
| 589 |
else:
|
| 590 |
sum_chain = load_summarize_chain(llm, chain_type='refine', verbose=True)
|
|
|
|
| 1169 |
# agent.max_execution_time = int(os.getenv("max_iterations"))
|
| 1170 |
# agent.handle_parsing_errors = True
|
| 1171 |
# agent.early_stopping_method = "generate"
|
| 1172 |
+
global CurrentAgent
|
| 1173 |
+
CurrentAgent = ""
|
| 1174 |
|
| 1175 |
def SetAgent(Choice):
|
| 1176 |
global agent
|
| 1177 |
+
global CurrentAgent
|
| 1178 |
if Choice =='Zero Short Agent':
|
| 1179 |
agent = agent_ZEROSHOT_AGENT
|
| 1180 |
print("Set to:", Choice)
|
|
|
|
| 1202 |
elif Choice =='Structured Zero Short Agent':
|
| 1203 |
agent = agent_STRUCTURED_ZEROSHOT_REACT
|
| 1204 |
print("Set to:", Choice)
|
| 1205 |
+
|
| 1206 |
+
CurrentAgent = Choice
|
| 1207 |
+
return CurrentAgent
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
|
|
|
| 1883 |
global vectordb_p
|
| 1884 |
global agent
|
| 1885 |
global Choice
|
| 1886 |
+
global CurrentAgent
|
| 1887 |
# vectordb = Chroma(persist_directory='db', embedding_function=embeddings)
|
| 1888 |
retriever = vectordb_p.as_retriever()
|
| 1889 |
retriever.search_kwargs['k'] = int(os.environ["search_kwargs_k"])
|
| 1890 |
# retriever.search_kwargs['fetch_k'] = 100
|
| 1891 |
# if agent == agent_ZEROSHOT_REACT_2 or agent == agent_ZEROSHOT_AGENT_2:
|
| 1892 |
+
if CurrentAgent in ListAgentWithRemoteGPT:
|
| 1893 |
print("--------------- QA with Remote --------------")
|
| 1894 |
qa = RetrievalQA.from_chain_type(llm=GPTfake, chain_type="stuff",
|
| 1895 |
retriever=retriever, return_source_documents = True,
|