update gpt provider to latest changes (#17)

This commit is contained in:
Dmitry Afanasyev
2023-09-28 18:35:20 +03:00
committed by GitHub
parent 61f3a351e2
commit c8b5639944
20 changed files with 330 additions and 193 deletions

View File

@@ -1,8 +1,9 @@
from fastapi import APIRouter, Request
from settings.config import settings
from starlette import status
from starlette.responses import Response
from settings.config import settings
router = APIRouter()

View File

@@ -8,10 +8,11 @@ from typing import Any
from fastapi import Request, Response
from loguru import logger
from settings.config import AppSettings
from telegram import Update
from telegram.ext import Application
from settings.config import AppSettings
class BotApplication:
def __init__(

View File

@@ -5,14 +5,15 @@ from urllib.parse import urljoin
from uuid import uuid4
import httpx
from httpx import AsyncClient, AsyncHTTPTransport
from loguru import logger
from telegram import InlineKeyboardMarkup, Update
from telegram.ext import ContextTypes
from constants import CHAT_GPT_BASE_URL, BotEntryPoints
from core.keyboards import main_keyboard
from core.utils import SpeechToTextService
from httpx import AsyncClient, AsyncHTTPTransport
from loguru import logger
from settings.config import settings
from telegram import InlineKeyboardMarkup, Update
from telegram.ext import ContextTypes
async def main_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
@@ -37,7 +38,7 @@ async def about_bot(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
return None
await update.effective_message.reply_text(
"Бот использует бесплатную модель Chat-GPT3.5 для ответов на вопросы. "
"Принимает запросы на разных языках. \n\nБот так же умеет переводить голосовые сообщения в текст."
"Принимает запросы на разных языках. \n\nБот так же умеет переводить голосовые сообщения в текст. "
"Просто пришлите голосовуху и получите поток сознания без запятых в виде текста",
parse_mode='Markdown',
)

View File

@@ -1,6 +1,14 @@
from dataclasses import dataclass, field
from typing import Any
from telegram.ext import (
CallbackQueryHandler,
CommandHandler,
ConversationHandler,
MessageHandler,
filters,
)
from constants import BotEntryPoints, BotStagesEnum
from core.commands import (
about_bot,
@@ -11,13 +19,6 @@ from core.commands import (
voice_recognize,
website,
)
from telegram.ext import (
CallbackQueryHandler,
CommandHandler,
ConversationHandler,
MessageHandler,
filters,
)
@dataclass

View File

@@ -1,6 +1,7 @@
from constants import BotStagesEnum
from telegram import InlineKeyboardButton
from constants import BotStagesEnum
main_keyboard = [
[
InlineKeyboardButton("Обо мне", callback_data=str(BotStagesEnum.about_me)),

View File

@@ -3,9 +3,10 @@ import sys
from types import FrameType
from typing import TYPE_CHECKING, Any, cast
from constants import LogLevelEnum
from loguru import logger
from sentry_sdk.integrations.logging import EventHandler
from constants import LogLevelEnum
from settings.config import settings
if TYPE_CHECKING:

View File

@@ -5,7 +5,6 @@ from datetime import datetime, timedelta
from functools import lru_cache, wraps
from typing import Any
from constants import AUDIO_SEGMENT_DURATION
from loguru import logger
from pydub import AudioSegment
from speech_recognition import (
@@ -14,6 +13,8 @@ from speech_recognition import (
UnknownValueError as SpeechRecognizerError,
)
from constants import AUDIO_SEGMENT_DURATION
def timed_cache(**timedelta_kwargs: Any) -> Any:
def _wrapper(func: Any) -> Any:

View File

@@ -2,12 +2,13 @@ import asyncio
from functools import cached_property
import sentry_sdk
from fastapi import FastAPI
from fastapi.responses import UJSONResponse
from constants import LogLevelEnum
from core.bot import BotApplication, BotQueue
from core.handlers import bot_event_handlers
from core.logging import configure_logging
from fastapi import FastAPI
from fastapi.responses import UJSONResponse
from routers import api_router
from settings.config import AppSettings, get_settings

View File

@@ -1,7 +1,8 @@
from api.bot.controllers import router as bot_router
from api.system.controllers import router as system_router
from fastapi import APIRouter
from fastapi.responses import ORJSONResponse
from api.bot.controllers import router as bot_router
from api.system.controllers import router as system_router
from settings.config import settings
api_router = APIRouter(

View File

@@ -3,11 +3,12 @@ from os import environ
from pathlib import Path
from typing import Any
from constants import API_PREFIX
from dotenv import load_dotenv
from pydantic import HttpUrl, ValidationInfo, field_validator
from pydantic_settings import BaseSettings
from constants import API_PREFIX
BASE_DIR = Path(__file__).parent.parent
SHARED_DIR = BASE_DIR.resolve().joinpath("shared")
SHARED_DIR.mkdir(exist_ok=True)

View File

@@ -9,15 +9,16 @@ from typing import Any, AsyncGenerator
import pytest
import pytest_asyncio
from core.bot import BotApplication
from core.handlers import bot_event_handlers
from fastapi import FastAPI
from httpx import AsyncClient
from main import Application as AppApplication
from pytest_asyncio.plugin import SubRequest
from settings.config import AppSettings, get_settings
from telegram import Bot, User
from telegram.ext import Application, ApplicationBuilder, Defaults, ExtBot
from core.bot import BotApplication
from core.handlers import bot_event_handlers
from main import Application as AppApplication
from settings.config import AppSettings, get_settings
from tests.integration.bot.networking import NonchalantHttpxRequest
from tests.integration.factories.bot import BotInfoFactory

View File

@@ -5,9 +5,10 @@ from typing import Any
import pytest
from assertpy import assert_that
from core.bot import BotApplication, BotQueue
from faker import Faker
from httpx import AsyncClient
from core.bot import BotApplication, BotQueue
from main import Application
from tests.integration.bot.networking import MockedRequest
from tests.integration.factories.bot import (

View File

@@ -2,6 +2,7 @@ import string
import factory
from faker import Faker
from tests.integration.factories.models import Chat, User
faker = Faker("ru_RU")