Revert "fix: Streamline user ID extraction from conversation history and improve message formatting"
This reverts commit 7cfcfe21dab8c002c9e147a44e269cc016d51556.
This commit is contained in:
parent
7cfcfe21da
commit
39e5ba98e9
@ -95,8 +95,28 @@ class TetoCog(commands.Cog):
|
||||
# Collect unique user IDs from the conversation history
|
||||
user_ids_in_convo = set()
|
||||
for message_entry in messages:
|
||||
if message_entry["role"] == "user" and "user_id" in message_entry:
|
||||
user_ids_in_convo.add(message_entry["user_id"])
|
||||
if message_entry["role"] == "user":
|
||||
# Assuming user messages in history have a way to identify the author,
|
||||
# this might need adjustment based on how history is stored.
|
||||
# For now, let's assume the message object itself is available or can be retrieved.
|
||||
# This part needs refinement based on actual message history structure.
|
||||
# As a placeholder, let's assume we can get user ID from the message object.
|
||||
# In the on_message listener, we have the message object, but here we only have the history.
|
||||
# A better approach is to store user ID with the message in history.
|
||||
|
||||
# For now, let's try to extract user IDs from the text content if available
|
||||
if isinstance(message_entry["content"], list):
|
||||
for item in message_entry["content"]:
|
||||
if item["type"] == "text":
|
||||
# Simple regex to find potential user IDs in the text
|
||||
id_matches = re.findall(r"\(ID: (\d+)\)", item["text"])
|
||||
for user_id in id_matches:
|
||||
user_ids_in_convo.add(user_id)
|
||||
elif isinstance(message_entry["content"], str):
|
||||
id_matches = re.findall(r"\(ID: (\d+)\)", message_entry["content"])
|
||||
for user_id in id_matches:
|
||||
user_ids_in_convo.add(user_id)
|
||||
|
||||
|
||||
# Add list of users from conversation to the system prompt
|
||||
if user_ids_in_convo:
|
||||
@ -337,7 +357,7 @@ class TetoCog(commands.Cog):
|
||||
else:
|
||||
formatted_user_content.append(item) # Keep other types as they are
|
||||
|
||||
convo.append({"role": "user", "content": formatted_user_content, "user_id": str(message.author.id)})
|
||||
convo.append({"role": "user", "content": formatted_user_content})
|
||||
|
||||
try:
|
||||
async with channel.typing():
|
||||
@ -348,7 +368,7 @@ class TetoCog(commands.Cog):
|
||||
_teto_conversations[convo_key] = convo[-10:] # Keep last 10 interactions
|
||||
log.info("[TETO DEBUG] AI reply sent successfully.")
|
||||
except Exception as e:
|
||||
await channel.send(f"**Teto AI conversation failed! TwT**\n{e}")
|
||||
await channel.send(f"**Teto AI conversation failed! TwT**\n {e}")
|
||||
log.error(f"[TETO DEBUG] Exception during AI reply: {e}")
|
||||
|
||||
@app_commands.command(name="set_ai_model", description="Sets the AI model for Teto.")
|
||||
|
Loading…
x
Reference in New Issue
Block a user