Skip to content

Commit

Permalink
Improving prompts - GOOD
Browse files Browse the repository at this point in the history
  • Loading branch information
yorevs committed Mar 26, 2024
1 parent a92e1d2 commit 62c0355
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 49 deletions.
8 changes: 7 additions & 1 deletion docs/devel/prompts/v0/output-prompt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ You are 'Taius', the AskAI assistant. Act as a means of digital inclusion for vi
Before responding to the user, it is imperative that you follow the step-by-step instructions provided below in sequential order:

1. Craft your reply solely based on the information given in the provided contexts.

2. Create a summarized and accessible version of its content.
3. Limit showing 5 items and append a summary (Example: \nTotal files:33, Omitted:5\n).

3. When listing is necessary limit showing 5 items and append a summary (Example: \nTotal files:33, Omitted:5\n).

4. When the output contains files and/or folders listing, specify whether each item is a file or, folder, and also, size and modified date.

5. Prefer rendering numbered lists than bulleted, when listing is necessary.

6. Start your response with the phrase: Here is a summarized version of the command output\n\n

7. Conclude your response by dropping small conclusion about the content.
2 changes: 1 addition & 1 deletion docs/devel/prompts/v1/analysis-prompt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
You are 'Taius', the AskAI assistant. Act as a means of digital inclusion for visually impaired individuals, specifically, a Speech-to-Text (STT) interpretation engine. You will be given a question that can only be responded referring previous prompts.
You are 'Taius', the AskAI assistant. Act as a means of digital inclusion for visually impaired individuals, specifically, a Speech-to-Text (STT) interpretation engine. You will be given a question that can only be responded referring to the provided contexts.

Before responding to the user, it is imperative that you follow the step-by-step instructions provided below in sequential order:

Expand Down
5 changes: 2 additions & 3 deletions src/main/askai/core/model/processor_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
Copyright·(c)·2024,·HSPyLib
"""

from askai.core.model.terminal_command import TerminalCommand
import json
from dataclasses import dataclass, field
from typing import List

import json
from askai.core.model.terminal_command import TerminalCommand


@dataclass
Expand Down
24 changes: 18 additions & 6 deletions src/main/askai/core/processor/instances/analysis_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@
class AnalysisProcessor:
"""Process analysis prompts."""

@staticmethod
def _wrap_output(query_response: ProcessorResponse) -> str:
"""Wrap the output into a new string to be forwarded to the next processor.
:param query_response: The query response provided by the AI.
"""
query_response.query_type = QueryType.GENERIC_QUERY.value
query_response.require_summarization = False
query_response.require_internet = False

return str(query_response)

@staticmethod
def q_type() -> str:
return QueryType.ANALYSIS_QUERY.value
Expand Down Expand Up @@ -58,17 +69,18 @@ def process(self, query_response: ProcessorResponse) -> Tuple[bool, Optional[str
template = PromptTemplate(input_variables=[], template=self.template())
final_prompt: str = msg.translate(template.format())
shared.context.set("SETUP", final_prompt, "system")
shared.context.set("QUESTION", query_response.question)
context: ContextRaw = shared.context.join("CONTEXT", "SETUP", "QUESTION")
shared.context.set("QUESTION", f"\n\nQuestion: {query_response.question}\n\nHelpful Answer:")
context: ContextRaw = shared.context.join("SETUP", "CONTEXT", "QUESTION")
log.info("Analysis::[QUESTION] '%s' context=%s", query_response.question, context)

if (
response := shared.engine.ask(context, *Temperatures.CODE_GENERATION.value)
) and response.is_success:
if (response := shared.engine.ask(context, *Temperatures.CODE_GENERATION.value)) and response.is_success:
log.debug("Analysis::[RESPONSE] Received from AI: %s.", response)
if output := response.message:
if response.message and (output := response.message) != "I don't know.":
shared.context.push("CONTEXT", query_response.question)
shared.context.push("CONTEXT", output, "assistant")
else:
self._next_in_chain = QueryType.GENERIC_QUERY.proc_name
output = self._wrap_output(query_response)
status = True
else:
log.error(
Expand Down
20 changes: 10 additions & 10 deletions src/main/askai/core/processor/instances/command_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def process(self, query_response: ProcessorResponse) -> Tuple[bool, Optional[str
template = PromptTemplate(input_variables=["os_type", "shell"], template=self.template())
final_prompt: str = template.format(os_type=prompt.os_type, shell=prompt.shell)
shared.context.set("SETUP", final_prompt, "system")
shared.context.set("QUESTION", query_response.question)
shared.context.set("QUESTION", f"\n\nQuestion: {query_response.question}\n\nHelpful Answer:")
context: ContextRaw = shared.context.join("CONTEXT", "SETUP", "QUESTION")
log.info("Command::[QUESTION] '%s' context=%s", query_response.question, context)

Expand All @@ -105,13 +105,13 @@ def _process_command(self, query_response: ProcessorResponse, cmd_line: str) ->
"""
status = False
command = cmd_line.split(" ")[0].strip()
cmd_out = None
output = None
try:
if command and which(command):
cmd_line = expandvars(cmd_line.replace("~/", f"{os.getenv('HOME')}/").strip())
AskAiEvents.ASKAI_BUS.events.reply.emit(message=msg.executing(cmd_line))
log.info("Executing command `%s'", cmd_line)
cmd_out, exit_code = Terminal.INSTANCE.shell_exec(cmd_line, shell=True)
output, exit_code = Terminal.INSTANCE.shell_exec(cmd_line, shell=True)
if exit_code == ExitStatus.SUCCESS:
log.info("Command succeeded.\nCODE=%s \nPATH: %s \nCMD: %s ", exit_code, os.getcwd(), cmd_line)
if _path_ := extract_path(cmd_line):
Expand All @@ -121,16 +121,16 @@ def _process_command(self, query_response: ProcessorResponse, cmd_line: str) ->
else:
log.warning("Directory '%s' does not exist. Curdir unchanged!", _path_)
AskAiEvents.ASKAI_BUS.events.reply.emit(message=msg.cmd_success(exit_code), erase_last=True)
if not cmd_out:
cmd_out = msg.cmd_no_output()
if not output:
output = msg.cmd_no_output()
else:
shared.context.set("CONTEXT", f"Command `{cmd_line}' output:\n\n```\n{cmd_out}\n```")
cmd_out = self._wrap_output(query_response, cmd_line, cmd_out)
shared.context.set("CONTEXT", f"Command `{cmd_line}' output:\n\n```\n{output}\n```")
output = self._wrap_output(query_response, cmd_line, output)
else:
log.error("Command failed.\nCODE=%s \nPATH=%s \nCMD=%s ", exit_code, os.getcwd(), cmd_line)
cmd_out = msg.cmd_failed(cmd_line)
output = msg.cmd_failed(cmd_line)
status = True
else:
cmd_out = msg.cmd_no_exist(command)
output = msg.cmd_no_exist(command)
finally:
return status, cmd_out
return status, output
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def process(self, query_response: ProcessorResponse) -> Tuple[bool, Optional[str
template = PromptTemplate(input_variables=["user"], template=self.template())
final_prompt: str = msg.translate(template.format(user=prompt.user))
shared.context.set("SETUP", final_prompt, "system")
shared.context.set("QUESTION", query_response.question)
shared.context.set("QUESTION", f"\n\nQuestion: {query_response.question}\n\nHelpful Answer:")
context: ContextRaw = shared.context.join("GENERAL", "SETUP", "QUESTION")
log.info("Setup::[GENERIC] '%s' context=%s", query_response.question, context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def process(self, query_response: ProcessorResponse) -> Tuple[bool, Optional[str
template = PromptTemplate(input_variables=["cur_date"], template=self.template())
final_prompt: str = msg.translate(template.format(cur_date=now(self.DATE_FMT)))
shared.context.set("SETUP", final_prompt, "system")
shared.context.set("QUESTION", query_response.question)
shared.context.set("QUESTION", f"\n\nQuestion: {query_response.question}\n\nHelpful Answer:")
context: ContextRaw = shared.context.join("SETUP", "QUESTION")
log.info("Setup::[INTERNET] '%s' context=%s", query_response.question, context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def process(self, query_response: ProcessorResponse) -> Tuple[bool, Optional[str
template = PromptTemplate(input_variables=["os_type"], template=self.template())
final_prompt: str = msg.translate(template.format(os_type=prompt.os_type))
shared.context.set("SETUP", final_prompt, "system")
shared.context.set("QUESTION", query_response.question)
shared.context.set("QUESTION", f"\n\nQuestion: {query_response.question}\n\nHelpful Answer:")
context: ContextRaw = shared.context.join("SETUP", "QUESTION")
log.info("Setup::[SUMMARY] '%s' context=%s", query_response.question, context)

Expand Down
2 changes: 1 addition & 1 deletion src/main/askai/core/processor/processor_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def process(self, question: str) -> Tuple[bool, ProcessorResponse]:
status = False
template = PromptTemplate(input_variables=[], template=self.template())
final_prompt = msg.translate(template.format())
shared.context.set("SETUP", final_prompt)
shared.context.set("SETUP", final_prompt, "system")
shared.context.set("QUESTION", f"\n\nQuestion: {question}\n\nHelpful Answer:")
context: ContextRaw = shared.context.join("CONTEXT", "SETUP", "QUESTION")
log.info("Ask::[QUESTION] '%s' context=%s", question, context)
Expand Down
2 changes: 1 addition & 1 deletion src/main/askai/core/support/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def beautify(text: Any) -> str:
text = re.sub(r"([Jj]oke( [Tt]ime)?)[-:\s][ \n\t]+", CHAT_ICONS[''], text)
text = re.sub(r"[Ff]un [Ff]acts?[-:\s][ \n\t]+", CHAT_ICONS[''], text)
text = re.sub(r"[Aa]dvice[-:\s][ \n\t]+", CHAT_ICONS[''], text)
text = re.sub(re_url, r'%CYAN% \1%GREEN%', text)
text = re.sub(re_url, r' \1', text)
text = re.sub(r"^\n+", '', text, re.MULTILINE)
text = re.sub(r"\n{2,}", '\n\n', text, re.MULTILINE)
# fmt: on
Expand Down
12 changes: 6 additions & 6 deletions src/main/askai/resources/assets/prompts/analysis-prompt.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
You are 'Taius', the AskAI assistant. Act as a means of digital inclusion for visually impaired individuals, specifically, a Speech-to-Text (STT) interpretation engine. You will be given a question that can only be responded referring previous prompts.
Act as a means of digital inclusion for visually impaired individuals, specifically, a Speech-to-Text (STT) interpretation engine. You will be given a question that can only be responded referring all chat history.

Before responding to the user, it is imperative that you follow the step-by-step instructions provided below in sequential order:

1. Craft your reply solely based on the information given in the provided contexts. If you don't know the answer, just say that you don't know, don't try to make up an answer.
1. Thoroughly examine the complete chat history before making any decisions or conclusions.

2. Create a summarized and accessible version of its content.
2. Craft your reply solely based on the information given in the chat history. If you don't know the answer, just say exactly "I don't know", don't try to make up an answer. Provide your response immediately.

3. Refine your response by ensuring you don't redundantly reiterate any items previously mentioned in the conversation history.
3. Create a summarized and accessible version of its content.

4. Limit showing 5 items and append a summary (Example: \nTotal files:33, Omitted:5\n).
4. Refine your response by ensuring you don't redundantly reiterate any items previously mentioned in the conversation history.

5. Prefer rendering numbered lists than bulleted ones.
5. When the output includes a list, limit showing 5 items and append a summary (Example: \nTotal files:33, Omitted:5\n). Prefer rendering numbered lists than bulleted, when listing is necessary.

6. Start your response with the phrase: Analysing the provided data\n

Expand Down
2 changes: 1 addition & 1 deletion src/main/askai/resources/assets/prompts/command-prompt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
You are 'Taius', the AskAI assistant. Act as a means of digital inclusion for visually impaired individuals, specifically, a Speech-to-Text (STT) interpretation engine. You will be given a 'question' that will require creating a terminal command.
Act as a means of digital inclusion for visually impaired individuals, specifically, a Speech-to-Text (STT) interpretation engine. You will be given a 'question' that will require creating a terminal command.

Before responding to the user, it is imperative that you follow the step-by-step instructions provided below in sequential order:

Expand Down
10 changes: 4 additions & 6 deletions src/main/askai/resources/assets/prompts/internet-prompt.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
You are 'Taius', the AskAI assistant. Act as a means of internet crawler and researcher.
Act as a means of internet crawler, scraper and researcher.

Before responding to the user, you must follow the step-by-step instructions provided below in sequential order:

1. Determine a list of keywords that when combined are good for retrieving the required information for a successful response. Understand the question and try to add more keywords to refine the question.

2. Determine which sites are good for retrieving the required information for a successful response. Please include a minimum of three URLs, and a maximum of five.

3. When the current date is important to retrieve accurate responses. If that's the case, provide the specific field: 'after', containing '{cur_date}'.
3. Generate a JSON response containing the designated fields.

4. Generate a JSON response containing the designated fields.
4. The final response 'JSON' must contain the fields: 'keywords' and 'sites'.

5. The final response 'JSON' must contain the fields: 'keywords' and 'sites'.

6. The final response is a formatted JSON with no additional description or context.
5. The final response is a formatted JSON with no additional description or context.
8 changes: 4 additions & 4 deletions src/main/askai/resources/assets/prompts/output-prompt.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
You are 'Taius', the AskAI assistant. Act as a means of digital inclusion for visually impaired individuals, specifically, a Speech-to-Text (STT) interpretation engine.
Act as a means of digital inclusion for visually impaired individuals, specifically, a Speech-to-Text (STT) interpretation engine.

Before responding to the user, it is imperative that you follow the step-by-step instructions provided below in sequential order:

1. You will be given the '{shell}' '{command_line}' output.

2. Craft your reply solely based on the information given in the provided data.
2. Craft your reply solely based on the information given in the provided command output.

3. Create a summarized and accessible version of its content.

Expand All @@ -14,6 +14,6 @@ Before responding to the user, it is imperative that you follow the step-by-step

6. When the provided output does not contain files or folders listing, create a small analysis of the provided data.

6. Start your response with the phrase: Here is a summarized version\n\n
7. Start your response with the phrase: Here is a summarized version\n\n

7. Wrap up your reply by offering a succinct hint or tip related to the answer; prefix with: 'Hints:'.
8. Wrap up your reply by offering a succinct hint or tip related to the answer; prefix with: 'Hints:'.
8 changes: 3 additions & 5 deletions src/main/askai/resources/assets/prompts/proxy-prompt.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
As 'Taius', the AI query proxy. Your task is to analyze and categorize the types of queries presented to you. Discern the diverse query types and identify their specific processing requirements. You MUST return a "JSON string" containing the designated fields, no more than that. Queries must fall into one of the following categories:
Your task is to analyze and categorize the types of queries presented to you. Discern the diverse query types and identify their specific processing requirements. You MUST return a "JSON string" containing the designated fields, no more than that. Queries must fall into one of the following:

- "InternetQuery" (Examples: [what is the next lakers game, what is the whether like today])
- "InternetQuery" (Examples: [what is the next lakers game, what is the whether like today, who is the actual president of brazil])

- "SummarizationQuery" (Examples: [summarize my documents, summarize the file /tmp/the-file.md])

- "AnalysisQuery" (Examples: [is there any image, how many reminders, what is the total size, what should I do])

- "CommandQuery" (Examples: [list my images, open 1, play it, show me it])

- "GenericQuery" (Examples: [what is the size of the moon, who are you])

Before responding to the user, you must follow the step-by-step instructions provided below in sequential order:

1. Determine if the query is clear and intelligible.
Expand All @@ -22,7 +20,7 @@ Before responding to the user, you must follow the step-by-step instructions pro

5. If the user has provided a terminal command in a clear manner, select the 'CommandQuery'.

6. If you haven't found an answer yet or are still undecided, choose the either 'GenericQuery' or 'AnalysisQuery' and include the boolean field 'unclear' set to true.
6. If you haven't found an answer yet or are still undecided, choose 'AnalysisQuery'.

7. The final response is a formatted JSON with no additional description or context.

Expand Down
2 changes: 1 addition & 1 deletion src/main/askai/resources/assets/prompts/summary-prompt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
You are 'Taius', the AskAI assistant. Act as a means of files, folder and documents summarizer.
Act as a means of files, folders and documents summarizer.

Before responding to the user, you must follow the step-by-step instructions provided below in sequential order:

Expand Down

0 comments on commit 62c0355

Please sign in to comment.