Skip to content

Commit

Permalink
New proxy structure - 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Saporetti Junior committed Mar 25, 2024
1 parent 58d26fe commit c7f2719
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 38 deletions.
13 changes: 3 additions & 10 deletions docs/devel/askai-questions.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
Questions:

1. summarize my markdown files at my HomeSetup docs folder.
2.

Queries should fall into one of the following categories:

- File/Folder management/accessment
- Internet research
- File/Folder summarization
- Text summarization
- Data analysis
- Command execution
2. what is the weather like today in belo horizonte?
3. when is the next Flamengo game?
4. Who is the current Brazil president?
12 changes: 4 additions & 8 deletions src/main/askai/core/processor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
"""Package initialization."""

__all__ = [
'processor_base.py',
'analysis_processor',
'command_processor',
'generic_processor',
'internet_processor',
'output_processor',
'processor_proxy',
'summary_processor'
'instances',
'processor_base',
'processor_factory',
'processor_proxy'
]
__version__ = '1.0.1'
16 changes: 16 additions & 0 deletions src/main/askai/core/processor/instances/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# _*_ coding: utf-8 _*_
#
# 'askai' v1.0.1
#
# Package: main.askai.core.processor.instances
"""Package initialization."""

__all__ = [
'analysis_processor',
'command_processor',
'generic_processor',
'internet_processor',
'output_processor',
'summary_processor'
]
__version__ = '1.0.1'
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AnalysisProcessor:
def __init__(self):
self._template_file: str = "analysis-prompt"
self._next_in_chain: AIProcessor | None = None
self._supports: List[str] = ["Text summarization", "Data analysis", "Informational"]
self._supports: List[str] = ["Data analysis", "Informational"]

def supports(self, query_type: str) -> bool:
return query_type in self._supports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _wrap_output(query_response: QueryResponse, cmd_line: str, cmd_out: str) ->
def __init__(self):
self._template_file: str = "command-prompt"
self._next_in_chain: str = OutputProcessor.__name__
self._supports: List[str] = ['Command execution', 'File/Folder management/assessment']
self._supports: List[str] = ["Command execution"]

def supports(self, query_type: str) -> bool:
return query_type in self._supports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GenericProcessor:
def __init__(self):
self._template_file: str = "generic-prompt"
self._next_in_chain: AIProcessor | None = None
self._supports: List[str] = ['Current AI Database research', 'General']
self._supports: List[str] = ['AI Database', 'General']

def supports(self, query_type: str) -> bool:
return query_type in self._supports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class InternetProcessor:
DATE_FMT: str = "%a %d %b %-H:%M %Y" # E.g:. Fri 22 Mar 19:47 2024

def __init__(self):
self._template_file: str = "generic-prompt"
self._template_file: str = "internet-prompt"
self._next_in_chain: AIProcessor | None = None
self._supports: List[str] = ['Internet research']

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _ask_and_reply(question: str) -> Optional[str]:
def __init__(self):
self._template_file: str = "summary-prompt"
self._next_in_chain: AIProcessor | None = None
self._supports: List[str] = ['File/Folder summarization']
self._supports: List[str] = ['Summarization']

def supports(self, query_type: str) -> bool:
return query_type in self._supports
Expand Down
9 changes: 6 additions & 3 deletions src/main/askai/core/processor/processor_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class ProcessorProxy(metaclass=Singleton):

INSTANCE: "ProcessorProxy" = None

def __init__(self):
pass

@lru_cache
def template(self) -> str:
return prompt.read_prompt("proxy-prompt")
Expand All @@ -45,9 +48,9 @@ def process(self, question: str) -> Tuple[bool, QueryResponse]:
status = False
template = PromptTemplate(input_variables=[], template=self.template())
final_prompt = msg.translate(template.format())
shared.context.set("SETUP", final_prompt, "system")
shared.context.set("QUESTION", question)
context: ContextRaw = shared.context.join("CONTEXT", "SETUP", "QUESTION")
shared.context.set("SETUP", final_prompt)
shared.context.set("QUESTION", f"\n\nQuestion: {question}\n\nHelpful Answer:")
context: ContextRaw = shared.context.join("SETUP", "CONTEXT", "QUESTION")
log.info("Ask::[QUESTION] '%s' context=%s", question, context)

if (response := shared.engine.ask(context, *Temperatures.ZERO.value)) and response.is_success:
Expand Down
29 changes: 17 additions & 12 deletions src/main/askai/resources/assets/prompts/proxy-prompt.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
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. Don't try to make up an answer or change the question. You MUST return a "JSON string" containing the designated fields, no more than that. It's important to thoroughly examine the entire conversation history. The previous context may significantly impact the response. Ensure to review all of the chat history thoroughly. Queries should fall into one of the following categories:
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:

- Current AI Database research.
- File/Folder management/assessment.
- Internet research.
- File/Folder summarization.
- Text summarization.
- Data analysis.
- Command execution.
- "AI Database".
- "Internet research".
- "Summarization".
- "Data analysis".
- "Command execution".
- "Informational".

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.

2. Determine if the query suggests the user intends to end the conversation.

3. If you don't know the answer, use 'query_type' blank. Don't try to make up an answer.
3. Determine if the prompt or chat history includes any "Command output". If it does, ensure that the response is consistently based on that content.

4. The final response is a formatted JSON with no additional description or context.
4. Summarization prompts will always need a command, but you will select "Summarization" every time that happens.

5. The final response 'JSON' must contain the boolean fields: 'intelligible', and 'terminating'.
5. If you don't know the answer, just say that you don't have an answer, don't try to make up an answer.

6. The final response 'JSON' must contain the string fields: 'query_type', and 'question'.
6. The final response is a formatted JSON with no additional description or context.

7. The final response 'JSON' must contain the boolean fields: 'intelligible', and 'terminating'.

8. The final response 'JSON' must contain the string fields: 'query_type', and 'question'.

Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.
1 change: 1 addition & 0 deletions src/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""Package initialization."""

__all__ = [
'core',
'test_main'
]
__version__ = '1.0.1'
11 changes: 11 additions & 0 deletions src/test/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# _*_ coding: utf-8 _*_
#
# 'askai' v1.0.1
#
# Package: test.core
"""Package initialization."""

__all__ = [
'support'
]
__version__ = '1.0.1'
11 changes: 11 additions & 0 deletions src/test/core/support/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# _*_ coding: utf-8 _*_
#
# 'askai' v1.0.1
#
# Package: test.core.support
"""Package initialization."""

__all__ = [
'test_utilities'
]
__version__ = '1.0.1'

0 comments on commit c7f2719

Please sign in to comment.