feat(ai): introduce experimental callbacks for embed function#13478
feat(ai): introduce experimental callbacks for embed function#13478aayush-kapoor merged 14 commits intomainfrom
Conversation
| * | ||
| * Called when the operation begins, before the embedding model is called. | ||
| */ | ||
| export interface EmbedOnStartEvent { |
There was a problem hiding this comment.
when this is integrated into telemetry, some of the telemetry method names might need to change
There was a problem hiding this comment.
yeah, might need to come up with a good nomenclature. worth discussing in the follow up PR
…into aayush/embed-callbacks
| @@ -17,9 +17,9 @@ | |||
| /** | |||
| * Common model information used across callback events. | |||
There was a problem hiding this comment.
also file still called callback-events -- maybe generate-text-events?
There was a problem hiding this comment.
these are used by stream text as well.. how about core-events?
| export interface ModelEventInfo { | ||
| /** The provider identifier (e.g., 'openai', 'anthropic'). */ | ||
| readonly provider: string; | ||
| /** The specific model identifier (e.g., 'gpt-4o'). */ | ||
| readonly modelId: string; | ||
| } |
There was a problem hiding this comment.
we have this already somewhere in the codebase afaik. if not it is worth having more general, e.g. as standalone ModelInfo (dont like info but good enough until we have a better name)
|
|
||
| /** The model being used for generation. */ | ||
| readonly model: CallbackModelInfo; | ||
| readonly model: ModelEventInfo; |
There was a problem hiding this comment.
why do we have ModelEventInfo to begin with? can it be flattened?
| @@ -0,0 +1,104 @@ | |||
| import type { JSONValue } from '@ai-sdk/provider'; | |||
| import type { ProviderOptions } from '@ai-sdk/provider-utils'; | |||
| import type { ModelEventInfo } from '../generate-text/callback-events'; | |||
There was a problem hiding this comment.
the dependency on generate-text seems strange. can we flatten the object into the events? or extract it into some other folder?
|
🚀 Published in:
|
|
|
…on (#13637) This is an automated backport of #13478 to the release-v6.0 branch. FYI @aayush-kapoor This backport has conflicts that need to be resolved manually. ### `git cherry-pick` output ``` Auto-merging content/docs/03-ai-sdk-core/65-event-listeners.mdx Auto-merging packages/ai/src/embed/embed-many.test.ts Auto-merging packages/ai/src/embed/embed.test.ts CONFLICT (content): Merge conflict in packages/ai/src/embed/embed.test.ts Auto-merging packages/ai/src/generate-text/callback-events.ts error: could not apply ff9ce30... feat(ai): introduce experimental callbacks for embed function (#13478) hint: After resolving the conflicts, mark them with hint: "git add/rm <pathspec>", then run hint: "git cherry-pick --continue". hint: You can instead skip this commit with "git cherry-pick --skip". hint: To abort and get back to the state before "git cherry-pick", hint: run "git cherry-pick --abort". hint: Disable this message with "git config set advice.mergeConflict false" ``` --------- Co-authored-by: Aayush Kapoor <83492835+aayush-kapoor@users.noreply.github.com> Co-authored-by: Aayush Kapoor <aayushkapoor34@gmail.com>
## Background as a follow up to this PR #13478, specifically [this comment](#13478 (comment)), there was uneccessary convolution of the data ## Summary - flatten the `model: {provider, modelId}` to be `provider` and `modelId` individually - rename `callback-events.ts` to `core-events.ts` ## Manual Verification na ## Checklist - [x] Tests have been added / updated (for bug fixes / features) - [ ] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [x] I have reviewed this pull request (self-review) --------- Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
## Background the changes from #13478 were backported when they shouldn't have been. ## Summary cherry pick and revert all the changes ## Manual Verification na ## Checklist - [x] Tests have been added / updated (for bug fixes / features) - [x] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [x] I have reviewed this pull request (self-review)
Background
In order to completely decouple OTel from the
aipackage, we need to align all the core functions to emit event data at each step for each of the functions.We made similar changes to generateText and streamText when we introduced
experimental_*(onStart, onStepStart, onFinish etc) and the same changes/callbacks needed to be added for the embed functionSummary
onStartandonFinishcallbacks (experimental)embedandembedManyManual Verification
na
Checklist
pnpm changesetin the project root)Future Work
decouple otel from the embed and embedMany function and move integration to
open-telemetry-integration