feat: Enhance generation configuration by adding system instruction to Vertex AI model requests

This commit is contained in:
Slipstream 2025-06-01 17:46:19 -06:00
parent 5442175679
commit 8b4064cb85
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD

View File

@ -1095,17 +1095,22 @@ CRITICAL: Do NOT output anything other than the required JSON response.
try:
print(f"Querying Vertex AI model {model_path}...")
# Use the model's system_instruction parameter if available and preferred
# For now, the system prompt is embedded in the user_context_text
model_instance = self.genai_client.get_generative_model(
model_name=model_path,
system_instruction=types.Content(role="system", parts=[types.Part(text=system_prompt_text)]) # Pass system prompt here
# Prepare the generation config with system instruction
# The existing 'generation_config' (lines 1063-1072) already has temperature, max_tokens, safety_settings.
# We need to add system_instruction to it.
final_generation_config = types.GenerateContentConfig(
temperature=generation_config.temperature, # from existing config
max_output_tokens=generation_config.max_output_tokens, # from existing config
safety_settings=generation_config.safety_settings, # from existing config
system_instruction=types.Content(role="system", parts=[types.Part(text=system_prompt_text)])
# response_mime_type="application/json", # Consider if model supports this for forcing JSON
)
response = await model_instance.generate_content_async(
contents=request_contents, # This will now only contain the user turn with context and images
generation_config=generation_config,
# stream=False # Default
response = await self.genai_client.aio.models.generate_content(
model=model_path, # Correctly formatted model path
contents=request_contents, # User's message with context and images
generation_config=final_generation_config, # Pass the config with system_instruction
)
ai_response_content = self._get_response_text(response)