@arizeai/phoenix-client
Version:
A client for the Phoenix API
57 lines • 2.48 kB
TypeScript
import { SupportedSDK, toSDKParamsBase, Variables } from "./types";
/**
* Parameters for an SDK conversion function
*
* @example
* ```ts
* const params: SDKParams<"openai"> = { ... }
* toOpenAI(params)
* ```
*/
export type SDKParams<T extends SupportedSDK> = Parameters<(typeof PROVIDER_TO_SDK)[T]>[number] extends toSDKParamsBase ? Parameters<(typeof PROVIDER_TO_SDK)[T]>[number] : never;
/**
* Map of SDK names to their corresponding conversion functions
*/
export declare const PROVIDER_TO_SDK: {
openai: <V extends Variables = Variables>({ prompt, variables, }: import("./toOpenAI").ToOpenAIParams<V>) => import("openai/resources/chat/completions/completions.js").ChatCompletionCreateParams | null;
anthropic: <V extends Variables = Variables>({ prompt, variables, }: import("./toAnthropic").ToAnthropicParams<V>) => import("@anthropic-ai/sdk/resources/messages/messages.mjs").MessageCreateParams | null;
ai: <V extends Variables>({ prompt, variables, }: import("./toAI").ToAIParams<V>) => import("./toAI").PartialAIParams | null;
};
/**
* Parameters specific to the toSDK function
*/
export type ToSDKParams<T extends SupportedSDK, V extends Variables = Variables> = {
/**
* String representing the SDK to convert to
*/
sdk: T;
/**
* Optional variables to format the prompt with
* Keys are the variable names, values are the variable values
* The variable format is determined via prompt.template_format
*/
variables?: V;
};
/**
* Convert a Phoenix prompt to a specific SDK's parameters
*
* @example quickstart
* ```ts
* // Get a prompt from Phoenix, use it via openai sdk
* const prompt = await getPrompt({ prompt: { name: "my-prompt" } });
* const openaiParams = toSDK({ sdk: "openai", prompt });
* const response = await openai.chat.completions.create(openaiParams);
* ```
*
* @example type safety
* ```ts
* // Enforce variable types via Generic argument
* const prompt = await getPrompt({ prompt: { name: "my-prompt" } });
* const openaiParams = toSDK<"openai", { name: string }>({ sdk: "openai", prompt, variables: { name: "John" } });
* ```
*
* @param params - The parameters to convert a prompt to an SDK's parameters
* @returns The SDK's parameters
*/
export declare const toSDK: <T extends SupportedSDK, V extends Variables = Variables>({ sdk: _sdk, ...rest }: ToSDKParams<T, V> & SDKParams<T>) => ReturnType<(typeof PROVIDER_TO_SDK)[T]>;
//# sourceMappingURL=toSDK.d.ts.map