Detect OpenAI Reasoning Models and Adjust Request Payload

未关闭 适合新手
#176 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript

调研方向

从 packages/models/src/providers/openai.ts 开始,issue 指出请求负载在此处构建;添加 issue 中描述的模型检测 helper 和条件负载字段。先检查现有的负载构建逻辑及附近的测试,然后补充对推理模型和标准模型分支的覆盖。完成的标准是两个分支都使用指定的字段和提示角色,并且通过要求的 typecheck、test 和 lint 命令。

由索引模型根据 Issue 内容生成。

描述

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
主要语言
TypeScript
星标
125
派生
23
平均合并
2 天 13 小时
30 天内合并 PR
12

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

devarshishimpi/codra 的其他 Issue

查看 devarshishimpi/codra 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。