Skip to content

Commit

Permalink
Organize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
yorevs committed Oct 24, 2024
1 parent 8d1f55f commit 04aa649
Show file tree
Hide file tree
Showing 22 changed files with 104 additions and 131 deletions.
1 change: 0 additions & 1 deletion src/demo/devel/google_suggestions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import requests


if __name__ == '__main__':
query = 'home'

Expand Down
4 changes: 2 additions & 2 deletions src/demo/devel/gpt2_suggester.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os.path
from transformers import GPT2LMHeadModel, GPT2Tokenizer
from typing import AnyStr

import os.path
import torch
from transformers import GPT2LMHeadModel, GPT2Tokenizer


def initialize(model_name: str = 'gpt2') -> tuple:
Expand Down
13 changes: 6 additions & 7 deletions src/main/askai/__classpath__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
Copyright (c) 2024, HomeSetup
"""
import logging as log
import os
import sys
import warnings

import pydantic
from askai.core.model.api_keys import ApiKeys
from hspylib.core.metaclass.classpath import Classpath
from hspylib.core.tools.commons import is_debugging, parent_path, root_dir
from hspylib.modules.application.exit_status import ExitStatus

from askai.core.model.api_keys import ApiKeys
import logging as log
import os
import pydantic
import sys
import warnings

if not is_debugging():
warnings.simplefilter("ignore", category=FutureWarning)
Expand Down
23 changes: 11 additions & 12 deletions src/main/askai/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@
Copyright (c) 2024, HomeSetup
"""

import logging as log
import os
import re
import sys
from textwrap import dedent
from typing import Any, AnyStr, Optional

import click
from askai.__classpath__ import classpath
from askai.core.askai_configs import configs
from askai.core.enums.run_modes import RunModes
from askai.core.support.shared_instances import LOGGER_NAME
from clitt.core.tui.tui_application import TUIApplication
from hspylib.core.enums.charset import Charset
from hspylib.core.tools.commons import syserr, to_bool
Expand All @@ -29,11 +25,14 @@
from hspylib.modules.application.argparse.parser_action import ParserAction
from hspylib.modules.application.exit_status import ExitStatus
from hspylib.modules.application.version import Version
from textwrap import dedent
from typing import Any, AnyStr, Optional

from askai.__classpath__ import classpath
from askai.core.askai_configs import configs
from askai.core.enums.run_modes import RunModes
from askai.core.support.shared_instances import LOGGER_NAME
import click
import logging as log
import os
import re
import sys


class Main(TUIApplication):
Expand Down
9 changes: 2 additions & 7 deletions src/main/askai/core/askai.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,8 @@
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 hspylib.core.enums.charset import Charset
Expand Down
3 changes: 1 addition & 2 deletions src/main/askai/core/askai_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
Copyright (c) 2024, HomeSetup
"""
from hspylib.core.metaclass.classpath import AnyPath

from askai.core.askai_configs import configs
from askai.language.ai_translator import AITranslator
from askai.language.language import Language
from askai.language.translators.deepl_translator import DeepLTranslator
from functools import cached_property, lru_cache
from hspylib.core.metaclass.classpath import AnyPath
from hspylib.core.metaclass.singleton import Singleton
from typing import AnyStr

Expand Down
3 changes: 1 addition & 2 deletions src/main/askai/core/askai_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
Copyright (c) 2024, HomeSetup
"""
from hspylib.core.metaclass.singleton import Singleton

from askai.__classpath__ import classpath
from contextlib import redirect_stdout
from hspylib.core.metaclass.singleton import Singleton
from hspylib.core.tools.commons import console_out, to_bool
from io import StringIO
from pathlib import Path
Expand Down
2 changes: 1 addition & 1 deletion src/main/askai/core/component/rag_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from hspylib.core.config.path_object import PathObject
from hspylib.core.metaclass.classpath import AnyPath
from hspylib.core.preconditions import check_state
from hspylib.core.tools.commons import file_is_not_empty, dirname
from hspylib.core.tools.commons import dirname, file_is_not_empty
from hspylib.core.tools.text_tools import ensure_endswith, hash_text
from langchain_community.document_loaders import CSVLoader
from langchain_community.vectorstores import FAISS
Expand Down
8 changes: 3 additions & 5 deletions src/main/askai/core/model/acc_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
Copyright (c) 2024, HomeSetup
"""
from dataclasses import dataclass
from pathlib import Path

from hspylib.core.tools.text_tools import ensure_endswith

from askai.core.enums.acc_color import AccColor, AccuracyColors
from askai.core.support.llm_parser import parse_field
from dataclasses import dataclass
from hspylib.core.tools.text_tools import ensure_endswith
from pathlib import Path


@dataclass(frozen=True)
Expand Down
10 changes: 4 additions & 6 deletions src/main/askai/core/model/action_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
Copyright (c) 2024, HomeSetup
"""
from dataclasses import dataclass, field
from pathlib import Path
from types import SimpleNamespace

from hspylib.core.preconditions import check_state

from askai.core.model.model_result import ModelResult
from askai.core.support.llm_parser import parse_field, parse_list, parse_word
from askai.exception.exceptions import InaccurateResponse
from dataclasses import dataclass, field
from hspylib.core.preconditions import check_state
from pathlib import Path
from types import SimpleNamespace


@dataclass
Expand Down
31 changes: 15 additions & 16 deletions src/main/askai/core/processors/rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
Copyright (c) 2024, HomeSetup
"""
import logging as log
import os
import shutil
from askai.core.askai_configs import configs
from askai.core.askai_events import events
from askai.core.askai_messages import msg
from askai.core.askai_prompt import prompt
from askai.core.component.cache_service import PERSIST_DIR
from askai.core.component.rag_provider import RAG_EXT_DIR, RAGProvider
from askai.core.engine.openai.temperature import Temperature
from askai.core.model.ai_reply import AIReply
from askai.core.support.langchain_support import lc_llm
from askai.exception.exceptions import DocumentsNotFound, TerminatingQuery
from functools import lru_cache
from pathlib import Path
from typing import Optional

from hspylib.core.config.path_object import PathObject
from hspylib.core.metaclass.classpath import AnyPath
from hspylib.core.metaclass.singleton import Singleton
Expand All @@ -30,18 +34,13 @@
from langchain_core.prompts import BasePromptTemplate, ChatPromptTemplate
from langchain_core.runnables import Runnable, RunnablePassthrough
from langchain_text_splitters import RecursiveCharacterTextSplitter
from pathlib import Path
from rich.status import Status
from typing import Optional

from askai.core.askai_configs import configs
from askai.core.askai_events import events
from askai.core.askai_messages import msg
from askai.core.askai_prompt import prompt
from askai.core.component.cache_service import PERSIST_DIR
from askai.core.component.rag_provider import RAGProvider, RAG_EXT_DIR
from askai.core.engine.openai.temperature import Temperature
from askai.core.model.ai_reply import AIReply
from askai.core.support.langchain_support import lc_llm
from askai.exception.exceptions import DocumentsNotFound, TerminatingQuery
import logging as log
import os
import shutil


class Rag(metaclass=Singleton):
Expand Down
19 changes: 9 additions & 10 deletions src/main/askai/core/processors/splitter/splitter_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@
Copyright (c) 2024, HomeSetup
"""
import logging as log
from pathlib import Path
from types import SimpleNamespace
from typing import Optional

from hspylib.core.metaclass.singleton import Singleton
from langchain_core.messages import AIMessage
from langchain_core.prompts import ChatPromptTemplate, PromptTemplate, MessagesPlaceholder
from langchain_core.runnables import RunnableWithMessageHistory

from askai.core.askai_configs import configs
from askai.core.askai_prompt import prompt
from askai.core.component.geo_location import geo_location
Expand All @@ -36,6 +26,15 @@
from askai.core.router.tools.general import final_answer
from askai.core.support.langchain_support import lc_llm
from askai.core.support.shared_instances import shared
from hspylib.core.metaclass.singleton import Singleton
from langchain_core.messages import AIMessage
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder, PromptTemplate
from langchain_core.runnables import RunnableWithMessageHistory
from pathlib import Path
from types import SimpleNamespace
from typing import Optional

import logging as log


class SplitterActions(metaclass=Singleton):
Expand Down
11 changes: 5 additions & 6 deletions src/main/askai/core/processors/splitter/splitter_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
Copyright (c) 2024, HomeSetup
"""
import os
from textwrap import indent
from threading import Thread

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
from rich.console import Console
from textwrap import indent
from threading import Thread

import os


class SplitterExecutor(Thread):
Expand Down
21 changes: 10 additions & 11 deletions src/main/askai/core/processors/splitter/splitter_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,26 @@
Copyright (c) 2024, HomeSetup
"""
import logging as log
from collections import defaultdict
from typing import AnyStr, Optional

from hspylib.core.preconditions import check_state
from hspylib.core.tools.validator import Validator
from langchain_core.prompts import PromptTemplate
from transitions import Machine

from askai.core.askai_messages import msg
from askai.core.askai_prompt import prompt
from askai.core.enums.acc_color import AccColor
from askai.core.model.acc_response import AccResponse
from askai.core.model.action_plan import ActionPlan
from askai.core.model.model_result import ModelResult
from askai.core.processors.splitter.splitter_actions import actions
from askai.core.processors.splitter.splitter_result import SplitterResult, PipelineResponse
from askai.core.processors.splitter.splitter_result import PipelineResponse, SplitterResult
from askai.core.processors.splitter.splitter_states import States
from askai.core.processors.splitter.splitter_transitions import Transition, TRANSITIONS
from askai.core.router.evaluation import eval_response, EVALUATION_GUIDE
from askai.core.support.shared_instances import shared, LOGGER_NAME
from askai.core.support.shared_instances import LOGGER_NAME, shared
from collections import defaultdict
from hspylib.core.preconditions import check_state
from hspylib.core.tools.validator import Validator
from langchain_core.prompts import PromptTemplate
from transitions import Machine
from typing import AnyStr, Optional

import logging as log


class SplitterPipeline:
Expand Down
6 changes: 3 additions & 3 deletions src/main/askai/core/processors/splitter/splitter_result.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
from dataclasses import dataclass, field

from askai.core.enums.acc_color import AccColor
from askai.core.model.acc_response import AccResponse
from askai.core.model.action_plan import ActionPlan
from askai.core.model.model_result import ModelResult
from dataclasses import dataclass, field

import os


@dataclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
Copyright (c) 2024, HomeSetup
"""
from typing import TypeAlias

from askai.core.processors.splitter.splitter_states import States
from typing import TypeAlias

# Define the transitions between states
Transition: TypeAlias = dict[str, str | States]
Expand Down
15 changes: 7 additions & 8 deletions src/main/askai/core/processors/task_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@
Copyright (c) 2024, HomeSetup
"""
import logging as log
import os
from pathlib import Path
from typing import Any, Optional, Type, TypeAlias

from askai.core.processors.splitter.splitter_executor import SplitterExecutor
from askai.core.support.shared_instances import shared
from askai.exception.exceptions import InaccurateResponse, TerminatingQuery
from hspylib.core.exception.exceptions import InvalidArgumentError
from hspylib.core.metaclass.singleton import Singleton
from pathlib import Path
from pydantic_core import ValidationError
from typing import Any, Optional, Type, TypeAlias

from askai.core.processors.splitter.splitter_executor import SplitterExecutor
from askai.core.support.shared_instances import shared
from askai.exception.exceptions import InaccurateResponse, TerminatingQuery
import logging as log
import os

AgentResponse: TypeAlias = dict[str, Any]

Expand Down
13 changes: 6 additions & 7 deletions src/main/askai/core/router/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
Copyright (c) 2024, HomeSetup
"""

import logging as log
from textwrap import dedent

from langchain_core.messages import AIMessage
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder, PromptTemplate
from langchain_core.runnables.history import RunnableWithMessageHistory

from askai.core.askai_events import events
from askai.core.askai_messages import msg
from askai.core.askai_prompt import prompt
Expand All @@ -30,6 +23,12 @@
from askai.core.support.langchain_support import lc_llm
from askai.core.support.shared_instances import shared
from askai.exception.exceptions import InaccurateResponse
from langchain_core.messages import AIMessage
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder, PromptTemplate
from langchain_core.runnables.history import RunnableWithMessageHistory
from textwrap import dedent

import logging as log

# fmt: off
EVALUATION_GUIDE: str = dedent("""
Expand Down
Loading

0 comments on commit 04aa649

Please sign in to comment.