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

feature(core/react/use-chat handleSubmit): Make event parameter optional in handleSubmit to improve robustness #1688

Conversation

fribble186
Copy link

if e in the handleSubmit method were an optional parameter, this function would become more flexible
example:

import { useChat } from "ai/react";

const Index = () => {
  const { input, handleInputChange, handleSubmit } = useChat();
  const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
    if (e.key === "Enter") {
      e.preventDefault();
      console.log("Enter");
      handleSubmit();
    }
  };
  return (
    <div>
      <input onChange={handleInputChange} value={input} onKeyDown={handleKeyDown}/>
      <button onClick={handleSubmit}>send</button>
    </div>
  );
};
export default Index;

@lgrammel
Copy link
Collaborator

lgrammel commented Jun 3, 2024

I like this PR. However, it needs to be changed for all ui frameworks (vue, svelte, solid) and potentially for useCompletion as well.

@fribble186
Copy link
Author

I like this PR. However, it needs to be changed for all ui frameworks (vue, svelte, solid) and potentially for useCompletion as well.

I will take the time to make changes to the points mentioned.

@fribble186 fribble186 force-pushed the feature/imporve-usechat-handlesubmit-event-handle branch from 314fc0c to 6e17dda Compare June 7, 2024 02:16
@fribble186
Copy link
Author

fribble186 commented Jun 7, 2024

I like this PR. However, it needs to be changed for all ui frameworks (vue, svelte, solid) and potentially for useCompletion as well.

Thank you for your feedback!

I have made the requested changes and updated the implementation for all UI frameworks (Vue, Svelte, Solid) and also for useCompletion. Please review the updated PR and let me know if there are any further adjustments needed.

Additionally, while making these changes, I noticed an issue: the handleSubmit method returned by the useChat hook in React includes a metadata parameter, but the handleSubmit definition in the UseChatHelpers type does not include this parameter. It seems there is an inconsistency in the type definitions. Could you please confirm if this is an issue that needs to be addressed? @lgrammel

Thanks again!

@lgrammel lgrammel self-assigned this Jun 7, 2024
@lgrammel
Copy link
Collaborator

Superseeded by #2073

@lgrammel lgrammel closed this Jun 24, 2024
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

Successfully merging this pull request may close these issues.

2 participants