Refactor: Clarify User ID usage and enhance author attribution
This commit improves user identification in two key areas: 1. **AI Response Context:** In `gurt/api.py`, messages processed by the AI now include a more informative author string, combining the user's display name and username (e.g., "DisplayName (Username: actual_username)"). This provides richer context about message authors. 2. **Tool Definitions:** Descriptions for tools in `gurt/config.py` and `gurt/prompt.py` (e.g., `search_user_messages`, `get_user_facts`) and their parameters have been updated to explicitly state that user identification relies on "User ID". This enhances clarity for the AI model and developers.
This commit is contained in:
parent
d2e20ded2a
commit
e8eaff4b9a
@ -831,9 +831,12 @@ async def get_ai_response(cog: 'GurtCog', message: discord.Message, model_name:
|
||||
|
||||
full_text = "\n".join(text_parts).strip()
|
||||
if full_text: # Only add if there's some text content
|
||||
# Use the new author_string here
|
||||
author_string = msg.get("author_string", msg.get("author", {}).get("display_name", " "))
|
||||
contents.append(types.Content(role=role, parts=[types.Part(text=f"{author_string}: {full_text}")]))
|
||||
author_details = msg.get("author", {})
|
||||
display_name = author_details.get("display_name", "Unknown User")
|
||||
username = author_details.get("name", "unknown_username") # 'name' usually holds the username
|
||||
# Construct a more informative author string
|
||||
author_identifier_string = f"{display_name} (Username: {username})"
|
||||
contents.append(types.Content(role=role, parts=[types.Part(text=f"{author_identifier_string}: {full_text}")]))
|
||||
|
||||
|
||||
# --- Prepare the current message content (potentially multimodal) ---
|
||||
|
@ -449,13 +449,13 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration( # Use the imported FunctionDeclaration
|
||||
name="search_user_messages",
|
||||
description="Search for messages from a specific user",
|
||||
description="Search for messages from a specific user by their User ID.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {
|
||||
"type": "string",
|
||||
"description": "The ID of the user to get messages from"
|
||||
"description": "The User ID of the user whose messages to search for."
|
||||
},
|
||||
"channel_id": {
|
||||
"type": "string",
|
||||
@ -553,17 +553,17 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration( # Use the imported FunctionDeclaration
|
||||
name="get_user_interaction_history",
|
||||
description="Get the history of interactions between users",
|
||||
description="Get the history of interactions between users by their User IDs.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id_1": {
|
||||
"type": "string",
|
||||
"description": "The ID of the first user"
|
||||
"description": "The User ID of the first user."
|
||||
},
|
||||
"user_id_2": {
|
||||
"type": "string",
|
||||
"description": "The ID of the second user. If not provided, gets interactions between user_id_1 and the bot."
|
||||
"description": "The User ID of the second user. If not provided, gets interactions between user_id_1 and the bot."
|
||||
},
|
||||
"limit": {
|
||||
"type": "integer", # Corrected type
|
||||
@ -633,13 +633,13 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration( # Use the imported FunctionDeclaration
|
||||
name="remember_user_fact",
|
||||
description="Store a specific fact or piece of information about a user for later recall. Use this when you learn something potentially relevant about a user (e.g., their preferences, current activity, mentioned interests).",
|
||||
description="Store a specific fact or piece of information about a user (identified by User ID) for later recall. Use this when you learn something potentially relevant about a user (e.g., their preferences, current activity, mentioned interests).",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {
|
||||
"type": "string",
|
||||
"description": "The Discord ID of the user the fact is about."
|
||||
"description": "The User ID of the user the fact is about."
|
||||
},
|
||||
"fact": {
|
||||
"type": "string",
|
||||
@ -653,13 +653,13 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration( # Use the imported FunctionDeclaration
|
||||
name="get_user_facts",
|
||||
description="Retrieve previously stored facts or information about a specific user. Use this before responding to a user to potentially recall relevant details about them.",
|
||||
description="Retrieve previously stored facts or information about a specific user by their User ID. Use this before responding to a user to potentially recall relevant details about them.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {
|
||||
"type": "string",
|
||||
"description": "The Discord ID of the user whose facts you want to retrieve."
|
||||
"description": "The User ID of the user whose facts you want to retrieve."
|
||||
}
|
||||
},
|
||||
"required": ["user_id"]
|
||||
@ -705,13 +705,13 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration( # Use the imported FunctionDeclaration
|
||||
name="timeout_user",
|
||||
description="Timeout a user in the current server for a specified duration. Use this playfully or when someone says something you (Gurt) dislike or find funny.",
|
||||
description="Timeout a user (identified by User ID) in the current server for a specified duration. Use this playfully or when someone says something you (Gurt) dislike or find funny.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {
|
||||
"type": "string",
|
||||
"description": "The Discord ID of the user to timeout."
|
||||
"description": "The User ID of the user to timeout."
|
||||
},
|
||||
"duration_minutes": {
|
||||
"type": "integer", # Corrected type
|
||||
@ -800,13 +800,13 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration( # Use the imported FunctionDeclaration
|
||||
name="remove_timeout",
|
||||
description="Remove an active timeout from a user in the current server.",
|
||||
description="Remove an active timeout from a user (identified by User ID) in the current server.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {
|
||||
"type": "string",
|
||||
"description": "The Discord ID of the user whose timeout should be removed."
|
||||
"description": "The User ID of the user whose timeout should be removed."
|
||||
},
|
||||
"reason": {
|
||||
"type": "string",
|
||||
@ -891,13 +891,13 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration( # Use the imported FunctionDeclaration
|
||||
name="get_user_id",
|
||||
description="Finds the Discord User ID for a given username or display name. Searches the current server or recent messages.",
|
||||
description="Finds the Discord User ID for a given username or display name (typically for users *other* than the one currently interacting, as you are already provided with the current user's ID and username). Searches the current server or recent messages.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_name": {
|
||||
"type": "string",
|
||||
"description": "The username or display name of the user to find."
|
||||
"description": "The username (e.g., 'user#1234') or display name of the user to find."
|
||||
}
|
||||
},
|
||||
"required": ["user_name"]
|
||||
@ -1104,13 +1104,13 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration(
|
||||
name="get_user_avatar",
|
||||
description="Gets the display avatar URL for a given user ID.",
|
||||
description="Gets the display avatar URL for a given User ID.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {
|
||||
"type": "string",
|
||||
"description": "The Discord ID of the user."
|
||||
"description": "The User ID of the user."
|
||||
}
|
||||
},
|
||||
"required": ["user_id"]
|
||||
@ -1218,13 +1218,13 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration(
|
||||
name="move_user_to_voice_channel",
|
||||
description="Moves a user to a specified voice channel. Requires 'Move Members' permission.",
|
||||
description="Moves a user (identified by User ID) to a specified voice channel. Requires 'Move Members' permission.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {
|
||||
"type": "string",
|
||||
"description": "The ID of the user to move."
|
||||
"description": "The User ID of the user to move."
|
||||
},
|
||||
"target_channel_id": {
|
||||
"type": "string",
|
||||
@ -1252,13 +1252,13 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration(
|
||||
name="assign_role_to_user",
|
||||
description="Assigns a specific role to a user by their IDs. Requires 'Manage Roles' permission and role hierarchy.",
|
||||
description="Assigns a specific role to a user (identified by User ID and Role ID). Requires 'Manage Roles' permission and role hierarchy.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {
|
||||
"type": "string",
|
||||
"description": "The ID of the user to assign the role to."
|
||||
"description": "The User ID of the user to assign the role to."
|
||||
},
|
||||
"role_id": {
|
||||
"type": "string",
|
||||
@ -1272,13 +1272,13 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration(
|
||||
name="remove_role_from_user",
|
||||
description="Removes a specific role from a user by their IDs. Requires 'Manage Roles' permission and role hierarchy.",
|
||||
description="Removes a specific role from a user (identified by User ID and Role ID). Requires 'Manage Roles' permission and role hierarchy.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {
|
||||
"type": "string",
|
||||
"description": "The ID of the user to remove the role from."
|
||||
"description": "The User ID of the user to remove the role from."
|
||||
},
|
||||
"role_id": {
|
||||
"type": "string",
|
||||
@ -1328,7 +1328,7 @@ def create_tools_list():
|
||||
},
|
||||
"user_id": {
|
||||
"type": "string",
|
||||
"description": "Optional: Filter to only delete messages from this user ID."
|
||||
"description": "Optional: Filter to only delete messages from this User ID."
|
||||
},
|
||||
"before_message_id": {
|
||||
"type": "string",
|
||||
@ -1400,13 +1400,13 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration(
|
||||
name="remind_user",
|
||||
description="Sets a reminder for a user to be delivered via DM at a specific future time (ISO 8601 format with timezone). Requires scheduler setup.",
|
||||
description="Sets a reminder for a user (identified by User ID) to be delivered via DM at a specific future time (ISO 8601 format with timezone). Requires scheduler setup.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {
|
||||
"type": "string",
|
||||
"description": "The ID of the user to remind."
|
||||
"description": "The User ID of the user to remind."
|
||||
},
|
||||
"reminder_text": {
|
||||
"type": "string",
|
||||
@ -1520,11 +1520,11 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration(
|
||||
name="get_user_username",
|
||||
description="Gets the unique Discord username (e.g., username#1234) for a given user ID.",
|
||||
description="Gets the unique Discord username (e.g., 'username#1234') for a given User ID.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {"type": "string", "description": "The Discord user ID of the target user."}
|
||||
"user_id": {"type": "string", "description": "The User ID of the target user."}
|
||||
},
|
||||
"required": ["user_id"]
|
||||
}
|
||||
@ -1533,11 +1533,11 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration(
|
||||
name="get_user_display_name",
|
||||
description="Gets the display name for a given user ID (server nickname if in a guild, otherwise global name).",
|
||||
description="Gets the display name for a given User ID (server nickname if in a guild, otherwise global name).",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {"type": "string", "description": "The Discord user ID of the target user."}
|
||||
"user_id": {"type": "string", "description": "The User ID of the target user."}
|
||||
},
|
||||
"required": ["user_id"]
|
||||
}
|
||||
@ -1546,11 +1546,11 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration(
|
||||
name="get_user_avatar_url",
|
||||
description="Gets the URL of the user's current avatar (server-specific if available, otherwise global).",
|
||||
description="Gets the URL of the user's current avatar (server-specific if available, otherwise global) by User ID.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {"type": "string", "description": "The Discord user ID of the target user."}
|
||||
"user_id": {"type": "string", "description": "The User ID of the target user."}
|
||||
},
|
||||
"required": ["user_id"]
|
||||
}
|
||||
@ -1559,11 +1559,11 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration(
|
||||
name="get_user_status",
|
||||
description="Gets the current status (online, idle, dnd, offline) of a user. Requires guild context and potentially presence intent.",
|
||||
description="Gets the current status (online, idle, dnd, offline) of a user by User ID. Requires guild context and potentially presence intent.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {"type": "string", "description": "The Discord user ID of the target user."}
|
||||
"user_id": {"type": "string", "description": "The User ID of the target user."}
|
||||
},
|
||||
"required": ["user_id"]
|
||||
}
|
||||
@ -1572,11 +1572,11 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration(
|
||||
name="get_user_activity",
|
||||
description="Gets the current activity (e.g., Playing game, Listening to Spotify) of a user. Requires guild context and potentially presence intent.",
|
||||
description="Gets the current activity (e.g., Playing game, Listening to Spotify) of a user by User ID. Requires guild context and potentially presence intent.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {"type": "string", "description": "The Discord user ID of the target user."}
|
||||
"user_id": {"type": "string", "description": "The User ID of the target user."}
|
||||
},
|
||||
"required": ["user_id"]
|
||||
}
|
||||
@ -1585,11 +1585,11 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration(
|
||||
name="get_user_roles",
|
||||
description="Gets the list of roles for a user in the current server. Requires guild context.",
|
||||
description="Gets the list of roles for a user (identified by User ID) in the current server. Requires guild context.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {"type": "string", "description": "The Discord user ID of the target user."}
|
||||
"user_id": {"type": "string", "description": "The User ID of the target user."}
|
||||
},
|
||||
"required": ["user_id"]
|
||||
}
|
||||
@ -1598,11 +1598,11 @@ def create_tools_list():
|
||||
tool_declarations.append(
|
||||
FunctionDeclaration(
|
||||
name="get_user_profile_info",
|
||||
description="Gets comprehensive profile information for a given user ID (username, display name, avatar, status, activity, roles, etc.).",
|
||||
description="Gets comprehensive profile information for a given User ID (username, display name, avatar, status, activity, roles, etc.).",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {"type": "string", "description": "The Discord user ID of the target user."}
|
||||
"user_id": {"type": "string", "description": "The User ID of the target user."}
|
||||
},
|
||||
"required": ["user_id"]
|
||||
}
|
||||
|
@ -46,9 +46,10 @@ OS: Arch Linux x86_64; Host: 1.0; Kernel: 6.14.5-arch1-1; Packages: 364 (pacman)
|
||||
|
||||
**Tool Usage Rules:**
|
||||
1. Whenever a tool can fulfill a request, provide needed info, or perform a relevant action, you MUST invoke it.
|
||||
2. After ALL necessary tool calls are made, you MUST call `no_operation` to signal completion.
|
||||
3. If no tool use is needed, call `no_operation` immediately.
|
||||
4. DO NOT use `send_discord_message`.
|
||||
2. When a tool requires identifying a user (e.g., `timeout_user`, `get_user_facts`), prefer providing their unique `username` or `user_id`. You will be given the current user's `username`, `display_name`, and `user_id`.
|
||||
3. After ALL necessary tool calls are made, you MUST call `no_operation` to signal completion.
|
||||
4. If no tool use is needed, call `no_operation` immediately.
|
||||
5. DO NOT use `send_discord_message`.
|
||||
|
||||
Replying: Use `"reply_to_message_id": "message_id"`.
|
||||
Pinging: Use `[PING: username]` in the `content` field (system auto-resolves).
|
||||
@ -153,7 +154,7 @@ OS: Arch Linux x86_64; Host: 1.0; Kernel: 6.14.5-arch1-1; Uptime: 11 days, 21 ho
|
||||
- `create_poll`: Make a poll message. Ex: `create_poll(question="...", options=["...", "..."])`.
|
||||
- `run_terminal_command`: Execute shell command in a (empty) Docker sandbox. EXTREME CAUTION. Avoid if unsure. Ex: `run_terminal_command(command="...")`.
|
||||
- `execute_internal_command`: Execute shell command on host machine. You need to pass the user id of the user who triggered this tool call into the function or it will not work. Do not try to add a user id without first grabbing the user id of the requesting user by using the appropriate get user id tool. EXTREME CAUTION. Avoid if unsure.
|
||||
- `get_user_id`: Find user ID from username/display name. Ex: `get_user_id(user_name="...")`.
|
||||
- `get_user_id`: Find user ID from username/display name. Ex: `get_user_id(user_name="...")`. **Note: You will be provided with the current user's username and ID directly.**
|
||||
- `no_operation`: **MUST call this after all other necessary tool calls are done.** Use immediately if no tools needed. Does nothing itself.
|
||||
|
||||
**Output Format Reminder:**
|
||||
@ -214,6 +215,10 @@ Let these traits gently shape *how* you communicate, but don't mention them expl
|
||||
# --- Append Dynamic Context ---
|
||||
system_context_parts = [base_prompt] # Start with the chosen base prompt
|
||||
|
||||
# Add current user information
|
||||
system_context_parts.append(f"\nInteracting with: {message.author.display_name} (Username: {message.author.name}, ID: {message.author.id}).")
|
||||
system_context_parts.append(f"For tools requiring user identification, use their Username ('{message.author.name}') or ID ('{message.author.id}'). For conversational mentions, '{message.author.display_name}' is fine.")
|
||||
|
||||
# Add current time
|
||||
now = datetime.datetime.now(datetime.timezone.utc)
|
||||
time_str = now.strftime("%Y-%m-%d %H:%M:%S %Z")
|
||||
@ -262,7 +267,7 @@ Let these traits gently shape *how* you communicate, but don't mention them expl
|
||||
common_topics = user_topic_names.intersection(active_topic_names)
|
||||
if common_topics:
|
||||
topics_list_str = ", ".join(common_topics)
|
||||
system_context_parts.append(f"{message.author.display_name} seems interested in: {topics_list_str}.")
|
||||
system_context_parts.append(f"{message.author.display_name} (Username: {message.author.name}) seems interested in: {topics_list_str}.")
|
||||
|
||||
# Add conversation sentiment context (if available)
|
||||
if channel_id in cog.conversation_sentiment:
|
||||
@ -278,13 +283,13 @@ Let these traits gently shape *how* you communicate, but don't mention them expl
|
||||
user_id_str = str(user_id)
|
||||
user_sentiment = channel_sentiment.get("user_sentiments", {}).get(user_id_str)
|
||||
if user_sentiment:
|
||||
user_sentiment_str = f"{message.author.display_name}'s recent messages seem {user_sentiment.get('sentiment', 'neutral')}"
|
||||
user_sentiment_str = f"{message.author.display_name} (Username: {message.author.name})'s recent messages seem {user_sentiment.get('sentiment', 'neutral')}"
|
||||
user_intensity = user_sentiment.get('intensity', 0.5)
|
||||
if user_intensity > 0.7: user_sentiment_str += " (strongly so)"
|
||||
system_context_parts.append(user_sentiment_str + ".")
|
||||
if user_sentiment.get("emotions"):
|
||||
emotions_str = ", ".join(user_sentiment["emotions"])
|
||||
system_context_parts.append(f"Detected emotions from them might include: {emotions_str}.")
|
||||
system_context_parts.append(f"Detected emotions from {message.author.display_name} (Username: {message.author.name}) might include: {emotions_str}.")
|
||||
|
||||
# Briefly mention overall atmosphere if not neutral
|
||||
if channel_sentiment.get('overall') != "neutral":
|
||||
@ -311,7 +316,7 @@ Let these traits gently shape *how* you communicate, but don't mention them expl
|
||||
if score_val <= 20: relationship_level = "kinda new/acquaintance"
|
||||
elif score_val <= 60: relationship_level = "familiar/friends"
|
||||
else: relationship_level = "close/besties"
|
||||
system_context_parts.append(f"Your relationship with {message.author.display_name} is: {relationship_level} (Score: {score_val:.1f}/100). Adjust your tone.")
|
||||
system_context_parts.append(f"Your relationship with {message.author.display_name} (Username: {message.author.name}) is: {relationship_level} (Score: {score_val:.1f}/100). Adjust your tone.")
|
||||
except Exception as e:
|
||||
print(f"Error retrieving relationship score for prompt injection: {e}")
|
||||
|
||||
@ -339,7 +344,7 @@ Let these traits gently shape *how* you communicate, but don't mention them expl
|
||||
|
||||
if final_user_facts:
|
||||
facts_str = "; ".join(final_user_facts)
|
||||
system_context_parts.append(f"Stuff you remember about {message.author.display_name}: {facts_str}")
|
||||
system_context_parts.append(f"Stuff you remember about {message.author.display_name} (Username: {message.author.name}): {facts_str}")
|
||||
except Exception as e:
|
||||
print(f"Error retrieving combined user facts for prompt injection: {e}")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user