diff --git a/src/modules/external/yandexgpt/yandexgpt.py b/src/modules/external/yandexgpt/yandexgpt.py index b29188f..f1b6f78 100644 --- a/src/modules/external/yandexgpt/yandexgpt.py +++ b/src/modules/external/yandexgpt/yandexgpt.py @@ -8,9 +8,9 @@ from ...standard.config.config import * class YandexGPT: - self.token = None - self.catalog_id = None - self.language = { + token = None + catalog_id = None + languages = { "ru": "русский язык", "en": "английский язык", "de": "немецкий язык", @@ -117,7 +117,7 @@ class YandexGPT: stream=False, temperature=0.6, max_tokens=8000 ) - async def async_yandexgpt_text_history(self, messages, stream=False, temperature=0.6, max_tokens=8000): + async def async_yandexgpt_text_history(self, input_messages, stream=False, temperature=0.6, max_tokens=8000): url = "https://llm.api.cloud.yandex.net/foundationModels/v1/completion" gpt = f"gpt://{self.catalog_id}/summarization/latest" headers = { @@ -152,18 +152,18 @@ class YandexGPT: # TODO: Сделать функцию Vision return 0 - async def collect_messages(self, message_id, chat_id): + async def collect_messages(self, message_id, chat_id, start_message_id): messages = [] # Собираем цепочку сообщений в формате: [{"role": "user", "text": "<Имя_пользователя>: Привет!"}, # {"role": "assistant", "text": "Привет!"}] while True: - message = get_message_text(chat_id, message_id) - if get_message_ai_model(chat_id, start_message_id) != None: + message = db_api.get_message_text(chat_id, message_id) + if db_api.get_message_ai_model(chat_id, start_message_id) != None: messages.append({"role": "assistant", "text": message}) else: - sender_name = get_user_name(get_message_sender_id(chat_id, start_message_id)) + sender_name = db_api.get_user_name(db_api.get_message_sender_id(chat_id, start_message_id)) messages.append({"role": "user", "text": sender_name + ": " + message}) - message_id = get_message_answer_to_message_id(chat_id, message_id) + message_id = db_api.get_message_answer_to_message_id(chat_id, message_id) if message_id is None: break return messages.reverse() @@ -173,11 +173,11 @@ class YandexGPT: # Собираем цепочку сообщений в формате: [{"role": "user", "text": "<Имя_пользователя>: Привет!"}, # {"role": "assistant", "text": "Привет!"}] while True: - message = get_message_text(chat_id, start_message_id) - if get_message_ai_model(chat_id, start_message_id) != None: + message = db_api.get_message_text(chat_id, start_message_id) + if db_api.get_message_ai_model(chat_id, start_message_id) != None: messages.append({"role": "assistant", "text": message}) else: - sender_name = get_user_name(get_message_sender_id(chat_id, start_message_id)) + sender_name = db_api.get_user_name(db_api.get_message_sender_id(chat_id, start_message_id)) messages.append({"role": "user", "text": sender_name + ": " + message}) start_message_id -= 1 if start_message_id <= end_message_id: @@ -185,7 +185,7 @@ class YandexGPT: return messages.reverse() async def yandexgpt_request(self, message_id = None, type = "yandexgpt-lite", chat_id = None, - message_id_end = None): + message_id_end = None, input_language = None, output_language = None, text = None): if type == "yandexgpt-lite": messages = await self.collect_messages(message_id, chat_id) return await self.async_yandexgpt_lite( @@ -202,14 +202,14 @@ class YandexGPT: ) elif type == "yandexgpt-translate": return await self.async_yandexgpt_translate( - input_language=get_message_language(chat_id, message_id), - output_language=get_chat_language(chat_id), - text=get_message_text(chat_id, message_id) + input_language, + output_language, + text=db_api.get_message_text(chat_id, message_id) ) elif type == "yandexgpt-spelling-check": return await self.async_yandexgpt_spelling_check( - input_language=get_message_language(chat_id, message_id), - text=get_message_text(chat_id, message_id) + input_language, + text=db_api.get_message_text(chat_id, message_id) ) elif type == "yandexgpt-text-history": messages = await self.collect_messages_for_history(message_id, message_id_end, chat_id)