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

Allow submitting form without adding a message in useChat hook #167

Open
lesleh opened this issue Jun 20, 2023 · 8 comments
Open

Allow submitting form without adding a message in useChat hook #167

lesleh opened this issue Jun 20, 2023 · 8 comments
Labels
enhancement New feature or request

Comments

@lesleh
Copy link

lesleh commented Jun 20, 2023

Currently we do nothing if no text is input in the form - https://github.com/vercel-labs/ai/blob/fd69e9a5628d1cd21a7c4a36584b4c577e0cc0a6/packages/core/react/use-chat.ts#L253

But, submitting a new API request without adding a new user message is a good way to get the LLM to continue its previous response, for example if the user hit stop, or the previous response reached the token limit. This is how the OpenAI playground works.

@shuding shuding added the enhancement New feature or request label Jun 20, 2023
@MaxLeiter
Copy link
Member

Can you use reload? https://sdk.vercel.ai/docs/api-reference/use-chat

@lesleh
Copy link
Author

lesleh commented Jun 20, 2023

@MaxLeiter unfortunately not, reload works differently. Instead of adding another assistant response, it removes the last assistant response and requests a new one. So you couldn't use it to make the hook request another assistant message without providing an additional user message.

@shuding
Copy link
Member

shuding commented Jun 21, 2023

I think you can call append manually with role set to 'assistant'?

@lesleh
Copy link
Author

lesleh commented Jun 22, 2023

@shuding I don't believe so, append looks like it's more for adding a message with content you already have, not asking for a new message to be generated.

@shuding
Copy link
Member

shuding commented Jun 23, 2023

It seems like we need a new option in reload to explicitly send a request without removing the last assistant response. For example reload({ removeLastAssistantMessage: true }). Need a better name though.

@pomber
Copy link

pomber commented Jun 26, 2023

It seems like we need a new option in reload to explicitly send a request without removing the last assistant response. For example reload({ removeLastAssistantMessage: true }). Need a better name though.

Maybe even more flexibility? reload(messages => transformTheMessagesBeforeSendingThem(messages))

I need this so I can modify the last user message before reloading.

@shuding
Copy link
Member

shuding commented Jun 29, 2023

Love the idea from @pomber, vote for this:

reload({
  transform: (messages) => newMessages
})

So we can have other options added in the future. PR welcome!

@prashantbhudwal
Copy link

@shuding Raised PR. #989

#989

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

No branches or pull requests

5 participants