UNPKG

@arizeai/phoenix-client

Version:

A client for the Phoenix API

55 lines 1.74 kB
import { assertUnreachable } from "../../utils/assertUnreachable.js"; import { toAI } from "./toAI.js"; import { toAnthropic } from "./toAnthropic.js"; import { toOpenAI } from "./toOpenAI.js"; import invariant from "tiny-invariant"; /** * Map of SDK names to their corresponding conversion functions */ export const PROVIDER_TO_SDK = { openai: toOpenAI, anthropic: toAnthropic, ai: toAI, }; /** * Get the conversion function for a specific SDK name */ const getTargetSDK = (sdk) => { switch (sdk) { case "openai": return PROVIDER_TO_SDK.openai; case "anthropic": return PROVIDER_TO_SDK.anthropic; case "ai": return PROVIDER_TO_SDK.ai; default: assertUnreachable(sdk); } }; /** * 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 const toSDK = ({ sdk: _sdk, ...rest }) => { const sdk = getTargetSDK(_sdk); invariant(sdk, `No SDK found for provider ${_sdk}`); return sdk(rest); }; //# sourceMappingURL=toSDK.js.map