This commit is contained in:
Slipstream 2025-04-29 09:53:44 -06:00
parent c87bacf332
commit e3eb4b6190
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD
3 changed files with 28 additions and 4 deletions

View File

@ -166,7 +166,8 @@ async def call_vertex_api_with_retry(
generation_config: 'GenerationConfig', # Use string literal for type hint
safety_settings: Optional[Dict[Any, Any]], # Use Any for broader compatibility
request_desc: str,
stream: bool = False
stream: bool = False,
tool_choice: Optional[str] = None # Add tool_choice parameter
) -> Union['GenerationResponse', AsyncIterable['GenerationResponse'], None]: # Use string literals
"""
Calls the Vertex AI Gemini API with retry logic.
@ -198,7 +199,8 @@ async def call_vertex_api_with_retry(
contents=contents,
generation_config=generation_config,
safety_settings=safety_settings or STANDARD_SAFETY_SETTINGS,
stream=stream
stream=stream,
tool_choice=tool_choice # Pass tool_choice here
)
# --- Success Logging ---
@ -608,7 +610,8 @@ async def get_ai_response(cog: 'GurtCog', message: discord.Message, model_name:
contents=contents,
generation_config=generation_config_initial,
safety_settings=STANDARD_SAFETY_SETTINGS,
request_desc=f"Initial response check for message {message.id}"
request_desc=f"Initial response check for message {message.id}",
tool_choice="any" # Force a tool call
)
# --- Log Raw Request and Response ---

View File

@ -837,6 +837,19 @@ def create_tools_list():
}
)
)
# --- no_operation ---
tool_declarations.append(
generative_models.FunctionDeclaration(
name="no_operation",
description="Does absolutely nothing. Used when a tool call is forced but no action is needed.",
parameters={
"type": "object",
"properties": {}, # No parameters
"required": []
}
)
)
return tool_declarations
# Initialize TOOLS list, handling potential ImportError if library not installed

View File

@ -1185,6 +1185,13 @@ async def create_new_tool(cog: commands.Cog, tool_name: str, description: str, p
"generated_declaration_params": declaration_params_str
}
async def no_operation(cog: commands.Cog) -> Dict[str, Any]:
"""
Does absolutely nothing. Used when a tool call is forced but no action is needed.
"""
print("Executing no_operation tool.")
return {"status": "success", "message": "No operation performed."}
# --- Tool Mapping ---
# This dictionary maps tool names (used in the AI prompt) to their implementation functions.
@ -1214,5 +1221,6 @@ TOOL_MAPPING = {
"read_file_content": read_file_content,
"create_new_tool": create_new_tool, # Added the meta-tool
"execute_internal_command": execute_internal_command, # Added internal command execution
"get_user_id": get_user_id # Added user ID lookup tool
"get_user_id": get_user_id, # Added user ID lookup tool
"no_operation": no_operation # Added no-op tool
}