mirror of
https://github.com/Balshgit/gpt_chat_bot.git
synced 2026-02-03 11:40:39 +03:00
add gpt/chat api prefix (#33)
* add gpt/chat api prefix * add chatgpt backend url
This commit is contained in:
@@ -45,7 +45,6 @@ class ChatGptModelsEnum(StrEnum):
|
||||
gpt_3_5_turbo_stream_Vitalentum = "gpt-3.5-turbo-stream-Vitalentum"
|
||||
gpt_3_5_turbo_stream_GptGo = "gpt-3.5-turbo-stream-GptGo"
|
||||
gpt_3_5_turbo_stream_Aibn = "gpt-3.5-turbo-stream-Aibn"
|
||||
gpt_3_5_turbo_ChatgptDuo = "gpt-3.5-turbo-ChatgptDuo"
|
||||
gpt_3_5_turbo_stream_FreeGpt = "gpt-3.5-turbo-stream-FreeGpt"
|
||||
gpt_3_5_turbo_stream_Cromicle = "gpt-3.5-turbo-stream-Cromicle"
|
||||
gpt_4_stream_Chatgpt4Online = "gpt-4-stream-Chatgpt4Online"
|
||||
@@ -53,6 +52,7 @@ class ChatGptModelsEnum(StrEnum):
|
||||
gpt_3_5_turbo_stream_ChatgptDemo = "gpt-3.5-turbo-stream-ChatgptDemo"
|
||||
gpt_3_5_turbo_stream_H2o = "gpt-3.5-turbo-stream-H2o"
|
||||
gpt_3_5_turbo_stream_gptforlove = "gpt-3.5-turbo-stream-gptforlove"
|
||||
gpt_3_5_turbo_ChatgptDuo = "gpt-3.5-turbo-ChatgptDuo"
|
||||
|
||||
@classmethod
|
||||
def values(cls) -> set[str]:
|
||||
@@ -60,7 +60,4 @@ class ChatGptModelsEnum(StrEnum):
|
||||
|
||||
@staticmethod
|
||||
def _deprecated() -> set[str]:
|
||||
return {
|
||||
"gpt-3.5-turbo-stream-H2o",
|
||||
"gpt-3.5-turbo-stream-gptforlove",
|
||||
}
|
||||
return {"gpt-3.5-turbo-stream-H2o", "gpt-3.5-turbo-stream-gptforlove", "gpt-3.5-turbo-ChatgptDuo"}
|
||||
|
||||
@@ -45,7 +45,7 @@ async def about_bot(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
async def website(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
if not update.effective_message:
|
||||
return None
|
||||
website = urljoin(settings.DOMAIN, f"{settings.URL_PREFIX}/chat/")
|
||||
website = urljoin(settings.DOMAIN, f"{settings.chat_prefix}/")
|
||||
await update.effective_message.reply_text(f"Веб версия: {website}")
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ from loguru import logger
|
||||
from sqlalchemy import delete, desc, select, update
|
||||
from sqlalchemy.dialects.sqlite import insert
|
||||
|
||||
from constants import CHATGPT_BASE_URI, INVALID_GPT_REQUEST_MESSAGES
|
||||
from constants import INVALID_GPT_REQUEST_MESSAGES
|
||||
from core.bot.models.chat_gpt import ChatGpt
|
||||
from infra.database.db_adapter import Database
|
||||
from settings.config import AppSettings
|
||||
@@ -86,7 +86,7 @@ class ChatGPTRepository:
|
||||
|
||||
transport = AsyncHTTPTransport(retries=3)
|
||||
async with AsyncClient(base_url=self.settings.GPT_BASE_HOST, transport=transport, timeout=50) as client:
|
||||
return await client.post(CHATGPT_BASE_URI, json=data, timeout=50)
|
||||
return await client.post(self.settings.chatgpt_backend_url, json=data, timeout=50)
|
||||
|
||||
@staticmethod
|
||||
def _build_request_data(*, question: str, chatgpt_model: str) -> dict[str, Any]:
|
||||
|
||||
@@ -14,6 +14,7 @@ START_WITH_WEBHOOK="false"
|
||||
# ==== domain settings ====
|
||||
DOMAIN="http://localhost"
|
||||
URL_PREFIX=
|
||||
CHAT_PREFIX="/chat"
|
||||
|
||||
# ==== gpt settings ====
|
||||
GPT_BASE_HOST="http://localhost"
|
||||
|
||||
@@ -14,6 +14,7 @@ START_WITH_WEBHOOK="false"
|
||||
# ==== domain settings ====
|
||||
DOMAIN="http://localhost"
|
||||
URL_PREFIX=
|
||||
CHAT_PREFIX="/chat"
|
||||
|
||||
# ==== gpt settings ====
|
||||
GPT_BASE_HOST="http://localhost"
|
||||
|
||||
@@ -33,6 +33,7 @@ START_WITH_WEBHOOK="false"
|
||||
# ==== domain settings ====
|
||||
DOMAIN="https://mydomain.com"
|
||||
URL_PREFIX="/gpt"
|
||||
CHAT_PREFIX="/chat"
|
||||
|
||||
# ==== gpt settings ====
|
||||
GPT_BASE_HOST="http://chatgpt_chat_service:8858"
|
||||
|
||||
@@ -8,7 +8,7 @@ from pydantic import model_validator
|
||||
from pydantic_settings import BaseSettings
|
||||
from yarl import URL
|
||||
|
||||
from constants import API_PREFIX
|
||||
from constants import API_PREFIX, CHATGPT_BASE_URI
|
||||
|
||||
BASE_DIR = Path(__file__).parent.parent
|
||||
SHARED_DIR = BASE_DIR.resolve().joinpath("shared")
|
||||
@@ -76,6 +76,7 @@ class AppSettings(SentrySettings, LoggingSettings, BaseSettings):
|
||||
START_WITH_WEBHOOK: bool = False
|
||||
DOMAIN: str = "https://localhost"
|
||||
URL_PREFIX: str = ""
|
||||
CHAT_PREFIX: str = ""
|
||||
|
||||
DB_NAME: str = "chatgpt.db"
|
||||
DB_ECHO: bool = False
|
||||
@@ -107,6 +108,14 @@ class AppSettings(SentrySettings, LoggingSettings, BaseSettings):
|
||||
return "/" + "/".join([self.URL_PREFIX.strip("/"), API_PREFIX.strip("/")])
|
||||
return API_PREFIX
|
||||
|
||||
@cached_property
|
||||
def chat_prefix(self) -> str:
|
||||
return self.URL_PREFIX + self.CHAT_PREFIX
|
||||
|
||||
@cached_property
|
||||
def chatgpt_backend_url(self) -> str:
|
||||
return self.chat_prefix + CHATGPT_BASE_URI
|
||||
|
||||
@cached_property
|
||||
def token_part(self) -> str:
|
||||
return self.TELEGRAM_API_TOKEN[15:30]
|
||||
|
||||
@@ -4,7 +4,7 @@ from typing import Any, Iterator
|
||||
import respx
|
||||
from httpx import Response
|
||||
|
||||
from constants import CHATGPT_BASE_URI
|
||||
from settings.config import settings
|
||||
|
||||
|
||||
@contextmanager
|
||||
@@ -16,7 +16,7 @@ def mocked_ask_question_api(
|
||||
assert_all_called=True,
|
||||
base_url=host,
|
||||
) as respx_mock:
|
||||
ask_question_route = respx_mock.post(url=CHATGPT_BASE_URI, name="ask_question")
|
||||
ask_question_route = respx_mock.post(url=settings.chatgpt_backend_url, name="ask_question")
|
||||
ask_question_route.return_value = return_value
|
||||
ask_question_route.side_effect = side_effect
|
||||
yield respx_mock
|
||||
|
||||
Reference in New Issue
Block a user