Skip to content

Commit

Permalink
Refactorings + Initial splitter pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
yorevs committed Oct 21, 2024
1 parent 5ebe4c7 commit 4009b97
Show file tree
Hide file tree
Showing 41 changed files with 389 additions and 60 deletions.
Binary file added assets/images/AskAI-New-Flow.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions dependencies.hspd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package: tqdm, version: 4.66.5, mode: ge
package: pyperclip, version: 1.9.0, mode: ge
package: python-magic, version: 0.4.27, mode: ge
package: pytz, version: 2024.1, mode: ge
package: transitions, version: 0.9.2, mode: ge

/* LangChain */
package: langchain, version: 0.3.0, mode: ge
Expand Down
2 changes: 1 addition & 1 deletion src/demo/components/camera_demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from askai.core.component.camera import camera
from askai.core.component.image_store import ImageMetadata, store
from askai.core.features.tools.terminal import open_command
from askai.core.router.tools.terminal import open_command
from clitt.core.term.cursor import cursor
from clitt.core.tui.line_input.line_input import line_input
from hspylib.core.tools.text_tools import strip_escapes
Expand Down
2 changes: 1 addition & 1 deletion src/demo/components/vision_demo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from askai.core.features.tools.vision import offline_captioner
from askai.core.router.tools.vision import offline_captioner

import os

Expand Down
2 changes: 1 addition & 1 deletion src/demo/components/webcam_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Copyright (c) 2024, HomeSetup
"""
from askai.core.features.tools.webcam import webcam_capturer
from askai.core.router.tools.webcam import webcam_capturer
from hspylib.core.tools.commons import sysout
from utils import init_context

Expand Down
2 changes: 1 addition & 1 deletion src/demo/features/rag/x_refs_demo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from askai.core.features.router.evaluation import resolve_x_refs
from askai.core.router.evaluation import resolve_x_refs
from askai.core.support.shared_instances import shared
from askai.core.support.utilities import display_text
from utils import get_resource, init_context
Expand Down
2 changes: 1 addition & 1 deletion src/demo/features/router_demo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from askai.core.features.processors.task_splitter import splitter
from askai.core.router.processors.task_splitter import splitter
from askai.core.support.shared_instances import shared
from askai.core.support.utilities import display_text
from utils import init_context
Expand Down
2 changes: 1 addition & 1 deletion src/demo/features/tools/query_output_demo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from askai.core.features.tools.analysis import query_output
from askai.core.router.tools.analysis import query_output
from askai.core.support.shared_instances import shared
from askai.core.support.utilities import display_text
from utils import get_resource, init_context
Expand Down
2 changes: 1 addition & 1 deletion src/demo/others/screenshot_demo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from askai.core.features.tools.vision import take_screenshot
from askai.core.router.tools.vision import take_screenshot
from hspylib.core.tools.commons import sysout
from utils import init_context

Expand Down
2 changes: 1 addition & 1 deletion src/main/askai/core/askai.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from askai.core.component.cache_service import cache, CACHE_DIR
from askai.core.engine.ai_engine import AIEngine
from askai.core.enums.router_mode import RouterMode
from askai.core.features.processors.ai_processor import AIProcessor
from askai.core.model.ai_reply import AIReply
from askai.core.router.processors.ai_processor import AIProcessor
from askai.core.support.chat_context import ChatContext
from askai.core.support.shared_instances import shared
from askai.core.support.utilities import read_stdin
Expand Down
2 changes: 1 addition & 1 deletion src/main/askai/core/commander/commands/camera_cmd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC
from askai.core.askai_configs import configs
from askai.core.component.camera import camera
from askai.core.features.tools.webcam import webcam_capturer, webcam_identifier
from askai.core.router.tools.webcam import webcam_capturer, webcam_identifier
from askai.core.support.text_formatter import text_formatter
from askai.core.support.utilities import display_text
from hspylib.core.metaclass.classpath import AnyPath
Expand Down
2 changes: 1 addition & 1 deletion src/main/askai/core/component/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
from askai.core.component.audio_player import player
from askai.core.component.cache_service import FACE_DIR, IMG_IMPORTS_DIR, PHOTO_DIR
from askai.core.component.image_store import ImageData, ImageFile, ImageMetadata, store
from askai.core.features.tools.vision import image_captioner, parse_caption
from askai.core.model.ai_reply import AIReply
from askai.core.model.image_result import ImageResult
from askai.core.router.tools.vision import image_captioner, parse_caption
from askai.core.support.utilities import build_img_path
from askai.exception.exceptions import CameraAccessFailure, WebCamInitializationFailure
from hspylib.core.metaclass.classpath import AnyPath
Expand Down
2 changes: 1 addition & 1 deletion src/main/askai/core/component/image_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Copyright (c) 2024, HomeSetup
"""
from askai.core.features.tools.vision import offline_captioner
from askai.core.router.tools.vision import offline_captioner
from chromadb.api.types import IncludeEnum
from chromadb.utils.data_loaders import ImageLoader
from chromadb.utils.embedding_functions.open_clip_embedding_function import OpenCLIPEmbeddingFunction
Expand Down
12 changes: 6 additions & 6 deletions src/main/askai/core/enums/router_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
"""
from askai.core.askai_configs import configs
from askai.core.askai_messages import msg
from askai.core.features.processors.ai_processor import AIProcessor
from askai.core.features.processors.chat import chat
from askai.core.features.processors.qna import qna
from askai.core.features.processors.qstring import qstring
from askai.core.features.processors.rag import rag
from askai.core.features.processors.task_splitter import splitter
from askai.core.router.processors.ai_processor import AIProcessor
from askai.core.router.processors.chat import chat
from askai.core.router.processors.qna import qna
from askai.core.router.processors.qstring import qstring
from askai.core.router.processors.rag import rag
from askai.core.router.processors.task_splitter import splitter
from functools import lru_cache
from hspylib.core.enums.enumeration import Enumeration
from hspylib.core.tools.dict_tools import get_or_default_by_key
Expand Down
13 changes: 0 additions & 13 deletions src/main/askai/core/features/__init__.py

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

"""
@project: taius-coder
@package: taius-coder.main.taius_coder.core
@file: chat_processor.py
@package: askai.core.processors.chat
@file: chat.py
@created: Mon, 23 Sep 2024
@author: <B>H</B>ugo <B>S</B>aporetti <B>J</B>unior"
@site: https://github.com/yorevs/taius-coder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
@project: HsPyLib-AskAI
@package: askai.core.processors.qna
@file: qna.py
@created: Fri, 5 May 2024
@author: <B>H</B>ugo <B>S</B>aporetti <B>J</B>unior
@site: https://github.com/yorevs/askai
@license: MIT - Please refer to <https://opensource.org/licenses/MIT>
Copyright (c) 2024, HomeSetup
"""
from askai.core.askai_events import events
from askai.core.askai_messages import msg
from askai.core.component.summarizer import summarizer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
@project: HsPyLib-AskAI
@package: askai.core.processors.qstring
@file: qstring.py
@created: Fri, 5 May 2024
@author: <B>H</B>ugo <B>S</B>aporetti <B>J</B>unior
@site: https://github.com/yorevs/askai
@license: MIT - Please refer to <https://opensource.org/licenses/MIT>
Copyright (c) 2024, HomeSetup
"""
from askai.core.askai_prompt import prompt
from askai.core.component.cache_service import cache
from askai.core.engine.openai.temperature import Temperature
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
@project: HsPyLib-AskAI
@package: askai.core.processors.rag
@file: rag.py
@created: Fri, 5 May 2024
@author: <B>H</B>ugo <B>S</B>aporetti <B>J</B>unior
@site: https://github.com/yorevs/askai
@license: MIT - Please refer to <https://opensource.org/licenses/MIT>
Copyright (c) 2024, HomeSetup
"""
import logging as log
import os
import shutil
Expand Down
Empty file.
105 changes: 105 additions & 0 deletions src/main/askai/core/processors/splitter/splitter_executor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
@project: HsPyLib-AskAI
@package: askai.core.processors.splitter.splitter_executor
@file: splitter_executor.py
@created: Mon, 21 Oct 2024
@author: <B>H</B>ugo <B>S</B>aporetti <B>J</B>unior
@site: https://github.com/yorevs/askai
@license: MIT - Please refer to <https://opensource.org/licenses/MIT>
Copyright (c) 2024, HomeSetup
"""
from threading import Thread

from hspylib.core.decorator.decorators import profiled
from rich.console import Console

from askai.core.askai_configs import configs
from askai.core.enums.acc_color import AccColor
from askai.core.processors.splitter.splitter_pipeline import SplitterPipeline
from askai.core.processors.splitter.splitter_states import States


class SplitterExecutor(Thread):
"""Responsible for executing a Taius Coder pipeline."""

def __init__(self, pipeline: SplitterPipeline):
super().__init__()
self._pipeline = pipeline
self._console = Console()

@property
def pipeline(self) -> SplitterPipeline:
return self._pipeline

@profiled
def run(self):
with self._console.status("Processing query...", spinner="dots") as spinner:
max_retries: int = configs.max_router_retries
while not self.pipeline.state == States.COMPLETE:
self.pipeline.track_previous()
spinner.update(f"[green]{self.pipeline.state.value}[/green]")
if 0 < max_retries < self.pipeline.failures[self.pipeline.state.value]:
spinner.update(f"\nMax state retries reached: {max_retries}")
break
match self.pipeline.state:
case States.STARTUP:
if self.pipeline.st_startup():
self.pipeline.ev_pipeline_started()
case States.QUERY_QUEUED:
if self.pipeline.st_query_queued():
self.pipeline.ev_query_queued()
case States.MODEL_SELECT:
if self.pipeline.st_model_select():
self.pipeline.ev_model_selected()
case States.TASK_SPLIT:
status, direct = self.pipeline.st_task_split()
if status:
if direct:
self.pipeline.ev_direct_answer()
else:
self.pipeline.ev_plan_created()
case States.EXECUTE_TASK:
color, has_next = self.pipeline.st_execute_next()
if color.passed:
if has_next:
self.pipeline.st_execute_next()
else:
self.pipeline.ev_task_executed()
case States.ACCURACY_CHECK:
color: AccColor = self.pipeline.st_accuracy_check()
if color.passed:
self.pipeline.ev_accuracy_passed()
else:
self.pipeline.ev_accuracy_failed()
case States.REFINE_ANSWER:
if self.pipeline.st_refine_answer():
self.pipeline.ev_answer_refined()
case _:
spinner.update(f"Error: Machine stopped before it was done ({self.pipeline.state}) %NC%")
break
execution_status: bool = self.pipeline.previous != self.pipeline.state
execution_status_str: str = (
f"{'[green]√[/green]' if execution_status else '[red]X[/red]'}"
f" {str(self.pipeline.previous)}"
)
self.pipeline.failures[self.pipeline.state.value] += 1 if not execution_status else 0
self._console.print(f"[green]{execution_status_str}[/green]")

final_state: States = self.pipeline.state
final_state_str: str = '[green]√ Succeeded[/green] ' if final_state == States.COMPLETE else '[red]X Failed [/red]'
self._console.print(f"[cyan]Pipeline Execution {final_state_str} [cyan][{final_state}][/cyan]")

if final_state != States.COMPLETE:
self._console.print(f"Failed to generate a response")


if __name__ == '__main__':
query: str = "What is the size of the moon"
p: SplitterPipeline = SplitterPipeline(query)
executor: SplitterExecutor = SplitterExecutor(p)
executor.start()
executor.join()
Loading

0 comments on commit 4009b97

Please sign in to comment.