mirror of
https://git.meshkee.com/Meshkee/backend.git
synced 2026-08-11 22:30:59 +04:30
Switch AI defaults to OpenAI gpt-4.1-nano.
Prefer the cheapest ChatGPT model that supports our JSON completions, and skip custom temperature for gpt-5/o-series models. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
0743063c15
commit
23ba6344f6
@@ -38,31 +38,47 @@ export function resolveAiProvider(config: ConfigService): AiProviderConfig {
|
||||
return {
|
||||
apiKey: openAiKey,
|
||||
baseUrl: 'https://api.openai.com/v1',
|
||||
model: config.get<string>('OPENAI_MODEL')?.trim() || 'gpt-4o-mini',
|
||||
model: config.get<string>('OPENAI_MODEL')?.trim() || 'gpt-4.1-nano',
|
||||
};
|
||||
}
|
||||
|
||||
function supportsCustomTemperature(model: string): boolean {
|
||||
// gpt-5 / o-series chat models only accept the API default temperature.
|
||||
const id = model.trim().toLowerCase();
|
||||
return !(
|
||||
id.startsWith('gpt-5') ||
|
||||
id.startsWith('o1') ||
|
||||
id.startsWith('o3') ||
|
||||
id.startsWith('o4')
|
||||
);
|
||||
}
|
||||
|
||||
export async function requestAiJsonCompletion(
|
||||
provider: AiProviderConfig,
|
||||
systemPrompt: string,
|
||||
userPrompt: string,
|
||||
temperature = 0.4,
|
||||
): Promise<string> {
|
||||
const body: Record<string, unknown> = {
|
||||
model: provider.model,
|
||||
response_format: { type: 'json_object' },
|
||||
messages: [
|
||||
{ role: 'system', content: systemPrompt },
|
||||
{ role: 'user', content: userPrompt },
|
||||
],
|
||||
};
|
||||
|
||||
if (supportsCustomTemperature(provider.model)) {
|
||||
body.temperature = temperature;
|
||||
}
|
||||
|
||||
const response = await fetch(`${provider.baseUrl}/chat/completions`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${provider.apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: provider.model,
|
||||
temperature,
|
||||
response_format: { type: 'json_object' },
|
||||
messages: [
|
||||
{ role: 'system', content: systemPrompt },
|
||||
{ role: 'user', content: userPrompt },
|
||||
],
|
||||
}),
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
Reference in New Issue
Block a user