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

feat: Apply schema check for Azure OpenAI client response #130

Merged
merged 19 commits into from
Sep 17, 2024

Conversation

ZhongpinWang
Copy link
Contributor

Context

AI/gen-ai-hub-sdk-js-backlog#54.

Use Zod schema to type check OpenAI chat and embedding reponses at runtime.

Definition of Done

  • Code is tested (Unit, E2E)
  • Error handling created / updated & covered by the tests above
  • Documentation updated
  • (Optional) Aligned changes with the Java SDK
  • (Optional) Release notes updated

@ZhongpinWang
Copy link
Contributor Author

ZhongpinWang commented Sep 12, 2024

@marikaner @deekshas8 I would appreciate your opinions for this PR, especially if you like the approach with Zod. I can see some potential refactorings and automation, but feel free to mention them as well.

public api check is failing due to the generated zod schema. Unfortunately, we have to generate the schema at compile time to check types. Although we could infer new ts types from zod schema, there is AFAIK no way to create a zod schema at runtime from ts type probably because there is no type at js runtime.

@ZhongpinWang ZhongpinWang marked this pull request as ready for review September 16, 2024 14:53
Copy link
Contributor

@marikaner marikaner left a comment

Choose a reason for hiding this comment

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

Generally I am not opposed to the "response" classes itself, might make access to data more convenient. However, if I got it right we are checking the structure of all responses for each request (right?) I expected this to happen in the tests only, not in production. While I think it is not super expensive, I don't see a major benefit either.

eslint.config.js Show resolved Hide resolved
packages/foundation-models/package.json Outdated Show resolved Hide resolved
Copy link
Contributor

@marikaner marikaner left a comment

Choose a reason for hiding this comment

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

LGTM

packages/foundation-models/package.json Show resolved Hide resolved
@ZhongpinWang ZhongpinWang merged commit 1f4617d into main Sep 17, 2024
9 checks passed
@ZhongpinWang ZhongpinWang deleted the feat-apply-schema-check-for-types branch September 17, 2024 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants