Skip to content

Conversation

@gr2m
Copy link
Collaborator

@gr2m gr2m commented Apr 15, 2025

Background

Towards #5766

Tasks

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • If required, a patch changeset for relevant packages has been added
  • You've run pnpm prettier-fix to fix any formatting issues

@gr2m gr2m force-pushed the v5-5766-async-validate branch from 635465b to f05c9b2 Compare April 15, 2025 22:46
@gr2m gr2m changed the title 🚧 make safeValidateTypes() async 🚧 fix: make validateTypes() and safeValidateTypes() async Apr 15, 2025
}),
);

const resolvedOutput = await output?.parseOutput(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Instead of passing an outputResolver() callback, the output needs to be computed ahead of instantiating the DefaultGenerateTextResult class, in order to retain the synchronous .experimental_output getter API

@gr2m
Copy link
Collaborator Author

gr2m commented Apr 15, 2025

To keep track, here are the methods that were previously sync and are now async:

  • processResult in packages/ai/core/generate-object/generate-object.ts
  • validatePartialResult and validateFinalResult in packages/ai/core/generate-object/output-strategy.ts
  • parsePartial and parseOutput in packages/ai/core/generate-text/output.ts
  • transform in packages/ai/core/generate-text/stream-text.ts
  • parsePartialJson in packages/ai/core/util/parse-partial-json.ts
  • onToolCallDeltaPart in packages/ai/core/util/process-chat-response.ts
  • doGenerate and doStream in packages/amazon-bedrock/src/bedrock-chat-language-model.ts
  • extractMetadata and processChunk in packages/deepseek/src/deepseek-metadata-extractor.ts
  • doGenerate and doStream in packages/groq/src/groq-chat-language-model.ts
  • doGenerate and doStream in packages/mistral/src/mistral-chat-language-model.ts
  • doGenerate and doStream in packages/openai/src/openai-chat-language-model.ts
  • doGenerate and doStream in packages/openai/src/responses/openai-responses-language-model.ts
  • standardizePrompt in packages/ai/core/prompt/standardize-prompt.ts
  • parseJSON and safeParseJSON in packages/provider-utils/src/parse-json.ts
  • parseProviderOptions in packages/provider-utils/src/parse-provider-options.ts
  • createJsonResponseHandler in packages/provider-utils/src/response-handler.ts

sources,
outputResolver: () => {
if (output == null) {
throw new NoOutputSpecifiedError();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this error be removed?

Comment on lines +764 to +765
if (this.resolvedOutput == null) {
throw new NoOutputSpecifiedError();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

null output might be valid in some cases. We can remove the error imo

Copy link
Collaborator

Choose a reason for hiding this comment

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

(this was the original reason for delaying the check)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removing the handling of falsy values leads to a type error. The generateText() method could in theory end up returning null or undefined. Shall we update the type?

packages/ai/core/generate-text/generate-text.ts:243:3 - error TS2322: Type 'DefaultGenerateTextResult<TOOLS, Awaited<OUTPUT> | undefined>' is not assignable to type 'GenerateTextResult<TOOLS, OUTPUT>'.
  Types of property 'experimental_output' are incompatible.
    Type 'Awaited<OUTPUT> | undefined' is not assignable to type 'OUTPUT'.
      'OUTPUT' could be instantiated with an arbitrary type which could be unrelated to 'Awaited<OUTPUT> | undefined'.

243   return recordSpan({
      ~~~~~~

Copy link
Collaborator

Choose a reason for hiding this comment

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

let's create a ticket to revisit this later

@lgrammel lgrammel closed this Apr 16, 2025
@lgrammel lgrammel reopened this Apr 16, 2025
@lgrammel
Copy link
Collaborator

Close/re-open to trigger actions.

@gr2m gr2m force-pushed the v5-5766-async-validate branch from 97bad38 to e329b0a Compare April 23, 2025 22:50
@gr2m gr2m changed the title 🚧 fix: make validateTypes() and safeValidateTypes() async fix: make validateTypes() and safeValidateTypes() async Apr 23, 2025
@gr2m gr2m marked this pull request as ready for review April 23, 2025 23:21
@lgrammel lgrammel merged commit b55e691 into v5 Apr 24, 2025
7 checks passed
@lgrammel lgrammel deleted the v5-5766-async-validate branch April 24, 2025 06:37
samdenty added a commit that referenced this pull request Apr 24, 2025
* origin/v5:
  fix: make `validateTypes()` and `safeValidateTypes()` async (#5779)
  refactor (image-model): rename `ImageModelV1` to `ImageModelV2` (#5936)
Graysonbarton

This comment was marked as spam.

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.

4 participants