fix chat history for speaking
This commit is contained in:
+28
-1
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user