fix: Update generation configuration to include system_instruction for model content generation

This commit is contained in:
Slipstream 2025-05-28 23:24:02 -06:00
parent 8e6b9b6270
commit 2db6b0f850
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD

View File

@ -378,31 +378,32 @@ class TetoCog(commands.Cog):
# For now, let's try with system_instruction in config.
# The `genai.GenerativeModel` has `system_instruction` parameter.
# `genai_client.aio.models.generate_content` does not directly take system_instruction.
# It's better to get a model instance first.
model_instance = self.genai_client.get_model(f"models/{self._ai_model}")
# Update: system_instruction is part of the model, not generate_content config directly for client.generate_content
# We need to use model_instance.generate_content_async for system_instruction.
# Or, if using client.generate_content, the system prompt must be the first message.
# Let's adjust to use model_instance.generate_content_async
# The `genai.GenerativeModel` has `system_instruction` parameter.
# `genai_client.aio.models.generate_content` does not directly take system_instruction.
# It's better to pass system_instruction within the generation_config.
# Add system_instruction to generation_config
generation_config_with_system = types.GenerateContentConfig(
temperature=generation_config.temperature,
max_output_tokens=generation_config.max_output_tokens,
safety_settings=generation_config.safety_settings,
system_instruction=types.Content(role="system", parts=[types.Part(text=system_prompt_text)])
)
final_contents_for_api = vertex_contents
# The system prompt is very long, better to use system_instruction if model supports it.
# Gemini models generally support system_instruction.
try:
print(f"[TETO DEBUG] Sending to Vertex AI. Model: {self._ai_model}, Tool Config: {vertex_tools is not None}")
response = await model_instance.generate_content_async(
response = await self.genai_client.aio.models.generate_content(
model=f"projects/{PROJECT_ID}/locations/{LOCATION}/models/{self._ai_model}", # Full model path
contents=final_contents_for_api,
generation_config=generation_config,
config=generation_config_with_system, # Pass the updated config
tools=vertex_tools,
tool_config=types.ToolConfig(
function_calling_config=types.FunctionCallingConfig(
mode=types.FunctionCallingConfigMode.ANY if vertex_tools else types.FunctionCallingConfigMode.NONE
)
) if vertex_tools else None,
# Pass system_instruction here
system_instruction=types.Content(role="system", parts=[types.Part(text=system_prompt_text)])
)
except google_exceptions.GoogleAPICallError as e: