@ai-sdk/vue
Version:
[Vue.js](https://vuejs.org/) UI components for the [AI SDK](https://ai-sdk.dev/docs):
46 lines (42 loc) • 1.67 kB
TypeScript
import { CompletionRequestOptions, UseCompletionOptions, UIMessage, AbstractChat, ChatInit } from 'ai';
export { UseCompletionOptions } from 'ai';
import { Ref } from 'vue';
type UseCompletionHelpers = {
/** The current completion result */
completion: Ref<string>;
/** The error object of the API request */
error: Ref<undefined | Error>;
/**
* Send a new prompt to the API endpoint and update the completion state.
*/
complete: (prompt: string, options?: CompletionRequestOptions) => Promise<string | null | undefined>;
/**
* Abort the current API request but keep the generated tokens.
*/
stop: () => void;
/**
* Update the `completion` state locally.
*/
setCompletion: (completion: string) => void;
/** The current value of the input */
input: Ref<string>;
/**
* Form submission handler to automatically reset input and append a user message
* @example
* ```jsx
* <form @submit="handleSubmit">
* <input @change="handleInputChange" v-model="input" />
* </form>
* ```
*/
handleSubmit: (event?: {
preventDefault?: () => void;
}) => void;
/** Whether the API request is in progress */
isLoading: Ref<boolean | undefined>;
};
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, streamProtocol, onFinish, onError, fetch, }?: UseCompletionOptions): UseCompletionHelpers;
declare class Chat<UI_MESSAGE extends UIMessage> extends AbstractChat<UI_MESSAGE> {
constructor({ messages, ...init }: ChatInit<UI_MESSAGE>);
}
export { Chat, UseCompletionHelpers, useCompletion };