$effort, 'omitTemperature' => $info !== null && !empty($info['omitTemperature']), 'headroom' => raijuAiEffortHeadroom($effort), 'param' => $info['effort']['param'] ?? null ]; } /** Add the effort parameter of the right API to an already built request body. $api: chat (Chat Completions), responses, anthropic. */ function raijuAiApplyReasoning(array $body, array $plan, string $api): array { if ($plan['effort'] === null) return $body; if ($plan['omitTemperature']) unset($body['temperature']); if ($api === 'anthropic' && $plan['param'] === 'anthropic') { $body['output_config'] = ['effort' => $plan['effort']]; } elseif ($api === 'responses' && $plan['param'] === 'openai') { $body['reasoning'] = ['effort' => $plan['effort']]; } elseif ($api === 'chat' && $plan['param'] === 'openai') { $body['reasoning_effort'] = $plan['effort']; } return $body; } /** Recommended and default models for a provider, with the default effort setting. Custom OpenAI-compatible hosts get no preset. */ function raijuAiProviderModelDefaults(string $provider, string $baseUrl = ''): array { $catalog = raijuAiModelCatalog()[$provider] ?? raijuAiModelCatalog()['openai-compatible']; $preset = ['chatModel' => (string)$catalog['text']['chat'], 'textModel' => (string)$catalog['text']['text']]; if ($provider === 'openai-compatible' && $baseUrl !== '' && raijuAiBaseUrlHost($baseUrl) !== 'api.openai.com') { $preset = ['chatModel' => '', 'textModel' => '']; } return $preset + ['reasoning' => ['chat' => 'recommended', 'text' => 'recommended']]; } /** What the browser needs: the registry reduced to the fields the UI uses. */ function raijuAiCapabilitiesForUi(): array { $models = []; foreach (raijuAiCapabilityCatalog()['models'] as $entry) { $models[] = [ 'provider' => $entry['provider'], 'host' => $entry['host'], 'model' => $entry['model'], 'label' => $entry['label'] ?? $entry['model'], 'tier' => $entry['tier'] ?? 'light', 'levels' => $entry['effort']['levels'] ?? [], 'recommended' => $entry['effort']['recommended'] ?? [] ]; } return ['models' => $models, 'levels' => RAIJU_AI_EFFORT_LEVELS]; }