Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(prompts): Enforce zod schemas match openapi types (3/3) #6316

Conversation

cephalization
Copy link
Contributor

@cephalization cephalization commented Feb 10, 2025

Depends on #6315

This PR introduces a new type utility to enforce that zod schemas for phoenix prompt types will always match the corresponding openapi generated types.

This pull request is 3 / 3 in a series of refactors to make the TS client easier to understand and maintain

  • Reorganize llm schemas and converters by generative provider sdk
  • Distinguish between generative provider and generative provider sdk target
    • Converters now switch on SDK instead of provider, are strongly typed and exhaustively checked
  • Strictly enforce zod schemas adhere to reference types (i.e. if phoenix openapi types change, zod schemas do not pass typecheck)

Partially resolves #6305

Copy link

pkg-pr-new bot commented Feb 10, 2025

Open in Stackblitz

npm i https://pkg.pr.new/Arize-ai/phoenix/@arizeai/phoenix-client@6316

commit: 254b87a

@cephalization cephalization marked this pull request as ready for review February 10, 2025 17:00
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Feb 10, 2025
@cephalization cephalization force-pushed the cephalization/prompts/reorganize-ts-schemas-2 branch from fcb3895 to 508433b Compare February 10, 2025 19:07
@cephalization cephalization force-pushed the cephalization/prompts/reorganize-ts-schemas-3 branch from a3ad339 to 3448a08 Compare February 10, 2025 19:08
extra_parameters: z.record(z.unknown()).optional(),
});
export const phoenixPromptResponseFormatSchema =
schemaMatches<PromptResponseFormat>()(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth a comment that running this util enforces the openAPI schema

@@ -1,18 +1,24 @@
import z from "zod";
import { jsonSchemaZodSchema } from "../../jsonSchema";
import { schemaMatches } from "../../../utils/schemaMatches";
import { PromptResponseFormat } from "../../../types/prompts";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably need to shuffle around this directory since it's not clear that this type relates to the REST API based types (e.g. openapi)

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Feb 10, 2025
@cephalization cephalization merged commit 132cc3a into cephalization/prompts/reorganize-ts-schemas-2 Feb 10, 2025
6 checks passed
@cephalization cephalization deleted the cephalization/prompts/reorganize-ts-schemas-3 branch February 10, 2025 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants