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

appendResponseMessages function Type error #4772

Closed
tsuzaki430 opened this issue Feb 8, 2025 · 2 comments
Closed

appendResponseMessages function Type error #4772

tsuzaki430 opened this issue Feb 8, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@tsuzaki430
Copy link

tsuzaki430 commented Feb 8, 2025

Description

Hi , thank you for using ai sdk, I feel good DX developing generative AI application.

I use appendResponseMessages function because of convert ResponseMessage to Message.
When I tried upgrade ai version 4.1.5 to 4.1.25 , I met the error.
I tried serveral versions.
[email protected] - @ai4.1.11 works expectedly.
But [email protected] - ai@latest(4.1.25) those message happens.
PR #4670 may depends about it.

it happens streamText onFinish happens error (not Linter error).

unhandledRejection:  TypeError: Cannot read properties of undefined (reading 'role') at onFinish 
 ⨯ unhandledRejection:  TypeError: Cannot read properties of undefined (reading 'role')
    at onFinish (src\app\api\aichat\general\route.ts:241:52)
  239 |             // responseにAIからの回答messages:Message[]が入っている
  240 |             // const uiMessages=convertToUIMessages(response.messages as Message[])
> 241 |             const uiMessages=appendResponseMessages({
      |                                                    ^
  242 |               messages:[] as Message[],
  243 |               responseMessages:response.messages,
  244 |             });

The parameter messages is empty array because I need the response only.

const uiMessages=appendResponseMessages({
  messages:[] as Message[],
  responseMessages:response.messages,
});

I hope this issue will be useful.

Code example

No response

AI provider

@ai-sdk/azure 1.1.9

Additional context

No response

@tsuzaki430 tsuzaki430 added the bug Something isn't working label Feb 8, 2025
@lgrammel
Copy link
Collaborator

lgrammel commented Feb 8, 2025

@tsuzaki430 you need to provide the input messages to appendResponseMessages. We reconcile messages and it may be that the last message gets modified (no new message added).

@tsuzaki430
Copy link
Author

@lgrammel Thank you for response and I fixed my code and this issue has solved.
I close this issue and thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants