Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document fix #806

Merged
merged 4 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion superagi/agent/output_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@ def parse(self, response: str) -> AgentGPTAction:
)
except BaseException as e:
logger.info(f"AgentSchemaOutputParser: Error parsing JSON respons {e}")
return {}
2 changes: 1 addition & 1 deletion superagi/agent/super_agi.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def execute(self, workflow_step: AgentWorkflowStep):
def handle_tool_response(self, session, assistant_reply):
action = self.output_parser.parse(assistant_reply)
tools = {t.name.lower().replace(" ", ""): t for t in self.tools}
action_name = action.name.lower().replace(" ", "")
action_name = action.name.lower().replace(" ", "") if action is not None else ""
agent = session.query(Agent).filter(Agent.id == self.agent_config["agent_id"],).first()
organisation = agent.get_agent_organisation(session)
if action_name == FINISH or action.name == "":
Expand Down
2 changes: 2 additions & 0 deletions superagi/resource_manager/llama_document_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def generate_summary_of_document(self, documents: list[Document]):
:param documents: list of Document objects
:return: summary of the documents
"""
if documents is None or not documents:
return
from llama_index import LLMPredictor, ServiceContext, ResponseSynthesizer, DocumentSummaryIndex
os.environ["OPENAI_API_KEY"] = get_config("OPENAI_API_KEY", "") or self.model_api_key
llm_predictor_chatgpt = LLMPredictor(llm=self._build_llm())
Expand Down
9 changes: 5 additions & 4 deletions superagi/resource_manager/resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def create_llama_document(self, file_path: str):
"""
if file_path is None:
raise Exception("file_path must be provided")
documents = SimpleDirectoryReader(input_files=[file_path]).load_data()

return documents
if os.path.exists(file_path):
documents = SimpleDirectoryReader(input_files=[file_path]).load_data()
return documents

def create_llama_document_s3(self, file_path: str):
"""
Expand All @@ -44,6 +44,7 @@ def create_llama_document_s3(self, file_path: str):
"""
if file_path is None:
raise Exception("file_path must be provided")
temporary_file_path = ""
try:
import boto3
s3 = boto3.client(
Expand All @@ -61,12 +62,12 @@ def create_llama_document_s3(self, file_path: str):
f.write(contents)

documents = SimpleDirectoryReader(input_files=[temporary_file_path]).load_data()
return documents
except Exception as e:
logger.error("superagi/resource_manager/resource_manager.py - create_llama_document_s3 threw : ", e)
finally:
if os.path.exists(temporary_file_path):
os.remove(temporary_file_path)
return documents

def save_document_to_vector_store(self, documents: list, resource_id: str, mode_api_key: str = None,
model_source: str = ""):
Expand Down
3 changes: 2 additions & 1 deletion superagi/resource_manager/resource_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def generate_agent_summary(self, agent_id: int, generate_all: bool = False) -> s
documents = ResourceManager(str(agent_id)).create_llama_document_s3(file_path)
else:
documents = ResourceManager(str(agent_id)).create_llama_document(file_path)
summary_texts.append(LlamaDocumentSummary(model_api_key=model_api_key, model_source=model_source).generate_summary_of_document(documents))
if documents is not None and len(documents) > 0:
summary_texts.append(LlamaDocumentSummary(model_api_key=model_api_key, model_source=model_source).generate_summary_of_document(documents))

agent_last_resource = self.session.query(AgentConfiguration). \
filter(AgentConfiguration.agent_id == agent_id,
Expand Down