Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown name minItems - Google AI SDK and OpenAI SDK #2762

Closed
BleedingDev opened this issue Aug 21, 2024 · 1 comment
Closed

Unknown name minItems - Google AI SDK and OpenAI SDK #2762

BleedingDev opened this issue Aug 21, 2024 · 1 comment
Labels
ai/provider bug Something isn't working duplicate This issue or pull request already exists

Comments

@BleedingDev
Copy link

BleedingDev commented Aug 21, 2024

Description

I updated to "@ai-sdk/google": "^0.0.43", and now I get error. It seems like this SDK tries to use feature that is not supported as stated in issues here:
google-gemini/generative-ai-js#200
google/generative-ai-docs#210

Edit: Seems like this is broken with OpenAI "@ai-sdk/openai": "^0.0.51", as well. But only when structuredOutputs is true.

    model: openai('gpt-4o-mini', {
      structuredOutputs: true
    }),

Error

Invalid JSON payload received. Unknown name \\"minItems\\" at 'generation_config.response_schema.properties[1].value.items.properties[1].value': Cannot find field.\\nInvalid JSON payload received. Unknown name \\"minItems\\" at 'generation_config.response_schema.properties[1].value': Cannot find field.",\n

Code example

'use server'
import { generateObject } from 'ai'
import { google } from '@ai-sdk/google'
import { z } from 'zod'
const getQuizSchema = (amountQuestions: number, amountAnswers: number) => {
  const answerSchema = z.object({
    text: z.string(),
    isCorrect: z.boolean(),
  })

  const taskSchema = z.object({
    question: z.string(),
    answers: z.array(answerSchema).length(amountAnswers),
  })

  const quizSchema = z.object({
    chapterName: z.string(),
    tasks: z.array(taskSchema).length(amountQuestions),
  })
  return quizSchema
}

export async function generateQuiz(
  content: string,
  {
    outputLang = 'English',
    amountQuestions = 5,
    amountAnswers = 4,
    allowMultiple = false,
  }: { outputLang?: string; amountQuestions?: number; amountAnswers?: number; allowMultiple?: boolean },
) {
  const schema = getQuizSchema(amountQuestions, amountAnswers)
  const { object } = await generateObject({
    model: google('models/gemini-1.5-flash-latest'),
    schema: schema,
    system: trim`
...
    `,
    prompt: trim`
...
    `,
  })

  return object
}

Additional context

Google

Broken in both tool and json modes.

OpenAI

Broken when structuredOutputs is true.

@BleedingDev BleedingDev changed the title Unknown name minItems - Google AI SDK Unknown name minItems - Google AI SDK and OpenAI SDK Aug 21, 2024
@lgrammel
Copy link
Collaborator

The provider JSON specs don't fully support the OpenAPI 3.0 spec (Google) or, as it seems, JSON Schema 7 (OpenAI) fully.

In the OpenAI case, just disable structured outputs.

In the Google case, I'm working on a workaround: #2743

@lgrammel lgrammel added bug Something isn't working duplicate This issue or pull request already exists ai/provider labels Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai/provider bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants