vercel / ai

Build AI-powered applications with React, Svelte, Vue, and Solid
https://sdk.vercel.ai/docs
Other
10.18k stars 1.53k forks source link

Type-safe body for useCompletion etc. #3838

Open umstek opened 10 hours ago

umstek commented 10 hours ago

Feature Description

When calling the complete method returned by useCompletion (etc.), we can pass our own data like so:

  const {
    complete,
    completion,
    error,
    isLoading,
  } = useCompletion({
    api: `${config.baseURL}/ai/completion`,
  });
await complete(promptText, { body: { model: 'fast' } });

Currently, useCompletion doesn't accept type arguments. If it did, we could've made the body passed to complete type safe.

Use Cases

This would help us avoid mistakes.

Additional context

This is definitely not a high priority, but I believe it is a nice to have.