Исправлены ошибки в 44f9bb8c.

This commit is contained in:
Kirill Kirilenko 2026-02-14 03:12:32 +03:00
parent 44f9bb8c04
commit cb60b23ae7
3 changed files with 33 additions and 31 deletions

View file

@ -182,10 +182,8 @@ class AiAgent:
ai_response = response.choices[0].message.content ai_response = response.choices[0].message.content
context.append(response.choices[0].message) context.append(response.choices[0].message)
if len(response.choices[0].message.tool_calls) > 0 and ai_response is not None and len(ai_response) > 0:
print(f"Модель хочет вызвать функцию, но также вернула текст: '{ai_response}'")
image_response_image: Optional[bytes] = None image_response_image: Optional[bytes] = None
if response.choices[0].message.tool_calls is not None:
for tool_call in response.choices[0].message.tool_calls: for tool_call in response.choices[0].message.tool_calls:
tool_name = tool_call.function.name tool_name = tool_call.function.name
tool_args = json.loads(tool_call.function.arguments) tool_args = json.loads(tool_call.function.arguments)

View file

@ -24,7 +24,9 @@ if __name__ == '__main__':
database.create_database(config['db_connection_string']) database.create_database(config['db_connection_string'])
create_ai_agent(config['openrouter_token'], config['openrouter_model'], database.DB, 'vk') create_ai_agent(config['openrouter_token_main'], config['openrouter_model_main'],
config['openrouter_token_image'], config['openrouter_model_image'],
database.DB, 'vk')
bot = Bot(labeler=handlers.labeler) bot = Bot(labeler=handlers.labeler)

View file

@ -54,11 +54,13 @@ async def any_message_handler(message: Message):
await message.answer(MESSAGE_UNSUPPORTED_CONTENT_TYPE) await message.answer(MESSAGE_UNSUPPORTED_CONTENT_TYPE)
return return
answer: ai_agent.Message
success: bool
answer, success = await utils.run_with_progress( answer, success = await utils.run_with_progress(
partial(ai_agent.agent.get_private_chat_reply, bot_id, chat_id, ai_message), partial(ai_agent.agent.get_private_chat_reply, bot_id, chat_id, ai_message),
partial(message.ctx_api.messages.set_activity, peer_id=chat_id, type='typing'), partial(message.ctx_api.messages.set_activity, peer_id=chat_id, type='typing'),
interval=4) interval=4)
answer_id = (await message.answer(answer)).message_id answer_id = (await message.answer(answer.text)).message_id
if success: if success:
ai_agent.agent.set_last_response_id(bot_id, chat_id, answer_id) ai_agent.agent.set_last_response_id(bot_id, chat_id, answer_id)