@arizeai/phoenix-client 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +136 -7
- package/dist/esm/__generated__/api/v1.d.ts +743 -12
- package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
- package/dist/esm/client.d.ts +9 -2
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +3 -2
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/config.d.ts.map +1 -1
- package/dist/esm/config.js +11 -1
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/experiments/runExperiment.d.ts +35 -8
- package/dist/esm/experiments/runExperiment.d.ts.map +1 -1
- package/dist/esm/experiments/runExperiment.js +29 -39
- package/dist/esm/experiments/runExperiment.js.map +1 -1
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/prompts/constants.d.ts +6 -0
- package/dist/esm/prompts/constants.d.ts.map +1 -0
- package/dist/esm/prompts/constants.js +10 -0
- package/dist/esm/prompts/constants.js.map +1 -0
- package/dist/esm/prompts/createPrompt.d.ts +65 -0
- package/dist/esm/prompts/createPrompt.d.ts.map +1 -0
- package/dist/esm/prompts/createPrompt.js +95 -0
- package/dist/esm/prompts/createPrompt.js.map +1 -0
- package/dist/esm/prompts/getPrompt.d.ts +16 -0
- package/dist/esm/prompts/getPrompt.d.ts.map +1 -0
- package/dist/esm/prompts/getPrompt.js +11 -0
- package/dist/esm/prompts/getPrompt.js.map +1 -0
- package/dist/esm/prompts/index.d.ts +4 -0
- package/dist/esm/prompts/index.d.ts.map +1 -0
- package/dist/esm/prompts/index.js +4 -0
- package/dist/esm/prompts/index.js.map +1 -0
- package/dist/esm/prompts/sdks/constants.d.ts +6 -0
- package/dist/esm/prompts/sdks/constants.d.ts.map +1 -0
- package/dist/esm/prompts/sdks/constants.js +6 -0
- package/dist/esm/prompts/sdks/constants.js.map +1 -0
- package/dist/esm/prompts/sdks/index.d.ts +2 -0
- package/dist/esm/prompts/sdks/index.d.ts.map +1 -0
- package/dist/esm/prompts/sdks/index.js +2 -0
- package/dist/esm/prompts/sdks/index.js.map +1 -0
- package/dist/esm/prompts/sdks/toAI.d.ts +12 -0
- package/dist/esm/prompts/sdks/toAI.d.ts.map +1 -0
- package/dist/esm/prompts/sdks/toAI.js +70 -0
- package/dist/esm/prompts/sdks/toAI.js.map +1 -0
- package/dist/esm/prompts/sdks/toAnthropic.d.ts +9 -0
- package/dist/esm/prompts/sdks/toAnthropic.d.ts.map +1 -0
- package/dist/esm/prompts/sdks/toAnthropic.js +69 -0
- package/dist/esm/prompts/sdks/toAnthropic.js.map +1 -0
- package/dist/esm/prompts/sdks/toOpenAI.d.ts +11 -0
- package/dist/esm/prompts/sdks/toOpenAI.d.ts.map +1 -0
- package/dist/esm/prompts/sdks/toOpenAI.js +77 -0
- package/dist/esm/prompts/sdks/toOpenAI.js.map +1 -0
- package/dist/esm/prompts/sdks/toSDK.d.ts +47 -0
- package/dist/esm/prompts/sdks/toSDK.d.ts.map +1 -0
- package/dist/esm/prompts/sdks/toSDK.js +44 -0
- package/dist/esm/prompts/sdks/toSDK.js.map +1 -0
- package/dist/esm/prompts/sdks/types.d.ts +28 -0
- package/dist/esm/prompts/sdks/types.d.ts.map +1 -0
- package/dist/esm/prompts/sdks/types.js +2 -0
- package/dist/esm/prompts/sdks/types.js.map +1 -0
- package/dist/esm/schemas/jsonLiteralSchema.d.ts +17 -0
- package/dist/esm/schemas/jsonLiteralSchema.d.ts.map +1 -0
- package/dist/esm/schemas/jsonLiteralSchema.js +16 -0
- package/dist/esm/schemas/jsonLiteralSchema.js.map +1 -0
- package/dist/esm/schemas/jsonSchema.d.ts +132 -0
- package/dist/esm/schemas/jsonSchema.d.ts.map +1 -0
- package/dist/esm/schemas/jsonSchema.js +42 -0
- package/dist/esm/schemas/jsonSchema.js.map +1 -0
- package/dist/esm/schemas/llm/anthropic/converters.d.ts +1497 -0
- package/dist/esm/schemas/llm/anthropic/converters.d.ts.map +1 -0
- package/dist/esm/schemas/llm/anthropic/converters.js +123 -0
- package/dist/esm/schemas/llm/anthropic/converters.js.map +1 -0
- package/dist/esm/schemas/llm/anthropic/messagePartSchemas.d.ts +264 -0
- package/dist/esm/schemas/llm/anthropic/messagePartSchemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/anthropic/messagePartSchemas.js +36 -0
- package/dist/esm/schemas/llm/anthropic/messagePartSchemas.js.map +1 -0
- package/dist/esm/schemas/llm/anthropic/messageSchemas.d.ts +795 -0
- package/dist/esm/schemas/llm/anthropic/messageSchemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/anthropic/messageSchemas.js +23 -0
- package/dist/esm/schemas/llm/anthropic/messageSchemas.js.map +1 -0
- package/dist/esm/schemas/llm/anthropic/toolCallSchemas.d.ts +48 -0
- package/dist/esm/schemas/llm/anthropic/toolCallSchemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/anthropic/toolCallSchemas.js +27 -0
- package/dist/esm/schemas/llm/anthropic/toolCallSchemas.js.map +1 -0
- package/dist/esm/schemas/llm/anthropic/toolChoiceSchemas.d.ts +30 -0
- package/dist/esm/schemas/llm/anthropic/toolChoiceSchemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/anthropic/toolChoiceSchemas.js +19 -0
- package/dist/esm/schemas/llm/anthropic/toolChoiceSchemas.js.map +1 -0
- package/dist/esm/schemas/llm/anthropic/toolSchemas.d.ts +191 -0
- package/dist/esm/schemas/llm/anthropic/toolSchemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/anthropic/toolSchemas.js +31 -0
- package/dist/esm/schemas/llm/anthropic/toolSchemas.js.map +1 -0
- package/dist/esm/schemas/llm/constants.d.ts +7422 -0
- package/dist/esm/schemas/llm/constants.d.ts.map +1 -0
- package/dist/esm/schemas/llm/constants.js +128 -0
- package/dist/esm/schemas/llm/constants.js.map +1 -0
- package/dist/esm/schemas/llm/converters.d.ts +29720 -0
- package/dist/esm/schemas/llm/converters.d.ts.map +1 -0
- package/dist/esm/schemas/llm/converters.js +308 -0
- package/dist/esm/schemas/llm/converters.js.map +1 -0
- package/dist/esm/schemas/llm/openai/converters.d.ts +3507 -0
- package/dist/esm/schemas/llm/openai/converters.d.ts.map +1 -0
- package/dist/esm/schemas/llm/openai/converters.js +311 -0
- package/dist/esm/schemas/llm/openai/converters.js.map +1 -0
- package/dist/esm/schemas/llm/openai/messagePartSchemas.d.ts +64 -0
- package/dist/esm/schemas/llm/openai/messagePartSchemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/openai/messagePartSchemas.js +21 -0
- package/dist/esm/schemas/llm/openai/messagePartSchemas.js.map +1 -0
- package/dist/esm/schemas/llm/openai/messageSchemas.d.ts +733 -0
- package/dist/esm/schemas/llm/openai/messageSchemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/openai/messageSchemas.js +67 -0
- package/dist/esm/schemas/llm/openai/messageSchemas.js.map +1 -0
- package/dist/esm/schemas/llm/openai/responseFormatSchema.d.ts +233 -0
- package/dist/esm/schemas/llm/openai/responseFormatSchema.d.ts.map +1 -0
- package/dist/esm/schemas/llm/openai/responseFormatSchema.js +19 -0
- package/dist/esm/schemas/llm/openai/responseFormatSchema.js.map +1 -0
- package/dist/esm/schemas/llm/openai/toolCallSchemas.d.ts +95 -0
- package/dist/esm/schemas/llm/openai/toolCallSchemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/openai/toolCallSchemas.js +40 -0
- package/dist/esm/schemas/llm/openai/toolCallSchemas.js.map +1 -0
- package/dist/esm/schemas/llm/openai/toolChoiceSchemas.d.ts +28 -0
- package/dist/esm/schemas/llm/openai/toolChoiceSchemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/openai/toolChoiceSchemas.js +16 -0
- package/dist/esm/schemas/llm/openai/toolChoiceSchemas.js.map +1 -0
- package/dist/esm/schemas/llm/openai/toolSchemas.d.ts +1282 -0
- package/dist/esm/schemas/llm/openai/toolSchemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/openai/toolSchemas.js +62 -0
- package/dist/esm/schemas/llm/openai/toolSchemas.js.map +1 -0
- package/dist/esm/schemas/llm/phoenixPrompt/converters.d.ts +847 -0
- package/dist/esm/schemas/llm/phoenixPrompt/converters.d.ts.map +1 -0
- package/dist/esm/schemas/llm/phoenixPrompt/converters.js +130 -0
- package/dist/esm/schemas/llm/phoenixPrompt/converters.js.map +1 -0
- package/dist/esm/schemas/llm/phoenixPrompt/messagePartSchemas.d.ts +128 -0
- package/dist/esm/schemas/llm/phoenixPrompt/messagePartSchemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/phoenixPrompt/messagePartSchemas.js +60 -0
- package/dist/esm/schemas/llm/phoenixPrompt/messagePartSchemas.js.map +1 -0
- package/dist/esm/schemas/llm/phoenixPrompt/messageSchemas.d.ts +196 -0
- package/dist/esm/schemas/llm/phoenixPrompt/messageSchemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/phoenixPrompt/messageSchemas.js +23 -0
- package/dist/esm/schemas/llm/phoenixPrompt/messageSchemas.js.map +1 -0
- package/dist/esm/schemas/llm/phoenixPrompt/responseFormatSchema.d.ts +41 -0
- package/dist/esm/schemas/llm/phoenixPrompt/responseFormatSchema.d.ts.map +1 -0
- package/dist/esm/schemas/llm/phoenixPrompt/responseFormatSchema.js +15 -0
- package/dist/esm/schemas/llm/phoenixPrompt/responseFormatSchema.js.map +1 -0
- package/dist/esm/schemas/llm/phoenixPrompt/toolCallSchemas.d.ts +36 -0
- package/dist/esm/schemas/llm/phoenixPrompt/toolCallSchemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/phoenixPrompt/toolCallSchemas.js +3 -0
- package/dist/esm/schemas/llm/phoenixPrompt/toolCallSchemas.js.map +1 -0
- package/dist/esm/schemas/llm/phoenixPrompt/toolChoiceSchemas.d.ts +34 -0
- package/dist/esm/schemas/llm/phoenixPrompt/toolChoiceSchemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/phoenixPrompt/toolChoiceSchemas.js +21 -0
- package/dist/esm/schemas/llm/phoenixPrompt/toolChoiceSchemas.js.map +1 -0
- package/dist/esm/schemas/llm/phoenixPrompt/toolSchemas.d.ts +41 -0
- package/dist/esm/schemas/llm/phoenixPrompt/toolSchemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/phoenixPrompt/toolSchemas.js +15 -0
- package/dist/esm/schemas/llm/phoenixPrompt/toolSchemas.js.map +1 -0
- package/dist/esm/schemas/llm/schemas.d.ts +2777 -0
- package/dist/esm/schemas/llm/schemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/schemas.js +77 -0
- package/dist/esm/schemas/llm/schemas.js.map +1 -0
- package/dist/esm/schemas/llm/types.d.ts +129 -0
- package/dist/esm/schemas/llm/types.d.ts.map +1 -0
- package/dist/esm/schemas/llm/types.js +2 -0
- package/dist/esm/schemas/llm/types.js.map +1 -0
- package/dist/esm/schemas/llm/utils.d.ts +25 -0
- package/dist/esm/schemas/llm/utils.d.ts.map +1 -0
- package/dist/esm/schemas/llm/utils.js +176 -0
- package/dist/esm/schemas/llm/utils.js.map +1 -0
- package/dist/esm/schemas/llm/vercel/messagePartSchemas.d.ts +114 -0
- package/dist/esm/schemas/llm/vercel/messagePartSchemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/vercel/messagePartSchemas.js +35 -0
- package/dist/esm/schemas/llm/vercel/messagePartSchemas.js.map +1 -0
- package/dist/esm/schemas/llm/vercel/messageSchemas.d.ts +142 -0
- package/dist/esm/schemas/llm/vercel/messageSchemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/vercel/messageSchemas.js +42 -0
- package/dist/esm/schemas/llm/vercel/messageSchemas.js.map +1 -0
- package/dist/esm/schemas/llm/vercel/toolChoiceSchemas.d.ts +16 -0
- package/dist/esm/schemas/llm/vercel/toolChoiceSchemas.d.ts.map +1 -0
- package/dist/esm/schemas/llm/vercel/toolChoiceSchemas.js +14 -0
- package/dist/esm/schemas/llm/vercel/toolChoiceSchemas.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/types/core.d.ts +8 -0
- package/dist/esm/types/core.d.ts.map +1 -1
- package/dist/esm/types/logger.d.ts +6 -0
- package/dist/esm/types/logger.d.ts.map +1 -0
- package/dist/esm/types/logger.js +2 -0
- package/dist/esm/types/logger.js.map +1 -0
- package/dist/esm/types/prompts.d.ts +107 -0
- package/dist/esm/types/prompts.d.ts.map +1 -0
- package/dist/esm/types/prompts.js +2 -0
- package/dist/esm/types/prompts.js.map +1 -0
- package/dist/esm/utils/assertUnreachable.d.ts +8 -0
- package/dist/esm/utils/assertUnreachable.d.ts.map +1 -0
- package/dist/esm/utils/assertUnreachable.js +10 -0
- package/dist/esm/utils/assertUnreachable.js.map +1 -0
- package/dist/esm/utils/formatPromptMessages.d.ts +26 -0
- package/dist/esm/utils/formatPromptMessages.d.ts.map +1 -0
- package/dist/esm/utils/formatPromptMessages.js +64 -0
- package/dist/esm/utils/formatPromptMessages.js.map +1 -0
- package/dist/esm/utils/getDatasetLike.d.ts +22 -0
- package/dist/esm/utils/getDatasetLike.d.ts.map +1 -0
- package/dist/esm/utils/getDatasetLike.js +37 -0
- package/dist/esm/utils/getDatasetLike.js.map +1 -0
- package/dist/esm/utils/getPromptVersionLike.d.ts +29 -0
- package/dist/esm/utils/getPromptVersionLike.d.ts.map +1 -0
- package/dist/esm/utils/getPromptVersionLike.js +50 -0
- package/dist/esm/utils/getPromptVersionLike.js.map +1 -0
- package/dist/esm/utils/isObject.d.ts +5 -0
- package/dist/esm/utils/isObject.d.ts.map +1 -0
- package/dist/esm/utils/isObject.js +7 -0
- package/dist/esm/utils/isObject.js.map +1 -0
- package/dist/esm/utils/noopLogger.d.ts +9 -0
- package/dist/esm/utils/noopLogger.d.ts.map +1 -0
- package/dist/esm/utils/noopLogger.js +9 -0
- package/dist/esm/utils/noopLogger.js.map +1 -0
- package/dist/esm/utils/safelyParseJSON.d.ts +14 -0
- package/dist/esm/utils/safelyParseJSON.d.ts.map +1 -0
- package/dist/esm/utils/safelyParseJSON.js +15 -0
- package/dist/esm/utils/safelyParseJSON.js.map +1 -0
- package/dist/esm/utils/safelyStringifyJSON.d.ts +14 -0
- package/dist/esm/utils/safelyStringifyJSON.d.ts.map +1 -0
- package/dist/esm/utils/safelyStringifyJSON.js +15 -0
- package/dist/esm/utils/safelyStringifyJSON.js.map +1 -0
- package/dist/esm/utils/schemaMatches.d.ts +17 -0
- package/dist/esm/utils/schemaMatches.d.ts.map +1 -0
- package/dist/esm/utils/schemaMatches.js +9 -0
- package/dist/esm/utils/schemaMatches.js.map +1 -0
- package/dist/src/__generated__/api/v1.d.ts +743 -12
- package/dist/src/__generated__/api/v1.d.ts.map +1 -1
- package/dist/src/client.d.ts +9 -2
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +3 -2
- package/dist/src/client.js.map +1 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +9 -1
- package/dist/src/config.js.map +1 -1
- package/dist/src/experiments/runExperiment.d.ts +35 -8
- package/dist/src/experiments/runExperiment.d.ts.map +1 -1
- package/dist/src/experiments/runExperiment.js +29 -34
- package/dist/src/experiments/runExperiment.js.map +1 -1
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +0 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/prompts/constants.d.ts +6 -0
- package/dist/src/prompts/constants.d.ts.map +1 -0
- package/dist/src/prompts/constants.js +13 -0
- package/dist/src/prompts/constants.js.map +1 -0
- package/dist/src/prompts/createPrompt.d.ts +65 -0
- package/dist/src/prompts/createPrompt.d.ts.map +1 -0
- package/dist/src/prompts/createPrompt.js +123 -0
- package/dist/src/prompts/createPrompt.js.map +1 -0
- package/dist/src/prompts/getPrompt.d.ts +16 -0
- package/dist/src/prompts/getPrompt.d.ts.map +1 -0
- package/dist/src/prompts/getPrompt.js +25 -0
- package/dist/src/prompts/getPrompt.js.map +1 -0
- package/dist/src/prompts/index.d.ts +4 -0
- package/dist/src/prompts/index.d.ts.map +1 -0
- package/dist/src/prompts/index.js +20 -0
- package/dist/src/prompts/index.js.map +1 -0
- package/dist/src/prompts/sdks/constants.d.ts +6 -0
- package/dist/src/prompts/sdks/constants.d.ts.map +1 -0
- package/dist/src/prompts/sdks/constants.js +9 -0
- package/dist/src/prompts/sdks/constants.js.map +1 -0
- package/dist/src/prompts/sdks/index.d.ts +2 -0
- package/dist/src/prompts/sdks/index.d.ts.map +1 -0
- package/dist/src/prompts/sdks/index.js +18 -0
- package/dist/src/prompts/sdks/index.js.map +1 -0
- package/dist/src/prompts/sdks/toAI.d.ts +12 -0
- package/dist/src/prompts/sdks/toAI.d.ts.map +1 -0
- package/dist/src/prompts/sdks/toAI.js +75 -0
- package/dist/src/prompts/sdks/toAI.js.map +1 -0
- package/dist/src/prompts/sdks/toAnthropic.d.ts +9 -0
- package/dist/src/prompts/sdks/toAnthropic.d.ts.map +1 -0
- package/dist/src/prompts/sdks/toAnthropic.js +71 -0
- package/dist/src/prompts/sdks/toAnthropic.js.map +1 -0
- package/dist/src/prompts/sdks/toOpenAI.d.ts +11 -0
- package/dist/src/prompts/sdks/toOpenAI.d.ts.map +1 -0
- package/dist/src/prompts/sdks/toOpenAI.js +78 -0
- package/dist/src/prompts/sdks/toOpenAI.js.map +1 -0
- package/dist/src/prompts/sdks/toSDK.d.ts +47 -0
- package/dist/src/prompts/sdks/toSDK.d.ts.map +1 -0
- package/dist/src/prompts/sdks/toSDK.js +63 -0
- package/dist/src/prompts/sdks/toSDK.js.map +1 -0
- package/dist/src/prompts/sdks/types.d.ts +28 -0
- package/dist/src/prompts/sdks/types.d.ts.map +1 -0
- package/dist/src/prompts/sdks/types.js +3 -0
- package/dist/src/prompts/sdks/types.js.map +1 -0
- package/dist/src/schemas/jsonLiteralSchema.d.ts +17 -0
- package/dist/src/schemas/jsonLiteralSchema.d.ts.map +1 -0
- package/dist/src/schemas/jsonLiteralSchema.js +22 -0
- package/dist/src/schemas/jsonLiteralSchema.js.map +1 -0
- package/dist/src/schemas/jsonSchema.d.ts +132 -0
- package/dist/src/schemas/jsonSchema.d.ts.map +1 -0
- package/dist/src/schemas/jsonSchema.js +48 -0
- package/dist/src/schemas/jsonSchema.js.map +1 -0
- package/dist/src/schemas/llm/anthropic/converters.d.ts +1497 -0
- package/dist/src/schemas/llm/anthropic/converters.d.ts.map +1 -0
- package/dist/src/schemas/llm/anthropic/converters.js +132 -0
- package/dist/src/schemas/llm/anthropic/converters.js.map +1 -0
- package/dist/src/schemas/llm/anthropic/messagePartSchemas.d.ts +264 -0
- package/dist/src/schemas/llm/anthropic/messagePartSchemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/anthropic/messagePartSchemas.js +42 -0
- package/dist/src/schemas/llm/anthropic/messagePartSchemas.js.map +1 -0
- package/dist/src/schemas/llm/anthropic/messageSchemas.d.ts +795 -0
- package/dist/src/schemas/llm/anthropic/messageSchemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/anthropic/messageSchemas.js +29 -0
- package/dist/src/schemas/llm/anthropic/messageSchemas.js.map +1 -0
- package/dist/src/schemas/llm/anthropic/toolCallSchemas.d.ts +48 -0
- package/dist/src/schemas/llm/anthropic/toolCallSchemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/anthropic/toolCallSchemas.js +34 -0
- package/dist/src/schemas/llm/anthropic/toolCallSchemas.js.map +1 -0
- package/dist/src/schemas/llm/anthropic/toolChoiceSchemas.d.ts +30 -0
- package/dist/src/schemas/llm/anthropic/toolChoiceSchemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/anthropic/toolChoiceSchemas.js +25 -0
- package/dist/src/schemas/llm/anthropic/toolChoiceSchemas.js.map +1 -0
- package/dist/src/schemas/llm/anthropic/toolSchemas.d.ts +191 -0
- package/dist/src/schemas/llm/anthropic/toolSchemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/anthropic/toolSchemas.js +38 -0
- package/dist/src/schemas/llm/anthropic/toolSchemas.js.map +1 -0
- package/dist/src/schemas/llm/constants.d.ts +7422 -0
- package/dist/src/schemas/llm/constants.d.ts.map +1 -0
- package/dist/src/schemas/llm/constants.js +131 -0
- package/dist/src/schemas/llm/constants.js.map +1 -0
- package/dist/src/schemas/llm/converters.d.ts +29720 -0
- package/dist/src/schemas/llm/converters.d.ts.map +1 -0
- package/dist/src/schemas/llm/converters.js +330 -0
- package/dist/src/schemas/llm/converters.js.map +1 -0
- package/dist/src/schemas/llm/openai/converters.d.ts +3507 -0
- package/dist/src/schemas/llm/openai/converters.d.ts.map +1 -0
- package/dist/src/schemas/llm/openai/converters.js +321 -0
- package/dist/src/schemas/llm/openai/converters.js.map +1 -0
- package/dist/src/schemas/llm/openai/messagePartSchemas.d.ts +64 -0
- package/dist/src/schemas/llm/openai/messagePartSchemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/openai/messagePartSchemas.js +27 -0
- package/dist/src/schemas/llm/openai/messagePartSchemas.js.map +1 -0
- package/dist/src/schemas/llm/openai/messageSchemas.d.ts +733 -0
- package/dist/src/schemas/llm/openai/messageSchemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/openai/messageSchemas.js +73 -0
- package/dist/src/schemas/llm/openai/messageSchemas.js.map +1 -0
- package/dist/src/schemas/llm/openai/responseFormatSchema.d.ts +233 -0
- package/dist/src/schemas/llm/openai/responseFormatSchema.d.ts.map +1 -0
- package/dist/src/schemas/llm/openai/responseFormatSchema.js +25 -0
- package/dist/src/schemas/llm/openai/responseFormatSchema.js.map +1 -0
- package/dist/src/schemas/llm/openai/toolCallSchemas.d.ts +95 -0
- package/dist/src/schemas/llm/openai/toolCallSchemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/openai/toolCallSchemas.js +47 -0
- package/dist/src/schemas/llm/openai/toolCallSchemas.js.map +1 -0
- package/dist/src/schemas/llm/openai/toolChoiceSchemas.d.ts +28 -0
- package/dist/src/schemas/llm/openai/toolChoiceSchemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/openai/toolChoiceSchemas.js +22 -0
- package/dist/src/schemas/llm/openai/toolChoiceSchemas.js.map +1 -0
- package/dist/src/schemas/llm/openai/toolSchemas.d.ts +1282 -0
- package/dist/src/schemas/llm/openai/toolSchemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/openai/toolSchemas.js +69 -0
- package/dist/src/schemas/llm/openai/toolSchemas.js.map +1 -0
- package/dist/src/schemas/llm/phoenixPrompt/converters.d.ts +847 -0
- package/dist/src/schemas/llm/phoenixPrompt/converters.d.ts.map +1 -0
- package/dist/src/schemas/llm/phoenixPrompt/converters.js +133 -0
- package/dist/src/schemas/llm/phoenixPrompt/converters.js.map +1 -0
- package/dist/src/schemas/llm/phoenixPrompt/messagePartSchemas.d.ts +128 -0
- package/dist/src/schemas/llm/phoenixPrompt/messagePartSchemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/phoenixPrompt/messagePartSchemas.js +71 -0
- package/dist/src/schemas/llm/phoenixPrompt/messagePartSchemas.js.map +1 -0
- package/dist/src/schemas/llm/phoenixPrompt/messageSchemas.d.ts +196 -0
- package/dist/src/schemas/llm/phoenixPrompt/messageSchemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/phoenixPrompt/messageSchemas.js +29 -0
- package/dist/src/schemas/llm/phoenixPrompt/messageSchemas.js.map +1 -0
- package/dist/src/schemas/llm/phoenixPrompt/responseFormatSchema.d.ts +41 -0
- package/dist/src/schemas/llm/phoenixPrompt/responseFormatSchema.d.ts.map +1 -0
- package/dist/src/schemas/llm/phoenixPrompt/responseFormatSchema.js +21 -0
- package/dist/src/schemas/llm/phoenixPrompt/responseFormatSchema.js.map +1 -0
- package/dist/src/schemas/llm/phoenixPrompt/toolCallSchemas.d.ts +36 -0
- package/dist/src/schemas/llm/phoenixPrompt/toolCallSchemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/phoenixPrompt/toolCallSchemas.js +6 -0
- package/dist/src/schemas/llm/phoenixPrompt/toolCallSchemas.js.map +1 -0
- package/dist/src/schemas/llm/phoenixPrompt/toolChoiceSchemas.d.ts +34 -0
- package/dist/src/schemas/llm/phoenixPrompt/toolChoiceSchemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/phoenixPrompt/toolChoiceSchemas.js +27 -0
- package/dist/src/schemas/llm/phoenixPrompt/toolChoiceSchemas.js.map +1 -0
- package/dist/src/schemas/llm/phoenixPrompt/toolSchemas.d.ts +41 -0
- package/dist/src/schemas/llm/phoenixPrompt/toolSchemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/phoenixPrompt/toolSchemas.js +21 -0
- package/dist/src/schemas/llm/phoenixPrompt/toolSchemas.js.map +1 -0
- package/dist/src/schemas/llm/schemas.d.ts +2777 -0
- package/dist/src/schemas/llm/schemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/schemas.js +83 -0
- package/dist/src/schemas/llm/schemas.js.map +1 -0
- package/dist/src/schemas/llm/types.d.ts +129 -0
- package/dist/src/schemas/llm/types.d.ts.map +1 -0
- package/dist/src/schemas/llm/types.js +3 -0
- package/dist/src/schemas/llm/types.js.map +1 -0
- package/dist/src/schemas/llm/utils.d.ts +25 -0
- package/dist/src/schemas/llm/utils.d.ts.map +1 -0
- package/dist/src/schemas/llm/utils.js +187 -0
- package/dist/src/schemas/llm/utils.js.map +1 -0
- package/dist/src/schemas/llm/vercel/messagePartSchemas.d.ts +114 -0
- package/dist/src/schemas/llm/vercel/messagePartSchemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/vercel/messagePartSchemas.js +41 -0
- package/dist/src/schemas/llm/vercel/messagePartSchemas.js.map +1 -0
- package/dist/src/schemas/llm/vercel/messageSchemas.d.ts +142 -0
- package/dist/src/schemas/llm/vercel/messageSchemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/vercel/messageSchemas.js +48 -0
- package/dist/src/schemas/llm/vercel/messageSchemas.js.map +1 -0
- package/dist/src/schemas/llm/vercel/toolChoiceSchemas.d.ts +16 -0
- package/dist/src/schemas/llm/vercel/toolChoiceSchemas.d.ts.map +1 -0
- package/dist/src/schemas/llm/vercel/toolChoiceSchemas.js +20 -0
- package/dist/src/schemas/llm/vercel/toolChoiceSchemas.js.map +1 -0
- package/dist/src/types/core.d.ts +8 -0
- package/dist/src/types/core.d.ts.map +1 -1
- package/dist/src/types/logger.d.ts +6 -0
- package/dist/src/types/logger.d.ts.map +1 -0
- package/dist/src/types/logger.js +3 -0
- package/dist/src/types/logger.js.map +1 -0
- package/dist/src/types/prompts.d.ts +107 -0
- package/dist/src/types/prompts.d.ts.map +1 -0
- package/dist/src/types/prompts.js +3 -0
- package/dist/src/types/prompts.js.map +1 -0
- package/dist/src/utils/assertUnreachable.d.ts +8 -0
- package/dist/src/utils/assertUnreachable.d.ts.map +1 -0
- package/dist/src/utils/assertUnreachable.js +13 -0
- package/dist/src/utils/assertUnreachable.js.map +1 -0
- package/dist/src/utils/formatPromptMessages.d.ts +26 -0
- package/dist/src/utils/formatPromptMessages.d.ts.map +1 -0
- package/dist/src/utils/formatPromptMessages.js +61 -0
- package/dist/src/utils/formatPromptMessages.js.map +1 -0
- package/dist/src/utils/getDatasetLike.d.ts +22 -0
- package/dist/src/utils/getDatasetLike.d.ts.map +1 -0
- package/dist/src/utils/getDatasetLike.js +47 -0
- package/dist/src/utils/getDatasetLike.js.map +1 -0
- package/dist/src/utils/getPromptVersionLike.d.ts +29 -0
- package/dist/src/utils/getPromptVersionLike.d.ts.map +1 -0
- package/dist/src/utils/getPromptVersionLike.js +68 -0
- package/dist/src/utils/getPromptVersionLike.js.map +1 -0
- package/dist/src/utils/isObject.d.ts +5 -0
- package/dist/src/utils/isObject.d.ts.map +1 -0
- package/dist/src/utils/isObject.js +10 -0
- package/dist/src/utils/isObject.js.map +1 -0
- package/dist/src/utils/noopLogger.d.ts +9 -0
- package/dist/src/utils/noopLogger.d.ts.map +1 -0
- package/dist/src/utils/noopLogger.js +12 -0
- package/dist/src/utils/noopLogger.js.map +1 -0
- package/dist/src/utils/safelyParseJSON.d.ts +14 -0
- package/dist/src/utils/safelyParseJSON.d.ts.map +1 -0
- package/dist/src/utils/safelyParseJSON.js +18 -0
- package/dist/src/utils/safelyParseJSON.js.map +1 -0
- package/dist/src/utils/safelyStringifyJSON.d.ts +14 -0
- package/dist/src/utils/safelyStringifyJSON.d.ts.map +1 -0
- package/dist/src/utils/safelyStringifyJSON.js +18 -0
- package/dist/src/utils/safelyStringifyJSON.js.map +1 -0
- package/dist/src/utils/schemaMatches.d.ts +17 -0
- package/dist/src/utils/schemaMatches.d.ts.map +1 -0
- package/dist/src/utils/schemaMatches.js +13 -0
- package/dist/src/utils/schemaMatches.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +32 -5
- package/src/__generated__/api/v1.ts +743 -12
- package/src/client.ts +9 -2
- package/src/config.ts +12 -1
- package/src/experiments/runExperiment.ts +54 -53
- package/src/index.ts +0 -2
- package/src/prompts/constants.ts +11 -0
- package/src/prompts/createPrompt.ts +181 -0
- package/src/prompts/getPrompt.ts +26 -0
- package/src/prompts/index.ts +3 -0
- package/src/prompts/sdks/constants.ts +10 -0
- package/src/prompts/sdks/index.ts +1 -0
- package/src/prompts/sdks/toAI.ts +105 -0
- package/src/prompts/sdks/toAnthropic.ts +98 -0
- package/src/prompts/sdks/toOpenAI.ts +115 -0
- package/src/prompts/sdks/toSDK.ts +81 -0
- package/src/prompts/sdks/types.ts +28 -0
- package/src/schemas/jsonLiteralSchema.ts +24 -0
- package/src/schemas/jsonSchema.ts +47 -0
- package/src/schemas/llm/anthropic/converters.ts +172 -0
- package/src/schemas/llm/anthropic/messagePartSchemas.ts +53 -0
- package/src/schemas/llm/anthropic/messageSchemas.ts +34 -0
- package/src/schemas/llm/anthropic/toolCallSchemas.ts +34 -0
- package/src/schemas/llm/anthropic/toolChoiceSchemas.ts +21 -0
- package/src/schemas/llm/anthropic/toolSchemas.ts +41 -0
- package/src/schemas/llm/constants.ts +156 -0
- package/src/schemas/llm/converters.ts +499 -0
- package/src/schemas/llm/openai/converters.ts +383 -0
- package/src/schemas/llm/openai/messagePartSchemas.ts +30 -0
- package/src/schemas/llm/openai/messageSchemas.ts +78 -0
- package/src/schemas/llm/openai/responseFormatSchema.ts +22 -0
- package/src/schemas/llm/openai/toolCallSchemas.ts +58 -0
- package/src/schemas/llm/openai/toolChoiceSchemas.ts +18 -0
- package/src/schemas/llm/openai/toolSchemas.ts +74 -0
- package/src/schemas/llm/phoenixPrompt/converters.ts +178 -0
- package/src/schemas/llm/phoenixPrompt/messagePartSchemas.ts +95 -0
- package/src/schemas/llm/phoenixPrompt/messageSchemas.ts +34 -0
- package/src/schemas/llm/phoenixPrompt/responseFormatSchema.ts +21 -0
- package/src/schemas/llm/phoenixPrompt/toolCallSchemas.ts +7 -0
- package/src/schemas/llm/phoenixPrompt/toolChoiceSchemas.ts +26 -0
- package/src/schemas/llm/phoenixPrompt/toolSchemas.ts +20 -0
- package/src/schemas/llm/schemas.ts +94 -0
- package/src/schemas/llm/types.ts +161 -0
- package/src/schemas/llm/utils.ts +259 -0
- package/src/schemas/llm/vercel/messagePartSchemas.ts +54 -0
- package/src/schemas/llm/vercel/messageSchemas.ts +54 -0
- package/src/schemas/llm/vercel/toolChoiceSchemas.ts +16 -0
- package/src/types/core.ts +9 -0
- package/src/types/logger.ts +5 -0
- package/src/types/prompts.ts +151 -0
- package/src/utils/assertUnreachable.ts +9 -0
- package/src/utils/formatPromptMessages.ts +79 -0
- package/src/utils/getDatasetLike.ts +52 -0
- package/src/utils/getPromptVersionLike.ts +73 -0
- package/src/utils/isObject.ts +6 -0
- package/src/utils/noopLogger.ts +10 -0
- package/src/utils/safelyParseJSON.ts +13 -0
- package/src/utils/safelyStringifyJSON.ts +15 -0
- package/src/utils/schemaMatches.ts +29 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { anthropicMessagePartSchema } from "./anthropic/messagePartSchemas";
|
|
2
|
+
import { anthropicMessageSchema } from "./anthropic/messageSchemas";
|
|
3
|
+
import { openAIToolCallSchema } from "./openai/toolCallSchemas";
|
|
4
|
+
import { openaiChatPartSchema } from "./openai/messagePartSchemas";
|
|
5
|
+
import { openAIMessageSchema } from "./openai/messageSchemas";
|
|
6
|
+
import { openAIToolChoiceSchema } from "./openai/toolChoiceSchemas";
|
|
7
|
+
import { anthropicToolChoiceSchema } from "./anthropic/toolChoiceSchemas";
|
|
8
|
+
import { openAIToolDefinitionSchema } from "./openai/toolSchemas";
|
|
9
|
+
import { anthropicToolDefinitionSchema } from "./anthropic/toolSchemas";
|
|
10
|
+
import { anthropicToolCallSchema } from "./anthropic/toolCallSchemas";
|
|
11
|
+
import { llmProviderToolDefinitionSchema } from "./schemas";
|
|
12
|
+
import type {
|
|
13
|
+
LLMMessagePart,
|
|
14
|
+
MessagePartWithProvider,
|
|
15
|
+
MessageWithProvider,
|
|
16
|
+
SDKConverters,
|
|
17
|
+
ToolCallWithProvider,
|
|
18
|
+
ToolChoiceWithProvider,
|
|
19
|
+
ToolDefinitionWithProvider,
|
|
20
|
+
} from "./types";
|
|
21
|
+
import { isObject } from "../../utils/isObject";
|
|
22
|
+
import type { ZodTypeAny } from "zod";
|
|
23
|
+
import { vercelAIMessageSchema } from "./vercel/messageSchemas";
|
|
24
|
+
import { phoenixMessageSchema } from "./phoenixPrompt/messageSchemas";
|
|
25
|
+
import { phoenixToolCallSchema } from "./phoenixPrompt/toolCallSchemas";
|
|
26
|
+
import { phoenixToolChoiceSchema } from "./phoenixPrompt/toolChoiceSchemas";
|
|
27
|
+
import { phoenixToolDefinitionSchema } from "./phoenixPrompt/toolSchemas";
|
|
28
|
+
import { phoenixContentPartSchema } from "./phoenixPrompt/messagePartSchemas";
|
|
29
|
+
|
|
30
|
+
export const makeSDKConverters = <
|
|
31
|
+
MessageSchema extends ZodTypeAny,
|
|
32
|
+
MessagePartSchema extends ZodTypeAny,
|
|
33
|
+
ToolChoiceSchema extends ZodTypeAny,
|
|
34
|
+
ToolCallSchema extends ZodTypeAny,
|
|
35
|
+
ToolDefinitionSchema extends ZodTypeAny,
|
|
36
|
+
ResponseFormatSchema extends ZodTypeAny,
|
|
37
|
+
>({
|
|
38
|
+
messages,
|
|
39
|
+
messageParts,
|
|
40
|
+
toolChoices,
|
|
41
|
+
toolCalls,
|
|
42
|
+
toolDefinitions,
|
|
43
|
+
responseFormat,
|
|
44
|
+
}: SDKConverters<
|
|
45
|
+
MessageSchema,
|
|
46
|
+
MessagePartSchema,
|
|
47
|
+
ToolChoiceSchema,
|
|
48
|
+
ToolCallSchema,
|
|
49
|
+
ToolDefinitionSchema,
|
|
50
|
+
ResponseFormatSchema
|
|
51
|
+
>): SDKConverters<
|
|
52
|
+
MessageSchema,
|
|
53
|
+
MessagePartSchema,
|
|
54
|
+
ToolChoiceSchema,
|
|
55
|
+
ToolCallSchema,
|
|
56
|
+
ToolDefinitionSchema,
|
|
57
|
+
ResponseFormatSchema
|
|
58
|
+
> => {
|
|
59
|
+
return {
|
|
60
|
+
messages,
|
|
61
|
+
messageParts,
|
|
62
|
+
toolChoices,
|
|
63
|
+
toolCalls,
|
|
64
|
+
toolDefinitions,
|
|
65
|
+
responseFormat,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Detect the provider of a message object
|
|
71
|
+
*/
|
|
72
|
+
export const detectMessageProvider = (
|
|
73
|
+
message: unknown
|
|
74
|
+
): MessageWithProvider => {
|
|
75
|
+
const { success: openaiSuccess, data: openaiData } =
|
|
76
|
+
openAIMessageSchema.safeParse(message);
|
|
77
|
+
if (openaiSuccess) {
|
|
78
|
+
return {
|
|
79
|
+
// we cannot disambiguate between azure openai and openai here
|
|
80
|
+
provider: "OPENAI",
|
|
81
|
+
validatedMessage: openaiData,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const { success: anthropicSuccess, data: anthropicData } =
|
|
85
|
+
anthropicMessageSchema.safeParse(message);
|
|
86
|
+
if (anthropicSuccess) {
|
|
87
|
+
return {
|
|
88
|
+
provider: "ANTHROPIC",
|
|
89
|
+
validatedMessage: anthropicData,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const { success: vercelSuccess, data: vercelData } =
|
|
93
|
+
vercelAIMessageSchema.safeParse(message);
|
|
94
|
+
if (vercelSuccess) {
|
|
95
|
+
return { provider: "VERCEL_AI", validatedMessage: vercelData };
|
|
96
|
+
}
|
|
97
|
+
const { success: phoenixSuccess, data: phoenixData } =
|
|
98
|
+
phoenixMessageSchema.safeParse(message);
|
|
99
|
+
if (phoenixSuccess) {
|
|
100
|
+
return { provider: "PHOENIX", validatedMessage: phoenixData };
|
|
101
|
+
}
|
|
102
|
+
return { provider: null, validatedMessage: null };
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const detectMessagePartProvider = (
|
|
106
|
+
part: LLMMessagePart
|
|
107
|
+
): MessagePartWithProvider => {
|
|
108
|
+
const { success: openaiSuccess, data: openaiData } =
|
|
109
|
+
openaiChatPartSchema.safeParse(part);
|
|
110
|
+
if (openaiSuccess) {
|
|
111
|
+
return {
|
|
112
|
+
provider: "OPENAI",
|
|
113
|
+
validatedMessage: openaiData,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
const { success: anthropicSuccess, data: anthropicData } =
|
|
117
|
+
anthropicMessagePartSchema.safeParse(part);
|
|
118
|
+
if (anthropicSuccess) {
|
|
119
|
+
return {
|
|
120
|
+
provider: "ANTHROPIC",
|
|
121
|
+
validatedMessage: anthropicData,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const { success: phoenixSuccess, data: phoenixData } =
|
|
125
|
+
phoenixContentPartSchema.safeParse(part);
|
|
126
|
+
if (phoenixSuccess) {
|
|
127
|
+
return { provider: "PHOENIX", validatedMessage: phoenixData };
|
|
128
|
+
}
|
|
129
|
+
return { provider: null, validatedMessage: null };
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Detect the provider of a tool call object
|
|
134
|
+
*/
|
|
135
|
+
export const detectToolCallProvider = (
|
|
136
|
+
toolCall: unknown
|
|
137
|
+
): ToolCallWithProvider => {
|
|
138
|
+
const { success: openaiSuccess, data: openaiData } =
|
|
139
|
+
openAIToolCallSchema.safeParse(toolCall);
|
|
140
|
+
if (openaiSuccess) {
|
|
141
|
+
// we cannot disambiguate between azure openai and openai here
|
|
142
|
+
return { provider: "OPENAI", validatedToolCall: openaiData };
|
|
143
|
+
}
|
|
144
|
+
const { success: anthropicSuccess, data: anthropicData } =
|
|
145
|
+
anthropicToolCallSchema.safeParse(toolCall);
|
|
146
|
+
if (anthropicSuccess) {
|
|
147
|
+
return { provider: "ANTHROPIC", validatedToolCall: anthropicData };
|
|
148
|
+
}
|
|
149
|
+
const { success: phoenixSuccess, data: phoenixData } =
|
|
150
|
+
phoenixToolCallSchema.safeParse(toolCall);
|
|
151
|
+
if (phoenixSuccess) {
|
|
152
|
+
return { provider: "PHOENIX", validatedToolCall: phoenixData };
|
|
153
|
+
}
|
|
154
|
+
return { provider: null, validatedToolCall: null };
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Detects the provider of a tool choice
|
|
159
|
+
* @param toolChoice the tool choice to detect the provider of
|
|
160
|
+
* @returns the provider of the tool choice
|
|
161
|
+
*/
|
|
162
|
+
export const detectToolChoiceProvider = (
|
|
163
|
+
toolChoice: unknown
|
|
164
|
+
): ToolChoiceWithProvider => {
|
|
165
|
+
const { success: openAISuccess, data: openAIData } =
|
|
166
|
+
openAIToolChoiceSchema.safeParse(toolChoice);
|
|
167
|
+
if (openAISuccess) {
|
|
168
|
+
return { provider: "OPENAI", toolChoice: openAIData };
|
|
169
|
+
}
|
|
170
|
+
const { success: anthropicSuccess, data: anthropicData } =
|
|
171
|
+
anthropicToolChoiceSchema.safeParse(toolChoice);
|
|
172
|
+
if (anthropicSuccess) {
|
|
173
|
+
return { provider: "ANTHROPIC", toolChoice: anthropicData };
|
|
174
|
+
}
|
|
175
|
+
const { success: phoenixSuccess, data: phoenixData } =
|
|
176
|
+
phoenixToolChoiceSchema.safeParse(toolChoice);
|
|
177
|
+
if (phoenixSuccess) {
|
|
178
|
+
return { provider: "PHOENIX", toolChoice: phoenixData };
|
|
179
|
+
}
|
|
180
|
+
return { provider: null, toolChoice: null };
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Detect the provider of a tool call object
|
|
185
|
+
*/
|
|
186
|
+
export const detectToolDefinitionProvider = (
|
|
187
|
+
toolDefinition: unknown
|
|
188
|
+
): ToolDefinitionWithProvider => {
|
|
189
|
+
const { success: openaiSuccess, data: openaiData } =
|
|
190
|
+
openAIToolDefinitionSchema.safeParse(toolDefinition);
|
|
191
|
+
if (openaiSuccess) {
|
|
192
|
+
return {
|
|
193
|
+
// we cannot disambiguate between azure openai and openai here
|
|
194
|
+
provider: "OPENAI",
|
|
195
|
+
validatedToolDefinition: openaiData,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
const { success: anthropicSuccess, data: anthropicData } =
|
|
199
|
+
anthropicToolDefinitionSchema.safeParse(toolDefinition);
|
|
200
|
+
if (anthropicSuccess) {
|
|
201
|
+
return {
|
|
202
|
+
provider: "ANTHROPIC",
|
|
203
|
+
validatedToolDefinition: anthropicData,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
const { success: phoenixSuccess, data: phoenixData } =
|
|
207
|
+
phoenixToolDefinitionSchema.safeParse(toolDefinition);
|
|
208
|
+
if (phoenixSuccess) {
|
|
209
|
+
return { provider: "PHOENIX", validatedToolDefinition: phoenixData };
|
|
210
|
+
}
|
|
211
|
+
return { provider: null, validatedToolDefinition: null };
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
export const findToolDefinitionName = (toolDefinition: unknown) => {
|
|
215
|
+
const parsed = llmProviderToolDefinitionSchema.safeParse(toolDefinition);
|
|
216
|
+
if (!parsed.success || parsed.data === null || !isObject(parsed.data)) {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (
|
|
221
|
+
"function" in parsed.data &&
|
|
222
|
+
isObject(parsed.data.function) &&
|
|
223
|
+
"name" in parsed.data.function &&
|
|
224
|
+
typeof parsed.data.function.name === "string"
|
|
225
|
+
) {
|
|
226
|
+
return parsed.data.function.name;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if ("name" in parsed.data && typeof parsed.data.name === "string") {
|
|
230
|
+
return parsed.data.name;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return null;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
export const findToolDefinitionDescription = (toolDefinition: unknown) => {
|
|
237
|
+
const parsed = llmProviderToolDefinitionSchema.safeParse(toolDefinition);
|
|
238
|
+
if (!parsed.success || parsed.data === null || !isObject(parsed.data)) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (
|
|
243
|
+
"function" in parsed.data &&
|
|
244
|
+
isObject(parsed.data.function) &&
|
|
245
|
+
"description" in parsed.data.function &&
|
|
246
|
+
typeof parsed.data.function.description === "string"
|
|
247
|
+
) {
|
|
248
|
+
return parsed.data.function.description;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (
|
|
252
|
+
"description" in parsed.data &&
|
|
253
|
+
typeof parsed.data.description === "string"
|
|
254
|
+
) {
|
|
255
|
+
return parsed.data.description;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return null;
|
|
259
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import { jsonLiteralSchema } from "../../jsonLiteralSchema";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
*
|
|
6
|
+
* Vercel AI SDK Message Part Schemas
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const vercelAIChatPartTextSchema = z.object({
|
|
11
|
+
type: z.literal("text"),
|
|
12
|
+
text: z.string(),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export type VercelAIChatPartText = z.infer<typeof vercelAIChatPartTextSchema>;
|
|
16
|
+
|
|
17
|
+
export const vercelAIChatPartImageSchema = z.object({
|
|
18
|
+
type: z.literal("image"),
|
|
19
|
+
image: z.string(), // ai supports more, but we will just support base64 for now
|
|
20
|
+
mimeType: z.string().optional(),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export type VercelAIChatPartImage = z.infer<typeof vercelAIChatPartImageSchema>;
|
|
24
|
+
|
|
25
|
+
export const vercelAIChatPartToolCallSchema = z.object({
|
|
26
|
+
type: z.literal("tool-call"),
|
|
27
|
+
toolCallId: z.string(),
|
|
28
|
+
toolName: z.string(),
|
|
29
|
+
args: jsonLiteralSchema, // json serializable parameters
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export type VercelAIChatPartToolCall = z.infer<
|
|
33
|
+
typeof vercelAIChatPartToolCallSchema
|
|
34
|
+
>;
|
|
35
|
+
|
|
36
|
+
export const vercelAIChatPartToolResultSchema = z.object({
|
|
37
|
+
type: z.literal("tool-result"),
|
|
38
|
+
toolCallId: z.string(),
|
|
39
|
+
toolName: z.string(),
|
|
40
|
+
result: jsonLiteralSchema, // json serializable result
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export type VercelAIChatPartToolResult = z.infer<
|
|
44
|
+
typeof vercelAIChatPartToolResultSchema
|
|
45
|
+
>;
|
|
46
|
+
|
|
47
|
+
export const vercelAIChatPartSchema = z.discriminatedUnion("type", [
|
|
48
|
+
vercelAIChatPartTextSchema,
|
|
49
|
+
vercelAIChatPartImageSchema,
|
|
50
|
+
vercelAIChatPartToolCallSchema,
|
|
51
|
+
vercelAIChatPartToolResultSchema,
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
export type VercelAIChatPart = z.infer<typeof vercelAIChatPartSchema>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
vercelAIChatPartImageSchema,
|
|
5
|
+
vercelAIChatPartTextSchema,
|
|
6
|
+
vercelAIChatPartToolCallSchema,
|
|
7
|
+
vercelAIChatPartToolResultSchema,
|
|
8
|
+
} from "./messagePartSchemas";
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
*
|
|
12
|
+
* Vercel AI SDK Message Schemas
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export const vercelAIMessageRoleSchema = z.enum([
|
|
17
|
+
"system",
|
|
18
|
+
"user",
|
|
19
|
+
"assistant",
|
|
20
|
+
"tool",
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
export type VercelAIMessageRole = z.infer<typeof vercelAIMessageRoleSchema>;
|
|
24
|
+
|
|
25
|
+
export const vercelAIMessageSchema = z.discriminatedUnion("role", [
|
|
26
|
+
z.object({
|
|
27
|
+
role: z.literal("system"),
|
|
28
|
+
content: z.string(),
|
|
29
|
+
}),
|
|
30
|
+
z.object({
|
|
31
|
+
role: z.literal("user"),
|
|
32
|
+
content: z.union([
|
|
33
|
+
z
|
|
34
|
+
.union([vercelAIChatPartTextSchema, vercelAIChatPartImageSchema])
|
|
35
|
+
.array(),
|
|
36
|
+
z.string(),
|
|
37
|
+
]),
|
|
38
|
+
}),
|
|
39
|
+
z.object({
|
|
40
|
+
role: z.literal("assistant"),
|
|
41
|
+
content: z.union([
|
|
42
|
+
z
|
|
43
|
+
.union([vercelAIChatPartTextSchema, vercelAIChatPartToolCallSchema])
|
|
44
|
+
.array(),
|
|
45
|
+
z.string(),
|
|
46
|
+
]),
|
|
47
|
+
}),
|
|
48
|
+
z.object({
|
|
49
|
+
role: z.literal("tool"),
|
|
50
|
+
content: vercelAIChatPartToolResultSchema.array(),
|
|
51
|
+
}),
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
export type VercelAIMessage = z.infer<typeof vercelAIMessageSchema>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Vercel AI SDK Tool Choice Schema
|
|
5
|
+
*/
|
|
6
|
+
export const vercelAIToolChoiceSchema = z.union([
|
|
7
|
+
z.literal("auto"),
|
|
8
|
+
z.literal("none"),
|
|
9
|
+
z.literal("required"),
|
|
10
|
+
z.object({
|
|
11
|
+
type: z.literal("tool"),
|
|
12
|
+
toolName: z.string(),
|
|
13
|
+
}),
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
export type VercelAIToolChoice = z.infer<typeof vercelAIToolChoiceSchema>;
|
package/src/types/core.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import { PhoenixClient } from "../client";
|
|
1
2
|
/**
|
|
2
3
|
* A uniquely identifiable node in Phoenix
|
|
3
4
|
*/
|
|
4
5
|
export interface Node {
|
|
5
6
|
id: string;
|
|
6
7
|
}
|
|
8
|
+
|
|
9
|
+
export interface ClientFn {
|
|
10
|
+
/**
|
|
11
|
+
* An instance of the Phoenix client.
|
|
12
|
+
* If not provided, the client will be created using the default configuration.
|
|
13
|
+
*/
|
|
14
|
+
client?: PhoenixClient;
|
|
15
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { components } from "../__generated__/api/v1";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Supported prompt model providers
|
|
5
|
+
*/
|
|
6
|
+
export type PromptModelProvider =
|
|
7
|
+
| "OPENAI"
|
|
8
|
+
| "AZURE_OPENAI"
|
|
9
|
+
| "ANTHROPIC"
|
|
10
|
+
| "GOOGLE";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Supported prompt provider SDKs
|
|
14
|
+
*
|
|
15
|
+
* These are possible sdk formats for prompt templates
|
|
16
|
+
*/
|
|
17
|
+
export type PromptProviderSDKs =
|
|
18
|
+
| "PHOENIX"
|
|
19
|
+
| "AZURE_OPENAI"
|
|
20
|
+
| "OPENAI"
|
|
21
|
+
| "ANTHROPIC"
|
|
22
|
+
| "VERCEL_AI";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The role of a prompt chat message
|
|
26
|
+
*/
|
|
27
|
+
export type PromptChatMessageRole = "user" | "system" | "ai" | "tool";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Selector for a prompt by id.
|
|
31
|
+
*/
|
|
32
|
+
export interface GetPromptByIdSelector {
|
|
33
|
+
promptId: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Selector for a prompt by name.
|
|
38
|
+
*/
|
|
39
|
+
export interface GetPromptByNameSelector {
|
|
40
|
+
name: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Selector for a prompt by version id.
|
|
45
|
+
*/
|
|
46
|
+
export interface GetPromptByVersionSelector {
|
|
47
|
+
versionId: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Selector for a named prompt by tag.
|
|
52
|
+
*/
|
|
53
|
+
export interface GetPromptByTagSelector {
|
|
54
|
+
tag: string;
|
|
55
|
+
name: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A prompt like object.
|
|
60
|
+
*
|
|
61
|
+
* Can be a prompt id, a prompt name, a prompt version id, or a prompt name + tag.
|
|
62
|
+
*/
|
|
63
|
+
export type PromptSelector =
|
|
64
|
+
| GetPromptByIdSelector
|
|
65
|
+
| GetPromptByNameSelector
|
|
66
|
+
| GetPromptByVersionSelector
|
|
67
|
+
| GetPromptByTagSelector;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The prompt data needed to create a prompt.
|
|
71
|
+
*/
|
|
72
|
+
export type PromptData = components["schemas"]["PromptData"];
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The prompt version type from the API.
|
|
76
|
+
*
|
|
77
|
+
* aka the prompt at a specific point in time
|
|
78
|
+
*/
|
|
79
|
+
export type PromptVersion = components["schemas"]["PromptVersion"];
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The prompt version data needed to create a prompt version.
|
|
83
|
+
*/
|
|
84
|
+
export type PromptVersionData = components["schemas"]["PromptVersionData"];
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The invocation parameters for a prompt version for OpenAI.
|
|
88
|
+
*/
|
|
89
|
+
export type OpenAIInvocationParameters =
|
|
90
|
+
components["schemas"]["PromptOpenAIInvocationParametersContent"];
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The invocation parameters for a prompt version for Azure OpenAI.
|
|
94
|
+
*/
|
|
95
|
+
export type AzureOpenAIInvocationParameters =
|
|
96
|
+
components["schemas"]["PromptAzureOpenAIInvocationParametersContent"];
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The invocation parameters for a prompt version for Anthropic.
|
|
100
|
+
*/
|
|
101
|
+
export type AnthropicInvocationParameters =
|
|
102
|
+
components["schemas"]["PromptAnthropicInvocationParametersContent"];
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The invocation parameters for a prompt version for Google.
|
|
106
|
+
*/
|
|
107
|
+
export type GoogleInvocationParameters =
|
|
108
|
+
components["schemas"]["PromptGoogleInvocationParametersContent"];
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The format of the prompt template message(s).
|
|
112
|
+
*/
|
|
113
|
+
export type PromptTemplateFormat = PromptVersion["template_format"];
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Extracts the chat message type from the prompt template who may be a StringTemplate or ChatTemplate.
|
|
117
|
+
*/
|
|
118
|
+
export type PromptChatMessage = Extract<
|
|
119
|
+
PromptVersion["template"],
|
|
120
|
+
{ messages: unknown[] }
|
|
121
|
+
>["messages"][number];
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Extracts the chat message part type from the prompt chat message.
|
|
125
|
+
*/
|
|
126
|
+
export type PromptChatMessagePart =
|
|
127
|
+
| components["schemas"]["TextContentPart"]
|
|
128
|
+
| components["schemas"]["ToolCallContentPart"]
|
|
129
|
+
| components["schemas"]["ToolResultContentPart"];
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The Phoenix prompt tool type from the API.
|
|
133
|
+
*/
|
|
134
|
+
export type PromptTool = components["schemas"]["PromptTools"]["tools"][number];
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The Phoenix prompt tool choice type from the API.
|
|
138
|
+
*/
|
|
139
|
+
export type PromptToolChoice = NonNullable<
|
|
140
|
+
components["schemas"]["PromptTools"]["tool_choice"]
|
|
141
|
+
>;
|
|
142
|
+
/**
|
|
143
|
+
* The Phoenix prompt output schema type from the API.
|
|
144
|
+
*/
|
|
145
|
+
export type PromptResponseFormat =
|
|
146
|
+
components["schemas"]["PromptResponseFormatJSONSchema"];
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The prompt type from the API.
|
|
150
|
+
*/
|
|
151
|
+
export type Prompt = components["schemas"]["Prompt"];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility function that uses the type system to check if a switch statement is exhaustive.
|
|
3
|
+
* If the switch statement is not exhaustive, there will be a type error caught in typescript
|
|
4
|
+
*
|
|
5
|
+
* See https://stackoverflow.com/questions/39419170/how-do-i-check-that-a-switch-block-is-exhaustive-in-typescript for more details.
|
|
6
|
+
*/
|
|
7
|
+
export function assertUnreachable(_: never): never {
|
|
8
|
+
throw new Error("Unreachable");
|
|
9
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Variables } from "../prompts/sdks/types";
|
|
2
|
+
import { PromptChatMessage, PromptTemplateFormat } from "../types/prompts";
|
|
3
|
+
import { assertUnreachable } from "./assertUnreachable";
|
|
4
|
+
import {
|
|
5
|
+
TextPart,
|
|
6
|
+
asTextPart,
|
|
7
|
+
} from "../schemas/llm/phoenixPrompt/messagePartSchemas";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Format a list of prompt messages
|
|
11
|
+
*
|
|
12
|
+
* @param format - The format of the prompt message variables, e.g. MUSTACHE, F_STRING, NONE
|
|
13
|
+
* @param promptMessages - The prompt messages to format
|
|
14
|
+
* @param variables - The variables to use in the formatting
|
|
15
|
+
* @returns The formatted prompt messages
|
|
16
|
+
*/
|
|
17
|
+
export function formatPromptMessages(
|
|
18
|
+
format: PromptTemplateFormat,
|
|
19
|
+
promptMessages: PromptChatMessage[],
|
|
20
|
+
variables: Variables = {}
|
|
21
|
+
) {
|
|
22
|
+
const replacements: [RegExp, string][] = [];
|
|
23
|
+
switch (format) {
|
|
24
|
+
case "MUSTACHE": {
|
|
25
|
+
const asMustache = Object.entries(variables).map(([key, value]) => [
|
|
26
|
+
new RegExp(`\\{\\{\\s*${key}\\s*\\}\\}(?!\\})`, "g"),
|
|
27
|
+
value.toString(),
|
|
28
|
+
]) satisfies [RegExp, string][];
|
|
29
|
+
replacements.push(...asMustache);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
case "F_STRING": {
|
|
33
|
+
const asF_STRING = Object.entries(variables).map(([key, value]) => [
|
|
34
|
+
new RegExp(`(?<!\\{)\\{\\s*${key}\\s*\\}(?!\\})`, "g"),
|
|
35
|
+
value.toString(),
|
|
36
|
+
]) satisfies [RegExp, string][];
|
|
37
|
+
replacements.push(...asF_STRING);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
case "NONE":
|
|
41
|
+
break;
|
|
42
|
+
default:
|
|
43
|
+
assertUnreachable(format);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return promptMessages.map((message) => ({
|
|
47
|
+
...message,
|
|
48
|
+
content:
|
|
49
|
+
typeof message.content == "string"
|
|
50
|
+
? applyReplacements(message.content, replacements)
|
|
51
|
+
: message.content.map((content) => {
|
|
52
|
+
const textPart = asTextPart(content);
|
|
53
|
+
if (textPart) {
|
|
54
|
+
return {
|
|
55
|
+
...textPart,
|
|
56
|
+
text: applyReplacements(textPart.text, replacements),
|
|
57
|
+
} satisfies TextPart;
|
|
58
|
+
}
|
|
59
|
+
return content;
|
|
60
|
+
}),
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Apply a list of replacements to a string
|
|
66
|
+
* @param text - The text to apply the replacements to
|
|
67
|
+
* @param replacements - The replacements to apply
|
|
68
|
+
* @returns The text with the replacements applied
|
|
69
|
+
*/
|
|
70
|
+
function applyReplacements(
|
|
71
|
+
text: string,
|
|
72
|
+
replacements: [RegExp, string][]
|
|
73
|
+
): string {
|
|
74
|
+
let newText = text;
|
|
75
|
+
for (const [key, value] of replacements) {
|
|
76
|
+
newText = newText.replaceAll(key, value);
|
|
77
|
+
}
|
|
78
|
+
return newText;
|
|
79
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import invariant from "tiny-invariant";
|
|
2
|
+
import { PhoenixClient } from "../client";
|
|
3
|
+
import { Example } from "../types/datasets";
|
|
4
|
+
|
|
5
|
+
import { Dataset } from "../types/datasets";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Parameters for the getDatasetLike function
|
|
9
|
+
*/
|
|
10
|
+
export type GetDatasetLikeParams = {
|
|
11
|
+
dataset: Dataset | string | Example[];
|
|
12
|
+
client: PhoenixClient;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Return a dataset object from the input.
|
|
17
|
+
*
|
|
18
|
+
* If the input is a string, assume it is a dataset id and fetch the dataset from the client.
|
|
19
|
+
* If the input is an array of examples, create a new dataset from the examples then return it.
|
|
20
|
+
* If the input is a dataset, return it as is.
|
|
21
|
+
*
|
|
22
|
+
* @param dataset - The dataset to get.
|
|
23
|
+
* @returns The dataset.
|
|
24
|
+
*/
|
|
25
|
+
export async function getDatasetLike({
|
|
26
|
+
dataset,
|
|
27
|
+
client,
|
|
28
|
+
}: GetDatasetLikeParams): Promise<Dataset | null> {
|
|
29
|
+
if (typeof dataset === "string") {
|
|
30
|
+
const datasetResponse = await client
|
|
31
|
+
.GET(`/v1/datasets/{id}`, { params: { path: { id: dataset } } })
|
|
32
|
+
.then((d) => d.data?.data);
|
|
33
|
+
invariant(datasetResponse, `Dataset ${dataset} not found`);
|
|
34
|
+
const examples = await client
|
|
35
|
+
.GET(`/v1/datasets/{id}/examples`, { params: { path: { id: dataset } } })
|
|
36
|
+
.then((e) => e.data?.data);
|
|
37
|
+
invariant(examples, `Examples for dataset ${dataset} not found`);
|
|
38
|
+
const datasetWithExamples: Dataset = {
|
|
39
|
+
...datasetResponse,
|
|
40
|
+
examples: examples.examples.map((example) => ({
|
|
41
|
+
...example,
|
|
42
|
+
updatedAt: new Date(example.updated_at),
|
|
43
|
+
})),
|
|
44
|
+
versionId: examples.version_id,
|
|
45
|
+
};
|
|
46
|
+
return datasetWithExamples;
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(dataset)) {
|
|
49
|
+
throw new Error("TODO: implement dataset creation from examples");
|
|
50
|
+
}
|
|
51
|
+
return dataset;
|
|
52
|
+
}
|