mirror of
https://github.com/Balshgit/gpt_chat_bot.git
synced 2025-12-16 21:20:39 +03:00
microservices are able to run (#5)
This commit is contained in:
22
bot_microservice/settings/.env.ci.runtests
Normal file
22
bot_microservice/settings/.env.ci.runtests
Normal file
@@ -0,0 +1,22 @@
|
||||
STAGE="runtests"
|
||||
|
||||
APP_HOST="0.0.0.0"
|
||||
APP_PORT="8000"
|
||||
|
||||
USER="web"
|
||||
TZ="Europe/Moscow"
|
||||
|
||||
TELEGRAM_API_TOKEN="123456789:AABBCCDDEEFFaabbccddeeff-1234567890"
|
||||
|
||||
# webhook settings
|
||||
DOMAIN="http://localhost"
|
||||
URL_PREFIX=
|
||||
|
||||
# set to true to start with webhook. Else bot will start on polling method
|
||||
START_WITH_WEBHOOK="true"
|
||||
|
||||
# quantity of workers for uvicorn
|
||||
WORKERS_COUNT=1
|
||||
# Enable uvicorn reloading
|
||||
RELOAD="true"
|
||||
DEBUG="true"
|
||||
22
bot_microservice/settings/.env.local.runtests
Normal file
22
bot_microservice/settings/.env.local.runtests
Normal file
@@ -0,0 +1,22 @@
|
||||
STAGE="runtests"
|
||||
|
||||
APP_HOST="0.0.0.0"
|
||||
APP_PORT="8000"
|
||||
|
||||
USER="web"
|
||||
TZ="Europe/Moscow"
|
||||
|
||||
TELEGRAM_API_TOKEN="123456789:AABBCCDDEEFFaabbccddeeff-1234567890"
|
||||
|
||||
# webhook settings
|
||||
DOMAIN="http://localhost"
|
||||
URL_PREFIX=
|
||||
|
||||
# set to true to start with webhook. Else bot will start on polling method
|
||||
START_WITH_WEBHOOK="true"
|
||||
|
||||
# quantity of workers for uvicorn
|
||||
WORKERS_COUNT=1
|
||||
# Enable uvicorn reloading
|
||||
RELOAD="true"
|
||||
DEBUG="true"
|
||||
26
bot_microservice/settings/.env.template
Normal file
26
bot_microservice/settings/.env.template
Normal file
@@ -0,0 +1,26 @@
|
||||
STAGE="dev"
|
||||
|
||||
APP_HOST="0.0.0.0"
|
||||
APP_PORT="8000"
|
||||
|
||||
# SENTRY_DSN=
|
||||
SENTRY_TRACES_SAMPLE_RATE="0.95"
|
||||
|
||||
USER="web"
|
||||
TZ="Europe/Moscow"
|
||||
|
||||
TELEGRAM_API_TOKEN="123456789:AABBCCDDEEFFaabbccddeeff-1234567890"
|
||||
|
||||
# webhook settings
|
||||
DOMAIN="https://mydomain.com"
|
||||
URL_PREFIX="/gpt"
|
||||
|
||||
# set to true to start with webhook. Else bot will start on polling method
|
||||
START_WITH_WEBHOOK="false"
|
||||
|
||||
# quantity of workers for uvicorn
|
||||
WORKERS_COUNT=1
|
||||
# Enable uvicorn reloading
|
||||
RELOAD="true"
|
||||
DEBUG="true"
|
||||
|
||||
0
bot_microservice/settings/__init__.py
Normal file
0
bot_microservice/settings/__init__.py
Normal file
69
bot_microservice/settings/config.py
Normal file
69
bot_microservice/settings/config.py
Normal file
@@ -0,0 +1,69 @@
|
||||
from functools import cached_property
|
||||
from os import environ
|
||||
from pathlib import Path
|
||||
|
||||
from constants import API_PREFIX
|
||||
from dotenv import load_dotenv
|
||||
from pydantic import HttpUrl
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
BASE_DIR = Path(__file__).parent.parent
|
||||
SHARED_DIR = BASE_DIR.resolve().joinpath("shared")
|
||||
SHARED_DIR.mkdir(exist_ok=True)
|
||||
|
||||
SHARED_DIR.joinpath("logs").mkdir(exist_ok=True)
|
||||
DIR_LOGS = SHARED_DIR.joinpath("logs")
|
||||
|
||||
env_path = f"{BASE_DIR}/settings/.env"
|
||||
|
||||
if environ.get("STAGE") == "runtests":
|
||||
if "LOCALTEST" in environ:
|
||||
env_path = f"{BASE_DIR}/settings/.env.local.runtests"
|
||||
else:
|
||||
env_path = f"{BASE_DIR}/settings/.env.ci.runtests"
|
||||
|
||||
load_dotenv(env_path, override=True)
|
||||
|
||||
|
||||
class SentrySettings(BaseSettings):
|
||||
SENTRY_DSN: HttpUrl | None = None
|
||||
DEPLOY_ENVIRONMENT: str | None = None
|
||||
SENTRY_TRACES_SAMPLE_RATE: float = 0.95
|
||||
|
||||
|
||||
class AppSettings(SentrySettings, BaseSettings):
|
||||
"""Application settings."""
|
||||
|
||||
PROJECT_NAME: str = "chat gpt bot"
|
||||
APP_HOST: str = "0.0.0.0"
|
||||
APP_PORT: int = 8000
|
||||
STAGE: str = "dev"
|
||||
DEBUG: bool = False
|
||||
|
||||
TELEGRAM_API_TOKEN: str = "123456789:AABBCCDDEEFFaabbccddeeff-1234567890"
|
||||
# webhook settings
|
||||
START_WITH_WEBHOOK: bool = False
|
||||
DOMAIN: str = "https://localhost"
|
||||
URL_PREFIX: str = ""
|
||||
|
||||
# quantity of workers for uvicorn
|
||||
WORKERS_COUNT: int = 1
|
||||
# Enable uvicorn reloading
|
||||
RELOAD: bool = False
|
||||
|
||||
@cached_property
|
||||
def api_prefix(self) -> str:
|
||||
if self.URL_PREFIX:
|
||||
return "/" + "/".join([self.URL_PREFIX.strip("/"), API_PREFIX.strip("/")])
|
||||
return API_PREFIX
|
||||
|
||||
@cached_property
|
||||
def bot_webhook_url(self) -> str:
|
||||
return "/".join([self.api_prefix, self.TELEGRAM_API_TOKEN])
|
||||
|
||||
class Config:
|
||||
case_sensitive = True
|
||||
|
||||
|
||||
def get_settings() -> AppSettings:
|
||||
return AppSettings()
|
||||
Reference in New Issue
Block a user