Skip to content

OpenAI 兼容的 AI 提供商目前并不够兼容 #2522

@Do1e

Description

@Do1e

Describe the bug

Image

如标题所属,在 Vercel AI SDK 中,createOpenAI 函数返回一个提供者(provider)实例。直接调用提供者函数会自动选择最合适的 API(可能是 responses, chat, 或 completion),这取决于传入的模型名称。
但事实上很多提供商给的AI这里自动选择的都是错的(比如自建的one-api,阿里云提供的api)。

只是一个很小的改进不想提PR了,这里直接给我的解决方案吧:

--- a/apps/core/src/modules/ai/ai-provider.factory.ts
+++ b/apps/core/src/modules/ai/ai-provider.factory.ts
@@ -15,17 +15,20 @@ export function createLanguageModel(
         baseURL: config.endpoint || undefined,
       })(modelName)
 
-    case AIProviderType.OpenAICompatible:
+    case AIProviderType.OpenAICompatible: {
       if (!config.endpoint) {
         throw new Error(
           `Endpoint is required for OpenAI-compatible provider: ${config.id}`,
         )
       }
-      // OpenAI-compatible providers use the same createOpenAI with custom baseURL
-      return createOpenAI({
+      // OpenAI-compatible providers: create a custom provider instance
+      const openai = createOpenAI({
         apiKey: config.apiKey,
         baseURL: config.endpoint,
-      })(modelName)
+      })
+      // For compatible APIs, use chat model format
+      return openai.chat(modelName)
+    }

Reproduction

None

System Info

System:
    OS: Linux 6.8 Alpine Linux
    CPU: (2) x64 Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz
    Memory: 1.09 GB / 3.82 GB
    Container: Yes
    Shell: Unknown - /bin/sh
  Binaries:
    Node: 22.18.0 - /usr/local/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.9.3 - /usr/local/bin/npm

https://do1e.cn/api/v2

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions