UNPKG

@flavoai/fastfold

Version:

Flavo frontend package

221 lines 6.27 kB
/** * FastFold AI Client Hooks * React hooks for AI functionality with streaming support */ export interface AIMessage { role: 'system' | 'user' | 'assistant'; content: string; } export interface AIChatOptions { /** API endpoint (default: /api/ai/chat) */ api?: string; /** AI model to use */ model?: string; /** AI provider (openai, anthropic, google) */ provider?: string; /** System prompt */ system?: string; /** Temperature (0-2) */ temperature?: number; /** Max tokens */ maxTokens?: number; /** Initial messages */ initialMessages?: AIMessage[]; /** Callback when streaming chunk received */ onChunk?: (chunk: string) => void; /** Callback when generation completes */ onFinish?: (response: AIChatResponse) => void; /** Callback on error */ onError?: (error: Error) => void; } export interface AIChatResponse { text: string; finishReason?: string; usage?: { promptTokens: number; completionTokens: number; totalTokens: number; }; } export interface AIObjectOptions<T = any> { /** API endpoint (default: /api/ai/generate) */ api?: string; /** JSON schema for structured output */ schema: Record<string, any>; /** AI model to use */ model?: string; /** AI provider */ provider?: string; /** Temperature */ temperature?: number; /** Max tokens */ maxTokens?: number; /** System prompt */ system?: string; /** Callback when generation completes */ onFinish?: (object: T) => void; /** Callback on error */ onError?: (error: Error) => void; } export interface AIEmbedOptions { /** API endpoint (default: /api/ai/embed) */ api?: string; /** Embedding model */ model?: string; /** AI provider */ provider?: string; } export interface AIStreamOptions { /** API endpoint (default: /api/ai/stream) */ api?: string; /** AI model to use */ model?: string; /** AI provider */ provider?: string; /** System prompt */ system?: string; /** Temperature */ temperature?: number; /** Max tokens */ maxTokens?: number; /** Callback when streaming chunk received */ onChunk?: (chunk: string) => void; /** Callback when streaming completes */ onFinish?: (text: string) => void; /** Callback on error */ onError?: (error: Error) => void; } export declare function configureAIClient(config: { baseUrl?: string; }): void; /** * 💬 useAIChat - Chat with AI with streaming support * * @example * const { messages, input, handleSubmit, isLoading, setInput } = useAIChat({ * api: '/api/ai/chat', * system: 'You are a helpful assistant', * onFinish: (response) => console.log('Done:', response), * }); * * // In your component: * <form onSubmit={handleSubmit}> * <input value={input} onChange={(e) => setInput(e.target.value)} /> * <button type="submit" disabled={isLoading}>Send</button> * </form> * {messages.map((m, i) => <div key={i}>{m.role}: {m.content}</div>)} */ export declare function useAIChat(options?: AIChatOptions): { messages: AIMessage[]; input: string; setInput: import("react").Dispatch<import("react").SetStateAction<string>>; handleSubmit: (e?: React.FormEvent) => Promise<void>; append: (message: AIMessage) => Promise<AIChatResponse | null>; reload: () => Promise<void>; stop: () => void; clear: () => void; isLoading: boolean; error: Error | null; }; /** * 🌊 useAIStream - Stream text generation with SSE * * @example * const { text, isStreaming, generate, stop } = useAIStream({ * api: '/api/ai/stream', * onChunk: (chunk) => console.log('Chunk:', chunk), * onFinish: (text) => console.log('Final:', text), * }); * * // Start streaming * await generate({ prompt: 'Tell me a story' }); */ export declare function useAIStream(options?: AIStreamOptions): { text: string; isStreaming: boolean; error: Error | null; generate: (params: { prompt?: string; messages?: AIMessage[]; }) => Promise<string>; stop: () => void; clear: () => void; }; /** * 🎯 useAIObject - Generate structured objects with AI * * @example * const { object, generate, isLoading, error } = useAIObject({ * schema: { * type: 'object', * properties: { * name: { type: 'string' }, * age: { type: 'number' }, * }, * required: ['name', 'age'], * }, * onFinish: (obj) => console.log('Generated:', obj), * }); * * // Generate object * await generate({ prompt: 'Generate a random person' }); */ export declare function useAIObject<T = any>(options: AIObjectOptions<T>): { object: T | null; isLoading: boolean; error: Error | null; generate: (params: { prompt?: string; messages?: AIMessage[]; }) => Promise<T>; clear: () => void; }; /** * ✍️ useAICompletion - Simple text completion * * @example * const { text, complete, isLoading } = useAICompletion({ * model: 'gpt-4o', * }); * * const result = await complete('Translate to French: Hello world'); */ export declare function useAICompletion(options?: { api?: string; model?: string; provider?: string; temperature?: number; maxTokens?: number; onFinish?: (text: string) => void; onError?: (error: Error) => void; }): { text: string; isLoading: boolean; error: Error | null; complete: (prompt: string) => Promise<string>; clear: () => void; }; /** * 🔢 useAIEmbed - Generate embeddings * * @example * const { embed, embedMany, isLoading } = useAIEmbed(); * * const embedding = await embed('Hello world'); * const embeddings = await embedMany(['Hello', 'World']); */ export declare function useAIEmbed(options?: AIEmbedOptions): { isLoading: boolean; error: Error | null; embed: (text: string) => Promise<number[]>; embedMany: (texts: string[]) => Promise<number[][]>; }; declare const _default: { useAIChat: typeof useAIChat; useAIStream: typeof useAIStream; useAIObject: typeof useAIObject; useAICompletion: typeof useAICompletion; useAIEmbed: typeof useAIEmbed; }; export default _default; //# sourceMappingURL=ai.d.ts.map