Skip to content

workers-ai-provider does not handle Response API #270

@harshil1712

Description

@harshil1712

The workers-ai-provider package doesn't handle the response API for the new GPT OSS models.

  • When passing the input and instructions parameters needed for these models, the following error is returned:

Example code:

const aiResponse = await generateText({
    model: workersAi('@cf/openai/gpt-oss-20b'),
    input: message,
    instructions: 'You are a helpful assistant',
  });

Error:

✘ [ERROR] Error in conversation: InvalidPromptError [AI_InvalidPromptError]: Invalid prompt: prompt or messages must be defined

      at standardizePrompt
  (file:///Users/harshil/projects/voice-assistant-worker/node_modules/ai/src/prompt/standardize-prompt.ts:23:11)
      at generateText
  (file:///Users/harshil/projects/voice-assistant-worker/node_modules/ai/src/generate-text/generate-text.ts:265:31)
      at workersAiAiSdk
  (file:///Users/harshil/projects/voice-assistant-worker/src/index.ts:59:28)
      at SiriAssistant.handleConversation
  (file:///Users/harshil/projects/voice-assistant-worker/src/index.ts:144:32)
      at async SiriAssistant._tryCatch
  (file:///Users/harshil/projects/voice-assistant-worker/node_modules/agents/src/index.ts:805:14)
      at async SiriAssistant.fetch
  (file:///Users/harshil/projects/voice-assistant-worker/node_modules/partyserver/src/index.ts:308:16)
  {
    cause: undefined,
    prompt: { system: undefined, prompt: undefined, messages:
  undefined },
    Symbol(vercel.ai.error): true,
    Symbol(vercel.ai.error.AI_InvalidPromptError): true
  }
  • If passing messages and/or prompt (as per the error message), a new error is thrown.
    Example code:
const aiResponse = await generateText({
    model: workersAi('@cf/openai/gpt-oss-20b'),
    messages: [{ role: 'user', content: message }],
  });

Error:

✘ [ERROR] Error in conversation: InferenceUpstreamError [AiError]: 5006: Error: oneOf at '/' not met, 0 matches: required properties at '/' are 'input', required properties at '/' are 'requests'

      at Ai._parseError (cloudflare-internal:ai-api:212:24)
      at async Ai.run (cloudflare-internal:ai-api:190:19)
      at async WorkersAIChatLanguageModel.doGenerate
  (file:///Users/harshil/projects/voice-assistant-worker/node_modules/workers-ai-provider/src/workersai-chat-language-model.ts:145:18)
      at async fn
  (file:///Users/harshil/projects/voice-assistant-worker/node_modules/ai/src/generate-text/generate-text.ts:382:32)
      at null.<anonymous> (async
  file:///Users/harshil/projects/voice-assistant-worker/.wrangler/tmp/dev-Q4WtKi/index.js:50184:22)
      at async _retryWithExponentialBackoff
  (file:///Users/harshil/projects/voice-assistant-worker/node_modules/ai/src/util/retry-with-exponential-backoff.ts:96:12)
      at async fn
  (file:///Users/harshil/projects/voice-assistant-worker/node_modules/ai/src/generate-text/generate-text.ts:338:34)
      at null.<anonymous> (async
  file:///Users/harshil/projects/voice-assistant-worker/.wrangler/tmp/dev-Q4WtKi/index.js:50184:22)
      at async generateText
  (file:///Users/harshil/projects/voice-assistant-worker/node_modules/ai/src/generate-text/generate-text.ts:274:12)
      at async workersAiAiSdk
  (file:///Users/harshil/projects/voice-assistant-worker/src/index.ts:59:22)

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