Detect OpenAI Reasoning Models and Adjust Request Payload

Offen Anfängerfreundlich
#176 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
78/100
Issue-Typ
Feature
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
typescript

Rechercherichtung

Beginne in packages/models/src/providers/openai.ts, wo laut Issue der Request-Payload erstellt wird, und füge den Model-Detection-Helper sowie die im Issue beschriebenen bedingten Payload-Felder hinzu. Untersuche zuerst die bestehende Payload-Erstellung und die Tests in der Nähe und ergänze dann Tests für Reasoning- und Standardmodell-Zweige. Fertig ist die Arbeit, wenn beide Zweige die angegebenen Felder und die Prompt-Rolle verwenden und die angeforderten Typecheck-, Test- und Lint-Befehle erfolgreich sind.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug good first issue

Goal

Add a helper function that detects whether an OpenAI model identifier refers to a reasoning model, and use it to conditionally adjust the request payload sent in packages/models/src/providers/openai.ts.

Background

OpenAI reasoning models (o1, o3, o3-mini, o4-mini, and future variants) reject the temperature parameter and require max_completion_tokens instead of max_tokens. The current adapter sends both unconditionally, causing HTTP 400 errors for any reasoning model.

This sub-issue is part of the parent issue: OpenAI adapter incompatible with reasoning models.

What to Build

Add an isOpenAIReasoningModel(model: string): boolean helper in the openai provider:

function isOpenAIReasoningModel(model: string): boolean {
  const lower = model.toLowerCase();
  return (
    /^o\d/.test(lower) ||            // o1, o3, o3-mini, o4-mini, o5, etc.
    lower.includes("-reasoning") ||   // possible future naming convention
    lower.startsWith("gpt-6")         // gpt-6 and variants when in reasoning mode
  );
}

Then update the body payload construction to branch on isReasoning:

const isReasoning = isOpenAIReasoningModel(model);

const bodyPayload: Record<string, unknown> = {
  model,
  messages: [
    { role: isReasoning ? "developer" : "system", content: prompts.system },
    { role: "user", content: prompts.user },
  ],
  ...(isReasoning
    ? { max_completion_tokens: effectiveCeiling }
    : { temperature, max_tokens: effectiveCeiling }),
  response_format: { type: "json_object" },
};

Done When

  • isOpenAIReasoningModel correctly identifies o-series and gpt-6 models
  • Standard models (gpt-4o, gpt-5, custom endpoints) return false and are unaffected
  • Reasoning models receive max_completion_tokens and no temperature
  • Standard models receive temperature and max_tokens as before
  • role: "developer" is used for the system prompt on reasoning models
  • Unit tests cover the detection helper and both branches of the payload builder
  • npm run typecheck, npm test, and npm run lint all pass
Vorherrschende Sprache
TypeScript
Sterne
125
Forks
23
Ø Merge
2 T. 13 Std.
Gemergte PRs (30 T.)
12

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus devarshishimpi/codra

Alle Issues in devarshishimpi/codra

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.