Skip to content

Commit

Permalink
improved analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-XT committed Jul 3, 2024
1 parent e95dddc commit 91c52e1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
27 changes: 21 additions & 6 deletions agixt/Interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,18 @@ async def format_prompt(
conversation_name = "-"
c = Conversations(conversation_name=conversation_name, user=self.user)
conversation = c.get_conversation()
conversation_id = c.get_conversation_id()
conversation_outputs = (
f"http://localhost:7437/outputs/{self.agent.agent_id}/{conversation_id}/"
)
if top_results == 0:
context = []
else:
if user_input:
if self.websearch == None or self.websearch.collection_number == "1":
conversation_id = c.get_conversation_id()

self.websearch = Websearch(
collection_number=str(conversation_id),
collection_number=conversation_id,
agent=self.agent,
user=self.user,
ApiClient=self.ApiClient,
Expand Down Expand Up @@ -249,11 +253,11 @@ async def format_prompt(
context.append([kwargs["context"]])
if vision_response != "":
context.append(
f"{self.agent_name}'s visual description from viewing uploaded images by user in this interaction:\n{vision_response}\n"
f"The assistant's visual description from viewing uploaded images by user in this interaction:\n{vision_response}\n"
)
if context != [] and context != "":
context = "\n".join(context)
context = f"The user's input causes you remember these things:\n{context}\n\nIf referencing a file, paper, or website, cite sources.\n"
context = f"The user's input causes the assistant to recall these memories from activities:\n{context}\n\n**If referencing a file or image from context to the user, link to it with a url at `{conversation_outputs}the_file_name` .** .\n"
else:
context = ""
working_directory = self.agent.working_directory
Expand Down Expand Up @@ -409,6 +413,7 @@ async def format_prompt(
"conversation_history",
"persona",
"import_files",
"output_url",
]
args = kwargs.copy()
for arg in kwargs:
Expand All @@ -427,6 +432,7 @@ async def format_prompt(
conversation_history=conversation_history,
persona=persona,
import_files=file_contents,
output_url=f"{self.outputs}/{c.get_conversation_id()}/",
**args,
)
tokens = get_tokens(formatted_prompt)
Expand Down Expand Up @@ -520,6 +526,7 @@ async def run(
if conversation_name == "":
conversation_name = "-"
c = Conversations(conversation_name=conversation_name, user=self.user)
conversation_id = c.get_conversation_id()
async_tasks = []
vision_response = ""
if "vision_provider" in self.agent.AGENT_CONFIG["settings"]:
Expand Down Expand Up @@ -547,9 +554,8 @@ async def run(
)
logging.error(f"Error getting vision response: {e}")
if self.websearch == None or self.websearch.collection_number == "1":
conversation_id = c.get_conversation_id()
self.websearch = Websearch(
collection_number=str(conversation_id),
collection_number=conversation_id,
agent=self.agent,
user=self.user,
ApiClient=self.ApiClient,
Expand Down Expand Up @@ -668,6 +674,11 @@ async def run(
vision_response=vision_response,
**kwargs,
)
if self.outputs in formatted_prompt:
# Anonymize AGiXT server URL to LLM
formatted_prompt = formatted_prompt.replace(
self.outputs, f"http://localhost:7437/outputs/{self.agent.agent_id}"
)
logging.info(f"Formatted Prompt: {formatted_prompt}")
log_message = (
user_input
Expand Down Expand Up @@ -695,6 +706,10 @@ async def run(
message=f"[ACTIVITY][ERROR] Unable to generate response.",
)
return f"Unable to retrieve response."
# Deanonymize AGiXT server URL to send back to the user
self.response = self.response.replace(
f"http://localhost:7437/outputs/{self.agent.agent_id}", self.outputs
)
# Handle commands if the prompt contains the {COMMANDS} placeholder
# We handle command injection that DOESN'T allow command execution by using {command_list} in the prompt
if "{COMMANDS}" in unformatted_prompt:
Expand Down
22 changes: 17 additions & 5 deletions agixt/XT.py
Original file line number Diff line number Diff line change
Expand Up @@ -1836,7 +1836,7 @@ async def analyze_csv(
file_preview = "\n".join(lines)
c.log_interaction(
role=self.agent_name,
message=f"[ACTIVITY] Analyzing data from file.",
message=f"[ACTIVITY] Analyzing data from file `{file_name}`.",
)
code_interpreter = await self.inference(
user_input=user_input,
Expand Down Expand Up @@ -1883,13 +1883,25 @@ async def analyze_csv(
conversation_name=conversation_name,
)
if not code_execution.startswith("Error"):
c.log_interaction(
role=self.agent_name,
message=f"[ACTIVITY] Data analysis complete.",
# Write to conversation memories
collection_id = c.get_conversation_id()
file_reader = FileReader(
agent_name=self.agent_name,
agent_config=self.agent.AGENT_CONFIG,
collection_number=collection_id,
ApiClient=self.ApiClient,
user=self.user_email,
)
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
file_name_string = ", ".join(file_names)
await file_reader.write_text_to_memory(
user_input=user_input,
text=f"Results from data analysis on {file_name_string} at {timestamp}:\n{code_execution}",
external_source=f"files {file_name_string}",
)
c.log_interaction(
role=self.agent_name,
message=f"## Results from analyzing data:\n{code_execution}",
message=f"[ACTIVITY] Writing report on analysis.",
)
else:
self.failures += 1
Expand Down

0 comments on commit 91c52e1

Please sign in to comment.