diff --git a/superagi/resource_manager/resource_summary.py b/superagi/resource_manager/resource_summary.py index fb76d3fb0..40462a5c9 100644 --- a/superagi/resource_manager/resource_summary.py +++ b/superagi/resource_manager/resource_summary.py @@ -33,14 +33,6 @@ def add_to_vector_store_and_create_summary(self, agent_id: int, resource_id: int ResourceManager(str(agent_id)).save_document_to_vector_store(documents, str(resource_id), model_api_key, model_source) except Exception as e: logger.error("add_to_vector_store_and_create_summary: Unable to save document to vector store.", e) - summary = None - try: - summary = LlamaDocumentSummary(model_api_key=model_api_key).generate_summary_of_document(documents) - except Exception as e: - logger.error("add_to_vector_store_and_create_summary - Unable to generate summary of document.", e) - resource = self.session.query(Resource).filter(Resource.id == resource_id).first() - resource.summary = summary - self.session.commit() def generate_agent_summary(self, agent_id: int, generate_all: bool = False) -> str: """Generate a summary of all resources for an agent.""" @@ -51,36 +43,11 @@ def generate_agent_summary(self, agent_id: int, generate_all: bool = False) -> s if not resources: return - agent = self.session.query(Agent).filter(Agent.id == agent_id).first() - organization = agent.get_agent_organisation(self.session) - model_api_key = Configuration.fetch_configuration(self.session, organization.id, "model_api_key") - model_source = Configuration.fetch_configuration(self.session, organization.id, "model_source") - - summary_texts = [resource.summary for resource in resources if resource.summary is not None] - - # generate_all is added because we want to generate summary for all resources when agent is created - # this is set to false when adding individual resources - if len(summary_texts) < len(resources) and generate_all: - file_paths = [resource.path for resource in resources if resource.summary is None] - for file_path in file_paths: - if resources[0].storage_type == 'S3': - documents = ResourceManager(str(agent_id)).create_llama_document_s3(file_path) - else: - documents = ResourceManager(str(agent_id)).create_llama_document(file_path) - 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)) - + resource_summary = " ".join([resource.name for resource in resources]) agent_last_resource = self.session.query(AgentConfiguration). \ filter(AgentConfiguration.agent_id == agent_id, AgentConfiguration.key == "last_resource_time").first() - if agent_last_resource is not None and \ - datetime.strptime(agent_last_resource.value, '%Y-%m-%d %H:%M:%S.%f') == resources[-1].updated_at \ - and not generate_all: - return - resource_summary = summary_texts[0] if summary_texts else None - if len(summary_texts) > 1: - resource_summary = LlamaDocumentSummary(model_api_key=model_api_key).generate_summary_of_texts(summary_texts) if agent_config_resource_summary is not None: agent_config_resource_summary.value = resource_summary diff --git a/superagi/tools/resource/query_resource.py b/superagi/tools/resource/query_resource.py index 66bb53679..031b941fd 100644 --- a/superagi/tools/resource/query_resource.py +++ b/superagi/tools/resource/query_resource.py @@ -35,7 +35,7 @@ class QueryResourceTool(BaseTool): args_schema: Type[BaseModel] = QueryResource description: str = "Tool searches resources content and extracts relevant information to perform the given task." \ "Tool is given preference over other search/read file tools for relevant data." \ - "Resources content includes: {summary}" + "Resources content is taken from the files: {summary}" agent_id: int = None llm: Optional[BaseLlm] = None diff --git a/superagi/worker.py b/superagi/worker.py index 95e5430a0..c0f614a69 100644 --- a/superagi/worker.py +++ b/superagi/worker.py @@ -77,5 +77,4 @@ def summarize_resource(agent_id: int, resource_id: int): resource_summarizer.add_to_vector_store_and_create_summary(agent_id=agent_id, resource_id=resource_id, documents=documents) - resource_summarizer.generate_agent_summary(agent_id=agent_id) session.close()