UNPKG

@axflow/models

Version:

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

127 lines (125 loc) 6.18 kB
declare namespace AnthropicCompletionTypes { export type Request = { model: string; prompt: string; max_tokens_to_sample: number; stop_sequences?: string[]; temperature?: number; top_p?: number; top_k?: number; metadata?: Record<any, string>; }; export type RequestOptions = { apiKey?: string; apiUrl?: string; version?: string; fetch?: typeof fetch; headers?: Record<string, string>; signal?: AbortSignal; }; type Completion = { model: string; completion: string; stop_reason: string | null; stop: string | null; log_id: string; }; export type Response = Completion; export type CompletionEvent = { event: 'completion'; data: Completion; }; export type PingEvent = { event: 'ping'; data: {}; }; export type ErrorEvent = { event: 'error'; data: { error: { type: string; message: string; }; }; }; export type Chunk = CompletionEvent | PingEvent | ErrorEvent; export type Events = 'completion' | 'ping' | 'error'; export {}; } /** * Run a completion against the Anthropic API. * * @see https://docs.anthropic.com/claude/reference/complete_post * * @param request The request body sent to Anthropic. See Anthropic's documentation for /v1/complete for supported parameters. * @param options * @param options.apiKey Anthropic API key. * @param options.apiUrl The url of the Anthropic (or compatible) API. Defaults to https://api.anthropic.com/v1/complete. * @param options.version The Anthropic API version. Defaults to 2023-06-01. Note that older versions are not currently supported. * @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 Anthropic completion. See Anthropic's documentation for /v1/complete. */ declare function run(request: AnthropicCompletionTypes.Request, options: AnthropicCompletionTypes.RequestOptions): Promise<AnthropicCompletionTypes.Response>; /** * Run a streaming completion against the Anthropic API. The resulting stream is the raw unmodified bytes from the API. * * @see https://docs.anthropic.com/claude/reference/complete_post * @see https://docs.anthropic.com/claude/reference/streaming * * @param request The request body sent to Anthropic. See Anthropic's documentation for /v1/complete for supported parameters. * @param options * @param options.apiKey Anthropic API key. * @param options.apiUrl The url of the Anthropic (or compatible) API. Defaults to https://api.anthropic.com/v1/complete. * @param options.version The Anthropic API version. Defaults to 2023-06-01. Note that older versions are not currently supported. * @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: AnthropicCompletionTypes.Request, options: AnthropicCompletionTypes.RequestOptions): Promise<ReadableStream<Uint8Array>>; /** * Run a streaming completion against the Anthropic API. The resulting stream is the parsed stream data as JavaScript objects. * * @see https://docs.anthropic.com/claude/reference/complete_post * @see https://docs.anthropic.com/claude/reference/streaming * * @param request The request body sent to Anthropic. See Anthropic's documentation for /v1/complete for supported parameters. * @param options * @param options.apiKey Anthropic API key. * @param options.apiUrl The url of the Anthropic (or compatible) API. Defaults to https://api.anthropic.com/v1/complete. * @param options.version The Anthropic API version. Defaults to 2023-06-01. Note that older versions are not currently supported. * @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: AnthropicCompletionTypes.Request, options: AnthropicCompletionTypes.RequestOptions): Promise<ReadableStream<AnthropicCompletionTypes.Chunk>>; /** * Run a streaming completion against the Anthropic API. The resulting stream emits only the string tokens. * * @see https://docs.anthropic.com/claude/reference/complete_post * @see https://docs.anthropic.com/claude/reference/streaming * * @param request The request body sent to Anthropic. See Anthropic's documentation for /v1/complete for supported parameters. * @param options * @param options.apiKey Anthropic API key. * @param options.apiUrl The url of the Anthropic (or compatible) API. Defaults to https://api.anthropic.com/v1/complete. * @param options.version The Anthropic API version. Defaults to 2023-06-01. Note that older versions are not currently supported. * @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: AnthropicCompletionTypes.Request, options: AnthropicCompletionTypes.RequestOptions): Promise<ReadableStream<string>>; /** * An object that encapsulates methods for calling the Anthropic Completion API. */ declare class AnthropicCompletion { static run: typeof run; static stream: typeof stream; static streamBytes: typeof streamBytes; static streamTokens: typeof streamTokens; } export { AnthropicCompletion, AnthropicCompletionTypes };