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

Append for useAssistant #1393

Closed
AlexIsMaking opened this issue Apr 19, 2024 · 7 comments
Closed

Append for useAssistant #1393

AlexIsMaking opened this issue Apr 19, 2024 · 7 comments
Assignees

Comments

@AlexIsMaking
Copy link

AlexIsMaking commented Apr 19, 2024

Feature Description

I've just switched to useAssistant and the function that I'm missing the most is the append function that's available for useChat.

My hacky workaround is to set the input using setInput and then trigger submitMessage once the input has been set. This doesn't look great to the user.

Use Case

I'm displaying buttons in my UI which will insert prompts, to start new conversations. I need to send the prompt to OpenAI when it's submitted.

@lgrammel lgrammel self-assigned this Apr 22, 2024
@lgrammel
Copy link
Collaborator

#1407

@lgrammel
Copy link
Collaborator

Available in v3.0.25

@AlexIsMaking
Copy link
Author

AlexIsMaking commented Apr 23, 2024

@lgrammel really grateful for the quick implementation here. When I use append, the status helper variable isn't set to in_progress though, is that expected behaviour?

At the moment, I'm relying on that status changing to trigger storage of user & assistant messages, since useAssistant doesn't have useChat's onFinish callback option.

@lgrammel
Copy link
Collaborator

@AlexIsMaking thanks for letting me know. it seems i dropped it by accident during the change

@lgrammel
Copy link
Collaborator

#1423

@brian-yates
Copy link

brian-yates commented Apr 30, 2024

Hello - I have a question and possible bug regarding the append function in the useAssistant hook. It seems that calling append will add a message to the messages property (e.g. setMessages(prev => [...prev, newMessage])), but it calls the API endpoint with whatever the current input value is, regardless of what you called append with.

I would expect that calling append would call the API with the respective appended message content.

For additional context, I am adding prompts to the chat form that a user can click which would automatically send a message with the prompt content, rather than having to manually type out the message...and it seems like append is the perfect method to do this...it just doesn't work like I would expect.

Is this a bug or is it expected behavior?

Edit: this seems to be fixed...just had to upgrade to ai version 3.1.0

@saintpepsicola
Copy link

Thanks. I just ran into the bug lol @brian-yates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants