Add function_id tracking and enable JSON mode for all AI functions
This commit is contained in:
@@ -130,6 +130,7 @@ class AIProcessor:
|
||||
temperature: float = 0.7,
|
||||
response_format: Optional[Dict] = None,
|
||||
api_key: Optional[str] = None,
|
||||
function_id: Optional[str] = None,
|
||||
response_steps=None
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
@@ -167,10 +168,17 @@ class AIProcessor:
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
# Add function_id to prompt if provided (for tracking)
|
||||
final_prompt = prompt
|
||||
if function_id:
|
||||
function_id_prefix = f'function_id: "{function_id}"\n\n'
|
||||
final_prompt = function_id_prefix + prompt
|
||||
logger.info(f"Added function_id to prompt: {function_id}")
|
||||
|
||||
# EXACT request format from reference plugin (openai-api.php line 402-404)
|
||||
body_data = {
|
||||
'model': model,
|
||||
'messages': [{'role': 'user', 'content': prompt}],
|
||||
'messages': [{'role': 'user', 'content': final_prompt}],
|
||||
'temperature': temperature,
|
||||
}
|
||||
|
||||
@@ -460,7 +468,13 @@ class AIProcessor:
|
||||
Returns:
|
||||
Dict with 'content', 'tokens_used', 'model', 'cost', 'error'
|
||||
"""
|
||||
result = self._call_openai(prompt, model, max_tokens, temperature)
|
||||
# Generate function_id for tracking (ai-generate-content-03 for AIProcessor path)
|
||||
function_id = "ai-generate-content-03"
|
||||
# Get response_format from settings for generate_content
|
||||
from igny8_core.ai.settings import get_model_config
|
||||
model_config = get_model_config('generate_content')
|
||||
response_format = model_config.get('response_format')
|
||||
result = self._call_openai(prompt, model, max_tokens, temperature, response_format=response_format, function_id=function_id)
|
||||
|
||||
return {
|
||||
'content': result.get('content', ''),
|
||||
|
||||
Reference in New Issue
Block a user