@arizeai/phoenix-client
Version:
A client for the Phoenix API
60 lines • 2.21 kB
TypeScript
import { toAI } from "./toAI";
import { toAnthropic } from "./toAnthropic";
import { toOpenAI } from "./toOpenAI";
import type { SupportedSDK, toSDKParamsBase, Variables } from "./types";
/**
* Parameters for an SDK conversion function
*
* @example
* ```ts
* const params: SDKParams<"openai"> = { ... }
* toOpenAI(params)
* ```
*/
export type SDKParams<SDK extends SupportedSDK> = Parameters<(typeof PROVIDER_TO_SDK)[SDK]>[number] extends toSDKParamsBase ? Parameters<(typeof PROVIDER_TO_SDK)[SDK]>[number] : never;
/**
* Map of SDK names to their corresponding conversion functions
*/
export declare const PROVIDER_TO_SDK: {
openai: typeof toOpenAI;
anthropic: typeof toAnthropic;
ai: typeof toAI;
};
/**
* Parameters specific to the toSDK function
*/
export type ToSDKParams<SDK extends SupportedSDK, PromptVariables extends Variables = Variables> = {
/**
* String representing the SDK to convert to
*/
sdk: SDK;
/**
* 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?: PromptVariables;
};
/**
* 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: <SDK extends SupportedSDK, PromptVariables extends Variables = Variables>({ sdk: _sdk, ...rest }: ToSDKParams<SDK, PromptVariables> & SDKParams<SDK>) => ReturnType<(typeof PROVIDER_TO_SDK)[SDK]>;
//# sourceMappingURL=toSDK.d.ts.map