Skip to content

Commit

Permalink
Fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
yorevs committed Sep 12, 2024
1 parent 8e51eb9 commit 44e523a
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 104 deletions.
4 changes: 2 additions & 2 deletions dependencies.hspd
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

/* HSPyLib projects */
package: hspylib, version: 1.12.47, mode: ge
package: hspylib-clitt, version: 0.9.132, mode: ge
package: hspylib, version: 1.12.49, mode: ge
package: hspylib-clitt, version: 0.9.133, mode: ge
package: hspylib-setman, version: 0.10.35, mode: ge

/* General */
Expand Down
13 changes: 6 additions & 7 deletions src/demo/components/camera_demo.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import os
from textwrap import dedent

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

from askai.core.component.camera import camera
from askai.core.component.image_store import ImageMetadata, store
from askai.core.features.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
from textwrap import dedent
from utils import init_context

import os

MENU = dedent(
f"""Camera Demo options
{'-' * 30}
Expand Down
7 changes: 3 additions & 4 deletions src/demo/components/scheduler_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
Copyright (c) 2024, HomeSetup
"""
import logging as log

from askai.core.component.scheduler import scheduler
from hspylib.core.zoned_datetime import now, SIMPLE_DATETIME_FORMAT

from utils import init_context

import logging as log


def echo(msg: str):
log.info(f"{msg} {now('[%H:%M:%S]')}")
Expand Down Expand Up @@ -60,7 +59,7 @@ def after_20_seconds():


if __name__ == "__main__":
init_context("scheduler-demo", rich_logging=False, console_enable=True, log_level=log.INFO)
init_context("scheduler-demo", rich_logging=True, console_enable=True, log_level=log.INFO)
log.info("-=" * 40)
log.info(f"AskAI Scheduler Demo - {scheduler.now.strftime(SIMPLE_DATETIME_FORMAT)}")
log.info("-=" * 40)
Expand Down
1 change: 0 additions & 1 deletion src/demo/others/screenshot_demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from askai.core.features.router.tools.vision import take_screenshot
from hspylib.core.tools.commons import sysout

from utils import init_context

if __name__ == "__main__":
Expand Down
3 changes: 1 addition & 2 deletions src/demo/others/translate_demo.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from hspylib.core.tools.commons import sysout

from askai.language.language import Language
from askai.language.translators.argos_translator import ArgosTranslator
from askai.language.translators.deepl_translator import DeepLTranslator
from askai.language.translators.marian_translator import MarianTranslator
from hspylib.core.tools.commons import sysout

if __name__ == "__main__":
text = """
Expand Down
24 changes: 2 additions & 22 deletions src/main/askai/core/askai.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,15 @@
from askai.core.support.chat_context import ChatContext
from askai.core.support.shared_instances import shared
from askai.core.support.utilities import read_stdin
from askai.exception.exceptions import (
ImpossibleQuery,
InaccurateResponse,
IntelligibleAudioError,
MaxInteractionsReached,
TerminatingQuery,
)
from askai.exception.exceptions import (ImpossibleQuery, InaccurateResponse, IntelligibleAudioError,
MaxInteractionsReached, TerminatingQuery)
from askai.tui.app_icons import AppIcons
from click import UsageError
from enum import Enum
from hspylib.core.enums.charset import Charset
from hspylib.core.tools.commons import file_is_not_empty, is_debugging
from hspylib.core.zoned_datetime import DATE_FORMAT, now, TIME_FORMAT
from hspylib.modules.application.exit_status import ExitStatus
from hspylib.modules.eventbus.event import Event
from openai import RateLimitError
from pathlib import Path
from typing import List, Optional, TypeAlias
Expand Down Expand Up @@ -212,17 +206,3 @@ def _reply_error(self, reply: AIReply) -> None:
:param reply: The error reply message to be displayed to the user.
"""
...

def _cb_mode_changed_event(self, ev: Event) -> None:
"""Callback to handle mode change events.
:param ev: The event object representing the mode change.
"""
self._mode: RouterMode = RouterMode.of_name(ev.args.mode)
if not self._mode.is_default:
sum_msg: str = (
f"{msg.enter_qna()} \n"
f"```\nContext:  {ev.args.sum_path},  {ev.args.glob} \n```\n"
f"`{msg.press_esc_enter()}` \n\n"
f"> {msg.qna_welcome()}"
)
events.reply.emit(reply=AIReply.info(sum_msg))
17 changes: 16 additions & 1 deletion src/main/askai/core/askai_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from askai.core.component.cache_service import cache, CACHE_DIR
from askai.core.component.recorder import recorder
from askai.core.component.scheduler import scheduler
from askai.core.enums.router_mode import RouterMode
from askai.core.model.ai_reply import AIReply
from askai.core.support.shared_instances import shared
from askai.core.support.text_formatter import text_formatter
Expand All @@ -32,7 +33,7 @@
from pathlib import Path
from rich.progress import Progress
from threading import Thread
from typing import List, TypeAlias, Optional
from typing import List, Optional, TypeAlias

import logging as log
import nltk
Expand Down Expand Up @@ -131,6 +132,20 @@ def _cb_reply_event(self, ev: Event) -> None:
cursor.erase_line()
self._reply(reply)

def _cb_mode_changed_event(self, ev: Event) -> None:
"""Callback to handle mode change events.
:param ev: The event object representing the mode change.
"""
self._mode: RouterMode = RouterMode.of_name(ev.args.mode)
if not self._mode.is_default:
sum_msg: str = (
f"{msg.enter_qna()} \n"
f"```\nContext:  {ev.args.sum_path},  {ev.args.glob} \n```\n"
f"`{msg.press_esc_enter()}` \n\n"
f"> {msg.qna_welcome()}"
)
events.reply.emit(reply=AIReply.info(sum_msg))

def _cb_mic_listening_event(self, ev: Event) -> None:
"""Callback to handle microphone listening events.
:param ev: The event object representing the microphone listening event.
Expand Down
3 changes: 1 addition & 2 deletions src/main/askai/core/commander/commands/settings_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
"""

from abc import ABC
from typing import Any, Optional

from askai.core.askai_configs import configs
from askai.core.askai_settings import settings
from askai.core.support.text_formatter import text_formatter
from askai.core.support.utilities import display_text
from hspylib.core.tools.commons import sysout
from setman.settings.settings_entry import SettingsEntry
from typing import Any, Optional


class SettingsCmd(ABC):
Expand Down
12 changes: 6 additions & 6 deletions src/main/askai/core/component/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
Copyright (c) 2024, HomeSetup
"""
import logging as log
import operator
import sys
from pathlib import Path
from typing import Callable, Optional, TypeAlias

from askai.core.askai_configs import configs
from askai.core.askai_events import events
from askai.core.askai_messages import msg
Expand All @@ -33,7 +27,13 @@
from hspylib.core.preconditions import check_argument, check_state
from hspylib.core.zoned_datetime import now_ms
from hspylib.modules.application.exit_status import ExitStatus
from pathlib import Path
from speech_recognition import AudioData, Microphone, Recognizer, RequestError, UnknownValueError, WaitTimeoutError
from typing import Callable, Optional, TypeAlias

import logging as log
import operator
import sys

InputDevice: TypeAlias = tuple[int, str]

Expand Down
12 changes: 6 additions & 6 deletions src/main/askai/core/component/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
Copyright (c) 2024, HomeSetup
"""
import inspect
import os
import threading
from datetime import datetime, timedelta
from hspylib.core.metaclass.singleton import Singleton
from hspylib.core.preconditions import check_argument
from hspylib.core.zoned_datetime import SIMPLE_DATETIME_FORMAT
from threading import Thread
from time import monotonic
from typing import Any, Callable, Iterable, Mapping

import inspect
import os
import pause
from hspylib.core.metaclass.singleton import Singleton
from hspylib.core.preconditions import check_argument
from hspylib.core.zoned_datetime import SIMPLE_DATETIME_FORMAT
import threading


class Scheduler(Thread, metaclass=Singleton):
Expand Down
23 changes: 11 additions & 12 deletions src/main/askai/core/features/router/task_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@
Copyright (c) 2024, HomeSetup
"""
import inspect
import logging as log
from functools import lru_cache
from textwrap import dedent
from typing import Callable, Optional

from clitt.core.tui.line_input.line_input import line_input
from hspylib.core.metaclass.classpath import AnyPath
from hspylib.core.metaclass.singleton import Singleton
from hspylib.core.tools.text_tools import ensure_endswith, ensure_startswith
from langchain_core.tools import BaseTool, StructuredTool

from askai.core.askai_messages import msg
from askai.core.features.router.tools.analysis import query_output
from askai.core.features.router.tools.browser import browse
Expand All @@ -34,6 +22,17 @@
from askai.core.features.router.tools.vision import image_captioner, parse_caption
from askai.core.features.router.tools.webcam import webcam_capturer, webcam_identifier
from askai.exception.exceptions import TerminatingQuery
from clitt.core.tui.line_input.line_input import line_input
from functools import lru_cache
from hspylib.core.metaclass.classpath import AnyPath
from hspylib.core.metaclass.singleton import Singleton
from hspylib.core.tools.text_tools import ensure_endswith, ensure_startswith
from langchain_core.tools import BaseTool, StructuredTool
from textwrap import dedent
from typing import Callable, Optional

import inspect
import logging as log


class AgentToolkit(metaclass=Singleton):
Expand Down
12 changes: 6 additions & 6 deletions src/main/askai/core/features/router/tools/vision.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import os
from textwrap import indent

import pyautogui
import torch
from PIL import Image
from askai.core.askai_events import events
from askai.core.askai_messages import msg
from askai.core.component.cache_service import PICTURE_DIR
Expand All @@ -16,8 +10,14 @@
from hspylib.core.enums.enumeration import Enumeration
from hspylib.core.metaclass.classpath import AnyPath
from hspylib.core.preconditions import check_argument
from PIL import Image
from textwrap import indent
from transformers import BlipForConditionalGeneration, BlipProcessor

import os
import pyautogui
import torch


class HFModel(Enumeration):
"""Available Hugging Face models"""
Expand Down
13 changes: 6 additions & 7 deletions src/main/askai/language/translators/argos_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@
Copyright (c) 2024, HomeSetup
"""

import logging as log
import os
import sys
from functools import lru_cache
from typing import Optional

from argostranslate import package, translate
from argostranslate.translate import ITranslation

from askai.exception.exceptions import TranslationPackageError
from askai.language.ai_translator import AITranslator
from askai.language.language import Language
from functools import lru_cache
from typing import Optional

import logging as log
import os
import sys


class ArgosTranslator(AITranslator):
Expand Down
7 changes: 3 additions & 4 deletions src/main/askai/language/translators/deepl_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
Copyright (c) 2024, HomeSetup
"""
from functools import lru_cache

import deepl

from askai.__classpath__ import API_KEYS
from askai.language.ai_translator import AITranslator
from askai.language.language import Language
from functools import lru_cache

import deepl


class DeepLTranslator(AITranslator):
Expand Down
7 changes: 3 additions & 4 deletions src/main/askai/language/translators/marian_translator.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import re
from askai.language.ai_translator import AITranslator
from askai.language.language import Language
from functools import lru_cache

from transformers import MarianMTModel, MarianTokenizer

from askai.language.ai_translator import AITranslator
from askai.language.language import Language
import re


class MarianTranslator(AITranslator):
Expand Down
Loading

0 comments on commit 44e523a

Please sign in to comment.