ai icon indicating copy to clipboard operation
ai copied to clipboard

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

Open zachtball opened this issue 1 year ago • 4 comments

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

zachtball avatar Feb 09 '24 00:02 zachtball

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,
    },
  });

rollsrobby avatar Feb 14 '24 07:02 rollsrobby

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

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

zachtball avatar Feb 14 '24 22:02 zachtball

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

jakepgoldman avatar Apr 18 '24 15:04 jakepgoldman

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

jakepgoldman avatar Apr 18 '24 15:04 jakepgoldman

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

lgrammel avatar Aug 08 '24 14:08 lgrammel