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

Add a setData Function to useCompletion #4538

Open
marnelram opened this issue Jan 27, 2025 · 0 comments
Open

Add a setData Function to useCompletion #4538

marnelram opened this issue Jan 27, 2025 · 0 comments
Labels
ai/ui enhancement New feature or request

Comments

@marnelram
Copy link

Feature Description

The useCompletion hook currently provides access to provider metadata by streaming it through the data field and onMessageAnnotation callback, but doesn't allow the data to be modified on the front-end. This feature would allow the data to be cleared if the user makes another completion request.

An example implementation:

  const {
    completion: researchOutput,
    data: citations,
    setData: setCitations,
    complete: research,
    isLoading: isResearching,
  } = useCompletion({
    api: "/api/perplexityTest"
  });

Use Cases

Use Case

  1. Clean State Between Completions

    • Clearing accumulated metadata before starting new completions
    • Resetting citation lists for new research queries
    • Ensuring stale data doesn't persist between different user sessions
  2. Error Recovery

    • Clearing invalid or partial data after failed completions
    • Resetting to a known state when handling errors

Additional context

Current Workaround is setting citations in a separate state variable

const [citations, setCitations] = useState<string[] | undefined>(undefined);
  const {
    completion: researchOutput,
    data: researchData,
    complete: research,
    isLoading: isResearching,
  } = useCompletion({
    api: "/api/perplexityTest",
    onFinish: (completion) => {
      setCitations(researchData as string[]);
    },
  });
@marnelram marnelram added the enhancement New feature or request label Jan 27, 2025
@lgrammel lgrammel added the ai/ui label Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai/ui enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants