UNPKG

@axflow/models

Version:

Zero-dependency, modular SDK for building robust natural language applications

135 lines (133 loc) 5.96 kB
declare namespace GoogleGenerateContentTypes { type RequestOptions = { apiKey?: string; apiUrl?: string; fetch?: typeof fetch; headers?: Record<string, string>; signal?: AbortSignal; }; type Part = { text?: string; inlineData?: { data: string; mimeType: string; }; }; type Content = { role?: 'user' | 'model'; parts: Part[]; }; type Request = { model: string; contents: Content[]; generationConfig?: { temperature?: number; stopSequences?: string[]; candidateCount?: number; maxOutputTokens?: number; topP?: number; topK?: number; }; safetySettings?: Array<{ category: string; threshold: string; }>; }; type SafetyReason = { category: string; probability: string; blocked?: boolean; }; type Response = { candidates: Array<{ index: number; content: Content; finishReason?: string; tokenCount?: number; safetyRatings: SafetyReason[]; citationMetadata?: { citationSources: Array<{ uri?: string; startIndex?: number; endIndex?: number; license?: string; }>; }; }>; promptFeedback?: { blockReason?: string; safetyRatings: SafetyReason[]; }; }; type Chunk = Response; } /** * Run a prediction against Google's generate content API. * * @see https://ai.google.dev/api/rest/v1/models/generateContent * * @param request The request body sent to Google. See https://ai.google.dev/api/rest/v1/models/generateContent * @param options * @param options.apiKey Google AI API key. * @param options.apiUrl The url of the Google generate content (or compatible) API. Defaults to https://generativelanguage.googleapis.com/v1. * @param options.fetch A custom implementation of fetch. Defaults to globalThis.fetch. * @param options.headers Optionally add additional HTTP headers to the request. * @param options.signal An AbortSignal that can be used to abort the fetch request. * @returns Google generate content response. See https://ai.google.dev/api/rest/v1/models/generateContent. */ declare function run(request: GoogleGenerateContentTypes.Request, options: GoogleGenerateContentTypes.RequestOptions): Promise<GoogleGenerateContentTypes.Response>; /** * Run a streaming prediction against Google's generate content API. * * @see https://ai.google.dev/api/rest/v1/models/streamGenerateContent * * @param request The request body sent to Google. See https://ai.google.dev/api/rest/v1/models/streamGenerateContent. * @param options * @param options.apiKey Google AI API key. * @param options.apiUrl The url of the Google generate content (or compatible) API. Defaults to https://generativelanguage.googleapis.com/v1. * @param options.fetch A custom implementation of fetch. Defaults to globalThis.fetch. * @param options.headers Optionally add additional HTTP headers to the request. * @param options.signal An AbortSignal that can be used to abort the fetch request. * @returns A stream of bytes directly from the API. */ declare function streamBytes(request: GoogleGenerateContentTypes.Request, options: GoogleGenerateContentTypes.RequestOptions): Promise<ReadableStream<Uint8Array>>; /** * Run a streaming prediction against Google's generate content API. The resulting stream is the parsed stream data as JavaScript objects. * * @see https://ai.google.dev/api/rest/v1/models/streamGenerateContent * * @param request The request body sent to Google. See https://ai.google.dev/api/rest/v1/models/streamGenerateContent. * @param options * @param options.apiKey Google AI API key. * @param options.apiUrl The url of the Google generate content (or compatible) API. Defaults to https://generativelanguage.googleapis.com/v1. * @param options.fetch A custom implementation of fetch. Defaults to globalThis.fetch. * @param options.headers Optionally add additional HTTP headers to the request. * @param options.signal An AbortSignal that can be used to abort the fetch request. * @returns A stream of objects representing each chunk from the API. */ declare function stream(request: GoogleGenerateContentTypes.Request, options: GoogleGenerateContentTypes.RequestOptions): Promise<ReadableStream<GoogleGenerateContentTypes.Chunk>>; /** * Run a streaming prediction against Google's generate content API. The resulting stream emits only the string tokens. * * @see https://ai.google.dev/api/rest/v1/models/streamGenerateContent * * @param request The request body sent to Google. See https://ai.google.dev/api/rest/v1/models/streamGenerateContent. * @param options * @param options.apiKey Google AI API key. * @param options.apiUrl The url of the Google generate content (or compatible) API. Defaults to https://generativelanguage.googleapis.com/v1. * @param options.fetch A custom implementation of fetch. Defaults to globalThis.fetch. * @param options.headers Optionally add additional HTTP headers to the request. * @param options.signal An AbortSignal that can be used to abort the fetch request. * @returns A stream of tokens from the API. */ declare function streamTokens(request: GoogleGenerateContentTypes.Request, options: GoogleGenerateContentTypes.RequestOptions): Promise<ReadableStream<string>>; /** * An object that encapsulates methods for calling Google AI's generate content APIs. */ declare class GoogleGenerateContent { static run: typeof run; static streamBytes: typeof streamBytes; static stream: typeof stream; static streamTokens: typeof streamTokens; } export { GoogleGenerateContent, GoogleGenerateContentTypes };