From 895fe365de37dfb274885a5f7238feb5494b69ec Mon Sep 17 00:00:00 2001 From: ducoterra Date: Fri, 22 May 2026 14:50:04 -0400 Subject: [PATCH] fix chat history for speaking --- vibe_bot/main.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/vibe_bot/main.py b/vibe_bot/main.py index b2564c9..885426f 100644 --- a/vibe_bot/main.py +++ b/vibe_bot/main.py @@ -288,9 +288,18 @@ async def speak(ctx, *, message: str): system_prompt_edit = f"{system_prompt}\nKeep your responses under 2-3 sentences." try: + db = get_database() + context = db.get_conversation_context( + user_id=str(ctx.author.id), current_message=text_to_speak, max_context=5 + ) + + prompts = [{"role": "user", "content": text_to_speak}] + if context: + prompts = context + prompts + bot_response = llama_wrapper.chat_completion_with_history( system_prompt=system_prompt_edit, - prompts=[{"role": "user", "content": text_to_speak}], + prompts=prompts, openai_url=CHAT_ENDPOINT, openai_api_key=CHAT_ENDPOINT_KEY, model=CHAT_MODEL, @@ -301,6 +310,24 @@ async def speak(ctx, *, message: str): await ctx.send(f"❌ **{bot_name}** failed to generate a response.") return + db.add_message( + message_id=f"{ctx.message.id}", + user_id=str(ctx.author.id), + username=ctx.author.name, + content=f"User: {text_to_speak}", + channel_id=str(ctx.channel.id), + guild_id=str(ctx.guild.id) if ctx.guild else None, + ) + + db.add_message( + message_id=f"{ctx.message.id}_response", + user_id=str(bot.user.id), + username=bot.user.name, + content=f"Bot: {bot_response}", + channel_id=str(ctx.channel.id), + guild_id=str(ctx.guild.id) if ctx.guild else None, + ) + await ctx.send(f"🔊 Generating speech for **{bot_name}**...") audio_buffer = tts_engine.generate_audio(bot_response, voice=TTS_VOICE, speed=TTS_SPEED)