UNPKG

phind-ai-provider

Version:

phind ai provider compatible with vercel ai sdk

83 lines (82 loc) 3.02 kB
import { LanguageModelV1 } from '@ai-sdk/provider'; /** * Service for communicating with the Phind AI API. * Implements the LanguageModelV1 interface from the AI SDK. */ export declare class PhindAIService implements LanguageModelV1 { readonly specificationVersion = "v1"; readonly defaultObjectGenerationMode = "json"; readonly supportsImageUrls = false; readonly supportsStructuredOutputs = false; readonly modelId: string; private static readonly API_URL; private readonly headers; /** * @param model Model identifier (e.g., 'Phind-70B') */ constructor(model?: string); /** Name of this service provider */ get provider(): string; /** * Convert SDK prompt (string or message array) into API-compatible format. * @param prompt Prompt to normalize * @returns Array of message objects with role and content */ private _normalizeMessages; /** * Generate text synchronously (full) using the API. * @param options Generation options (prompt, settings, etc.) */ doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>; /** * Stream text generation from the API. * @param options Generation options (prompt, settings, etc.) * @returns Stream of text parts */ doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doStream']>>>; /** * Execute a chat request and return the complete response text. * @param messages Message history * @returns Full text returned by the API */ chat(messages: { role: string; content: string; }[]): Promise<string>; /** * Execute a chat request in streaming mode and return a reader. * @param messages Message history * @returns Reader for the response stream */ chatReader(messages: { role: string; content: string; }[]): Promise<ReadableStreamDefaultReader>; /** * Async generator yielding chunks from the chat stream. * @param messages Message history */ chatStream(messages: { role: string; content: string; }[]): AsyncGenerator<string>; /** * Maps raw stream data using the provided mapResponse function. * @param reader Raw stream reader * @param mapResponse Function to map SSE lines to text * @returns Reader for the mapped stream */ streamMapResponse(reader: ReadableStreamDefaultReader, mapResponse: (lines: string[]) => string): Promise<ReadableStreamDefaultReader>; /** * Send chat request to the API and return the raw Response object. * @param messageHistory Chat message history for the payload * @throws Error on HTTP failure */ private _fetchChatResponse; /** * Build the final text output from SSE lines. * @param lines SSE event lines * @returns Parsed text content */ private _mapResponse; }