Skip to content

Commit

Permalink
refactor: Replace absolute imports with relative imports
Browse files Browse the repository at this point in the history
  • Loading branch information
goldfishh committed Jan 6, 2024
1 parent f0a2496 commit 68e013d
Show file tree
Hide file tree
Showing 95 changed files with 424 additions and 321 deletions.
9 changes: 7 additions & 2 deletions chatgpt_tool_hub/apps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
from chatgpt_tool_hub.apps.app import App
from chatgpt_tool_hub.apps.app_factory import AppFactory
from .app import App
from .app_factory import AppFactory

__all__ = [
"App",
"AppFactory"
]
6 changes: 3 additions & 3 deletions chatgpt_tool_hub/apps/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from typing import List

from chatgpt_tool_hub.engine.tool_engine import ToolEngine
from chatgpt_tool_hub.common.log import LOG
from chatgpt_tool_hub.tools.base_tool import BaseTool
from ..engine.tool_engine import ToolEngine
from ..common.log import LOG
from ..tools.base_tool import BaseTool


class App:
Expand Down
16 changes: 8 additions & 8 deletions chatgpt_tool_hub/apps/app_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from rich.console import Console

from chatgpt_tool_hub.apps import App
from chatgpt_tool_hub.common.constants import TRUE_VALUES_SET
from chatgpt_tool_hub.common.log import refresh
from chatgpt_tool_hub.common.utils import get_from_dict_or_env
from chatgpt_tool_hub.models import build_model_params
from chatgpt_tool_hub.tools import dynamic_tool_loader
from . import App
from ..common.constants import TRUE_VALUES_SET
from ..common.log import refresh
from ..common.utils import get_from_dict_or_env
from ..models import build_model_params
from ..tools import dynamic_tool_loader


class AppFactory:
Expand Down Expand Up @@ -55,13 +55,13 @@ def create_app(self, app_type: str = 'victorinox', tools_list: list = None, cons
self.init_env(**kwargs)

if app_type == 'lite':
from chatgpt_tool_hub.apps.lite_app import LiteApp
from ..apps.lite_app import LiteApp
app = LiteApp(**build_model_params(kwargs))
app.create(tools_list, **kwargs)
return app

elif app_type == 'victorinox':
from chatgpt_tool_hub.apps.victorinox import Victorinox
from ..apps.victorinox import Victorinox

for default_tool in self.default_tools_list:
if default_tool not in tools_list:
Expand Down
12 changes: 6 additions & 6 deletions chatgpt_tool_hub/apps/lite_app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from chatgpt_tool_hub.apps import App
from chatgpt_tool_hub.apps import AppFactory
from chatgpt_tool_hub.chains import LLMChain
from chatgpt_tool_hub.common.log import LOG
from chatgpt_tool_hub.models.model_factory import ModelFactory
from chatgpt_tool_hub.prompts import PromptTemplate
from ..apps import App
from ..apps import AppFactory
from ..chains import LLMChain
from ..common.log import LOG
from ..models.model_factory import ModelFactory
from ..prompts import PromptTemplate


class LiteApp(App):
Expand Down
22 changes: 11 additions & 11 deletions chatgpt_tool_hub/apps/victorinox.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

from rich.console import Console

from chatgpt_tool_hub.apps import App
from chatgpt_tool_hub.apps import AppFactory
from chatgpt_tool_hub.common.log import LOG
from chatgpt_tool_hub.common.utils import get_from_dict_or_env
from chatgpt_tool_hub.database import ConversationTokenBufferMemory
from chatgpt_tool_hub.engine.initialize import init_tool_engine as init_engine
from chatgpt_tool_hub.models import MEMORY_MAX_TOKENS_NUM
from chatgpt_tool_hub.models.model_factory import ModelFactory
from chatgpt_tool_hub.tools.all_tool_list import main_tool_register
from chatgpt_tool_hub.tools.base_tool import BaseTool
from chatgpt_tool_hub.tools.load_tools import load_tools
from ..apps import App
from ..apps import AppFactory
from ..common.log import LOG
from ..common.utils import get_from_dict_or_env
from ..database import ConversationTokenBufferMemory
from ..engine.initialize import init_tool_engine as init_engine
from ..models import MEMORY_MAX_TOKENS_NUM
from ..models.model_factory import ModelFactory
from ..tools.all_tool_list import main_tool_register
from ..tools.base_tool import BaseTool
from ..tools.load_tools import load_tools


class Victorinox(App):
Expand Down
4 changes: 2 additions & 2 deletions chatgpt_tool_hub/bots/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from chatgpt_tool_hub.bots.chat_bot.base import ChatBot
from chatgpt_tool_hub.bots.qa_bot.base import QABot
from .chat_bot.base import ChatBot
from .qa_bot.base import QABot

__all__ = [
"ChatBot",
Expand Down
3 changes: 1 addition & 2 deletions chatgpt_tool_hub/bots/all_bot_list.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Functionality for loading bots."""

from chatgpt_tool_hub.bots import ChatBot
from chatgpt_tool_hub.bots import QABot
from . import ChatBot, QABot


BOT_TO_CLASS = {
Expand Down
21 changes: 11 additions & 10 deletions chatgpt_tool_hub/bots/chat_bot/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@

from rich.console import Console
from rich.panel import Panel
from chatgpt_tool_hub.bots.chat_bot.prompt import FORMAT_INSTRUCTIONS, PREFIX, SUFFIX
from chatgpt_tool_hub.chains import LLMChain
from chatgpt_tool_hub.common import json_utils
from chatgpt_tool_hub.common.callbacks import BaseCallbackManager
from chatgpt_tool_hub.common.log import LOG
from chatgpt_tool_hub.common.schema import BotAction, BotFinish
from chatgpt_tool_hub.engine import Bot
from chatgpt_tool_hub.models.base import BaseLLM
from chatgpt_tool_hub.prompts import PromptTemplate
from chatgpt_tool_hub.tools.base_tool import BaseTool

from .prompt import FORMAT_INSTRUCTIONS, PREFIX, SUFFIX
from ...chains import LLMChain
from ...common import json_utils
from ...common.callbacks import BaseCallbackManager
from ...common.log import LOG
from ...common.schema import BotAction, BotFinish
from ...engine import Bot
from ...models.base import BaseLLM
from ...prompts import PromptTemplate
from ...tools.base_tool import BaseTool

default_ai_prefix = "LLM-OS"
default_human_prefix = "user"
Expand Down
16 changes: 8 additions & 8 deletions chatgpt_tool_hub/bots/qa_bot/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

from rich.console import Console

from chatgpt_tool_hub.bots.qa_bot.prompt import FORMAT_INSTRUCTIONS, PREFIX, SUFFIX
from chatgpt_tool_hub.chains import LLMChain
from chatgpt_tool_hub.common.callbacks import BaseCallbackManager
from chatgpt_tool_hub.common.log import LOG
from chatgpt_tool_hub.engine import Bot
from chatgpt_tool_hub.models.base import BaseLLM
from chatgpt_tool_hub.prompts import PromptTemplate
from chatgpt_tool_hub.tools.base_tool import BaseTool
from .prompt import FORMAT_INSTRUCTIONS, PREFIX, SUFFIX
from ...chains import LLMChain
from ...common.callbacks import BaseCallbackManager
from ...common.log import LOG
from ...engine import Bot
from ...models.base import BaseLLM
from ...prompts import PromptTemplate
from ...tools.base_tool import BaseTool

FINAL_ANSWER_ACTION = "Final Answer:"

Expand Down
6 changes: 4 additions & 2 deletions chatgpt_tool_hub/chains/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Chains are easily reusable components which can be linked together."""

from chatgpt_tool_hub.chains.llm import LLMChain
from .llm import LLMChain
from .base import Chain

__all__ = [
"LLMChain",
"Chain",
"LLMChain"
]
6 changes: 5 additions & 1 deletion chatgpt_tool_hub/chains/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
"""Chain that makes API calls and summarizes the responses to answer a question."""
from chatgpt_tool_hub.chains.api.base import APIChain
from .base import APIChain

__all__ = [
"APIChain"
]
14 changes: 7 additions & 7 deletions chatgpt_tool_hub/chains/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from rich.console import Console
from rich.panel import Panel

from chatgpt_tool_hub.chains.api.prompt import API_RESPONSE_PROMPT, API_URL_PROMPT
from chatgpt_tool_hub.chains.base import Chain
from chatgpt_tool_hub.chains.llm import LLMChain
from chatgpt_tool_hub.common.log import LOG
from chatgpt_tool_hub.common.schema import BaseLanguageModel
from chatgpt_tool_hub.prompts import BasePromptTemplate
from chatgpt_tool_hub.tools.web_requests import RequestsWrapper
from .prompt import API_RESPONSE_PROMPT, API_URL_PROMPT
from .. import Chain, LLMChain

from ...common.log import LOG
from ...common.schema import BaseLanguageModel
from ...prompts import BasePromptTemplate
from ...tools.web_requests import RequestsWrapper


class APIChain(Chain, BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion chatgpt_tool_hub/chains/api/prompt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from chatgpt_tool_hub.prompts.prompt import PromptTemplate
from ...prompts.prompt import PromptTemplate

API_URL_PROMPT_TEMPLATE = """你收到一个的调用API文档: {api_docs}
你的任务是使用这个文档,生成完整的API URL以回答用户的问题
Expand Down
6 changes: 3 additions & 3 deletions chatgpt_tool_hub/chains/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from pydantic import BaseModel, Field, validator
from rich.console import Console

from chatgpt_tool_hub.common.callbacks import BaseCallbackManager
from chatgpt_tool_hub.common.callbacks import get_callback_manager
from chatgpt_tool_hub.common.schema import BaseMemory
from ..common.callbacks import BaseCallbackManager
from ..common.callbacks import get_callback_manager
from ..common.schema import BaseMemory


def _get_verbosity() -> bool:
Expand Down
10 changes: 5 additions & 5 deletions chatgpt_tool_hub/chains/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

from pydantic import BaseModel, Extra

from chatgpt_tool_hub.chains.base import Chain
from chatgpt_tool_hub.common.input import get_colored_text
from chatgpt_tool_hub.common.schema import BaseLanguageModel, LLMResult, PromptValue
from chatgpt_tool_hub.prompts.base import BasePromptTemplate
from chatgpt_tool_hub.prompts.prompt import PromptTemplate
from ..common.input import get_colored_text
from ..common.schema import BaseLanguageModel, LLMResult, PromptValue
from ..prompts.base import BasePromptTemplate
from ..prompts.prompt import PromptTemplate
from .base import Chain


class LLMChain(Chain, BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion chatgpt_tool_hub/common/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
except ImportError:
from sqlalchemy.ext.declarative import declarative_base

from chatgpt_tool_hub.common.schema import Generation
from .schema import Generation

RETURN_VAL_TYPE = List[Generation]

Expand Down
2 changes: 1 addition & 1 deletion chatgpt_tool_hub/common/calculate_token.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from chatgpt_tool_hub.common.log import LOG
from .log import LOG


# refer to https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
Expand Down
4 changes: 2 additions & 2 deletions chatgpt_tool_hub/common/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from abc import ABC, abstractmethod
from typing import Any, Dict, List, Union

from chatgpt_tool_hub.common.schema import BotAction, BotFinish, LLMResult
from chatgpt_tool_hub.common.singleton import Singleton
from .schema import BotAction, BotFinish, LLMResult
from .singleton import Singleton


class BaseCallbackHandler(ABC):
Expand Down
2 changes: 1 addition & 1 deletion chatgpt_tool_hub/common/json_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
from typing import Any, Dict, Optional, Union

from chatgpt_tool_hub.common.log import LOG
from .log import LOG


def fix_and_parse_json(
Expand Down
2 changes: 1 addition & 1 deletion chatgpt_tool_hub/common/log.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys
import logging
from chatgpt_tool_hub.common.constants import LOGGING_LEVEL, LOGGING_FMT, LOGGING_DATEFMT
from .constants import LOGGING_LEVEL, LOGGING_FMT, LOGGING_DATEFMT


def _get_logger(level: int = LOGGING_LEVEL):
Expand Down
4 changes: 2 additions & 2 deletions chatgpt_tool_hub/common/text_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
Union,
)

from chatgpt_tool_hub.common.document import Document
from chatgpt_tool_hub.common.log import LOG
from .document import Document
from .log import LOG

class TextSplitter(ABC):
"""Interface for splitting text into chunks."""
Expand Down
2 changes: 1 addition & 1 deletion chatgpt_tool_hub/database/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from chatgpt_tool_hub.database.token_buffer import ConversationTokenBufferMemory
from .token_buffer import ConversationTokenBufferMemory

__all__ = [
"ConversationTokenBufferMemory",
Expand Down
4 changes: 2 additions & 2 deletions chatgpt_tool_hub/database/chat_memory.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from abc import ABC
from typing import Any, Dict, List, Optional

from chatgpt_tool_hub.database.utils import get_prompt_input_key
from .utils import get_prompt_input_key
from pydantic import BaseModel, Field

from chatgpt_tool_hub.common.schema import AIMessage, BaseMemory, BaseMessage, HumanMessage
from ..common.schema import AIMessage, BaseMemory, BaseMessage, HumanMessage


class ChatMessageHistory(BaseModel):
Expand Down
6 changes: 3 additions & 3 deletions chatgpt_tool_hub/database/token_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from pydantic import BaseModel

from chatgpt_tool_hub.common.log import LOG
from chatgpt_tool_hub.common.schema import BaseLanguageModel, BaseMessage, get_buffer_string
from chatgpt_tool_hub.database.chat_memory import BaseChatMemory
from ..common.log import LOG
from ..common.schema import BaseLanguageModel, BaseMessage, get_buffer_string
from .chat_memory import BaseChatMemory


class ConversationTokenBufferMemory(BaseChatMemory, BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion chatgpt_tool_hub/database/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Dict, List

from chatgpt_tool_hub.common.schema import get_buffer_string # noqa: 401
from ..common.schema import get_buffer_string # noqa: 401


def get_prompt_input_key(inputs: Dict[str, Any], memory_variables: List[str]) -> str:
Expand Down
10 changes: 8 additions & 2 deletions chatgpt_tool_hub/engine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
from chatgpt_tool_hub.engine.bot import Bot
from chatgpt_tool_hub.engine.tool_engine import ToolEngine
from .bot import Bot
from .tool_engine import ToolEngine


__all__ = [
"Bot",
"ToolEngine"
]
22 changes: 11 additions & 11 deletions chatgpt_tool_hub/engine/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
from pydantic import BaseModel, root_validator, validator
from rich.console import Console

from chatgpt_tool_hub.chains import LLMChain
from chatgpt_tool_hub.common.calculate_token import count_string_tokens
from chatgpt_tool_hub.common.callbacks import BaseCallbackManager
from chatgpt_tool_hub.common.log import LOG
from chatgpt_tool_hub.common.schema import BotAction, BotFinish, BaseMessage
from chatgpt_tool_hub.models import ALL_MAX_TOKENS_NUM, BOT_SCRATCHPAD_MAX_TOKENS_NUM
from chatgpt_tool_hub.models.base import BaseLLM
from chatgpt_tool_hub.prompts import BasePromptTemplate
from chatgpt_tool_hub.prompts import PromptTemplate
from chatgpt_tool_hub.tools import SummaryTool
from chatgpt_tool_hub.tools.base_tool import BaseTool
from ..chains import LLMChain
from ..common.calculate_token import count_string_tokens
from ..common.callbacks import BaseCallbackManager
from ..common.log import LOG
from ..common.schema import BotAction, BotFinish, BaseMessage
from ..models import ALL_MAX_TOKENS_NUM, BOT_SCRATCHPAD_MAX_TOKENS_NUM
from ..models.base import BaseLLM
from ..prompts import BasePromptTemplate
from ..prompts import PromptTemplate
from ..tools import SummaryTool
from ..tools.base_tool import BaseTool


class Bot(BaseModel):
Expand Down
Loading

0 comments on commit 68e013d

Please sign in to comment.