vercel / ai

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

Request body is not sent with useChat after upgrading to >=2.2.26 #965

Closed zachtball closed 3 months ago

zachtball commented 9 months ago

Description

Install version >2.2.25 Use useChat hook and point the api at a lambda url (haven't tested another backend service) Try to log the request body, it is undefined Install version 2.2.25 Works fine

Code example

  const { messages, input, handleInputChange, append, isLoading, setMessages } = useChat({
    api: process.env.NEXT_PUBLIC_CHAT_LAMBDA_URL,
    body: {
      functions,
      idToken,
      ...settings,
    },
  });

in my backend (lambda) I do

console.log('body', event.body);
// INFO body undefined

Change version to "ai": "2.2.25", and it works fine

INFO    body 
{
    "messages": [
...

Additional context

No response

rollsrobby commented 9 months ago

try setting sendExtraMessageFields to true. works for us with v2.2.35

  const { messages, input, handleInputChange, append, isLoading, setMessages } = useChat({
    api: process.env.NEXT_PUBLIC_CHAT_LAMBDA_URL,
    sendExtraMessageFields: true,
    body: {
      functions,
      idToken,
      ...settings,
    },
  });
zachtball commented 9 months ago

try setting sendExtraMessageFields to true. works for us with v2.2.35

Hey thanks for the reply, sadly that did not work for me.

jakepgoldman commented 7 months ago

This is an issue for me in 3.0.23. Any resolution? body is not dynamic.

jakepgoldman commented 7 months ago

This is an issue for me in 3.0.23. Any resolution? body is not dynamic.

lgrammel commented 3 months ago

You can send in the body in handleSubmit if it's dynamic: https://sdk.vercel.ai/docs/ai-sdk-ui/chatbot#setting-custom-body-fields-per-request