UNPKG

askexperts

Version:

AskExperts SDK: build and use AI experts - ask them questions and pay with bitcoin on an open protocol

59 lines (58 loc) 2.2 kB
import { APIPromise } from "openai"; import { ChatCompletionCreateParams, ChatCompletion, ChatCompletionChunk } from "openai/resources/chat/completions"; import { PricingResult } from "../experts/utils/ModelPricing.js"; import { OpenRouter } from "../experts/utils/OpenRouter.js"; import { LightningPaymentManager } from "../payments/LightningPaymentManager.js"; import { SimplePool } from "nostr-tools"; export * from "./OpenaiOpenRouter.js"; export * from "./OpenaiAskExperts.js"; /** * Interface that matches the OpenAI chat completions API * This allows for dependency injection and easier testing */ export interface OpenaiInterface { /** * Execute a chat completion request * * @param quoteId - Quote ID for the request * @param options - Additional options for the request * @returns Promise resolving to chat completion or chunks */ execute(quoteId: string, options?: any): APIPromise<ChatCompletion> | APIPromise<AsyncIterable<ChatCompletionChunk>>; /** * Gets pricing information for a model in sats per million tokens * * @param model - Model ID * @returns Promise resolving to pricing information or undefined if not available */ pricing(model: string): Promise<PricingResult | undefined>; /** * Estimates the price of processing a prompt * * @param model - Model ID * @param content - The chat completion parameters * @returns Promise resolving to the estimated price object */ getQuote(model: string, content: ChatCompletionCreateParams): Promise<{ amountSats: number; quoteId: string; }>; } /** * Creates an OpenAI instance that implements OpenaiInterface * * @param apiKey - OpenAI API key * @param baseURL - OpenAI base URL * @param defaultHeaders - Optional default headers * @returns OpenAI instance implementing OpenaiInterface */ export declare function createOpenAI(options?: { apiKey?: string; baseURL?: string; defaultHeaders?: Record<string, string>; paymentManager?: LightningPaymentManager; pool?: SimplePool; discoveryRelays?: string[]; margin?: number; openRouter?: OpenRouter; }): OpenaiInterface;