vercel / ai

Build AI-powered applications with React, Svelte, Vue, and Solid
https://sdk.vercel.ai/docs
Other
10.1k stars 1.5k forks source link

Gemini: AI_UnsupportedFunctionalityError: system messages are only supported at the beginning of the conversation #2384

Open GorvGoyl opened 3 months ago

GorvGoyl commented 3 months ago

Description

I recently updated my packages and started receiving an error for the Gemini Flash 1.5 AI model. I understand that the system message should come first, but is this a requirement for Google Gemini? I checked the Gemini documentation but couldn't find any information on the order of the system message.

PS: Keeping the system message at last improves the response quality for some models.

Error:   [AI_UnsupportedFunctionalityError: 'system messages are only supported at the beginning of the conversation' functionality not supported.] {
  name: 'AI_UnsupportedFunctionalityError',
  functionality: 'system messages are only supported at the beginning of the conversation'
}
error in streaming generateResponse API  [AI_UnsupportedFunctionalityError: 'system messages are only supported at the beginning of the conversation' functionality not supported.] {
  name: 'AI_UnsupportedFunctionalityError',
  functionality: 'system messages are only supported at the beginning of the conversation'
}
stack trace:  AI_UnsupportedFunctionalityError: 'system messages are only supported at the beginning of the conversation' functionality not supported.
    at convertToGoogleGenerativeAIMessages (webpack-internal:///(middleware)/./node_modules/.pnpm/@ai-sdk+google@0.0.27_zod@3.23.8/node_modules/@ai-sdk/google/dist/index.mjs:32:17)
    at GoogleGenerativeAILanguageModel.getArgs (webpack-internal:///(middleware)/./node_modules/.pnpm/@ai-sdk+google@0.0.27_zod@3.23.8/node_modules/@ai-sdk/google/dist/index.mjs:209:51)
    at GoogleGenerativeAILanguageModel.doStream (webpack-internal:///(middleware)/./node_modules/.pnpm/@ai-sdk+google@0.0.27_zod@3.23.8/node_modules/@ai-sdk/google/dist/index.mjs:307:43)
    at fn (webpack-internal:///(middleware)/./node_modules/.pnpm/ai@3.2.33_openai@4.53.0_encoding@0.1.13__react@18.3.1_solid-js@1.8.18_svelte@4.2.18_vue@3.4.3_b6x64b64e4vtih556h5y2ochom/node_modules/ai/dist/index.mjs:1974:35)
    at eval (webpack-internal:///(middleware)/./node_modules/.pnpm/ai@3.2.33_openai@4.53.0_encoding@0.1.13__react@18.3.1_solid-js@1.8.18_svelte@4.2.18_vue@3.4.3_b6x64b64e4vtih556h5y2ochom/node_modules/ai/dist/index.mjs:1363:28)
    at Object.startActiveSpan (webpack-internal:///(middleware)/./node_modules/.pnpm/ai@3.2.33_openai@4.53.0_encoding@0.1.13__react@18.3.1_solid-js@1.8.18_svelte@4.2.18_vue@3.4.3_b6x64b64e4vtih556h5y2ochom/node_modules/ai/dist/index.mjs:1292:14)
    at recordSpan (webpack-internal:///(middleware)/./node_modules/.pnpm/ai@3.2.33_openai@4.53.0_encoding@0.1.13__react@18.3.1_solid-js@1.8.18_svelte@4.2.18_vue@3.4.3_b6x64b64e4vtih556h5y2ochom/node_modules/ai/dist/index.mjs:1361:17)
    at eval (webpack-internal:///(middleware)/./node_modules/.pnpm/ai@3.2.33_openai@4.53.0_encoding@0.1.13__react@18.3.1_solid-js@1.8.18_svelte@4.2.18_vue@3.4.3_b6x64b64e4vtih556h5y2ochom/node_modules/ai/dist/index.mjs:1963:15)
    at _retryWithExponentialBackoff (webpack-internal:///(middleware)/./node_modules/.pnpm/ai@3.2.33_openai@4.53.0_encoding@0.1.13__react@18.3.1_solid-js@1.8.18_svelte@4.2.18_vue@3.4.3_b6x64b64e4vtih556h5y2ochom/node_modules/ai/dist/index.mjs:122:18)
    at eval (webpack-internal:///(middleware)/./node_modules/.pnpm/ai@3.2.33_openai@4.53.0_encoding@0.1.13__react@18.3.1_solid-js@1.8.18_svelte@4.2.18_vue@3.4.3_b6x64b64e4vtih556h5y2ochom/node_modules/ai/dist/index.mjs:111:25)

Code example

No response

Additional context

"@ai-sdk/google": "^0.0.27",
"ai": "^3.2.33"
wong2 commented 3 months ago

I think since the Gemini API returned this error, it means that's how it is

GorvGoyl commented 3 months ago

But if I revert ai-sdk/google to the previous version (0.0.26), the error doesn't appear.

medkira commented 3 months ago

i am facing the same error , and same If i revert ai-sdk/google to the previous version (0.0.26), the error doesn't appear.