-
Notifications
You must be signed in to change notification settings - Fork 548
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
Add native run binding for Workers AI #5371
Conversation
🦋 Changeset detectedLatest commit: c49bf87 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
a38364d
to
146916d
Compare
81a6392
to
9a3b827
Compare
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8498132672/npm-package-wrangler-5371 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/5371/npm-package-wrangler-5371 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8498132672/npm-package-wrangler-5371 dev path/to/script.js Additional artifacts:npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8498132672/npm-package-create-cloudflare-5371 --no-auto-update npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8498132672/npm-package-cloudflare-kv-asset-handler-5371 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8498132672/npm-package-miniflare-5371 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8498132672/npm-package-cloudflare-pages-shared-5371 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8498132672/npm-package-cloudflare-vitest-pool-workers-5371 Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
1937246
to
61ab497
Compare
Will this change the user experience for local dev? |
@admah yes, user will be able to use Workers ai without installing the |
@G4brym — assume this need to go out in wrangler for next week? ready for review? Think @craigsdennis trying to build something using new binding |
258b887
to
fe1b31d
Compare
@irvinebroque only now i could finish the pr, because workerd was only released this morning |
I'm not sure if miniflare needs to be released first, as this wrangler changes depends on a miniflare release |
Think PR description would help here as took a sec to wrap my head around why this needed to refactor bit of Miniflare. Tests fail only with your changes or also with latest workerd? Have you dug in? Bumped here to test: #5451
https://github.com/cloudflare/workers-sdk/blob/main/packages/miniflare/test/index.spec.ts#L1177 https://github.com/cloudflare/workers-sdk/blob/main/packages/miniflare/test/index.spec.ts#L19 https://github.com/cloudflare/workers-sdk/blob/main/packages/miniflare/test/index.spec.ts#L1156 |
Tests fail without the Miniflare changes, just when bumping workerd to latest. |
Believe cloudflare/workerd@5a4beaa is the only Queues related commit that went out in latest workerd release. @sesteves — not totally sure if cause, but wanted to flag |
#5455 should bump |
@@ -117,6 +121,7 @@ export interface ConfigBundle { | |||
upstreamProtocol: "http" | "https"; | |||
inspect: boolean; | |||
serviceBindings: Record<string, (_request: Request) => Promise<Response>>; | |||
wrappedBindings?: Record<string, object>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrappedBindings?: Record<string, object>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -262,6 +267,7 @@ type MiniflareBindingsConfig = Pick< | |||
| "queueConsumers" | |||
| "name" | |||
| "serviceBindings" | |||
| "wrappedBindings" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "wrappedBindings" |
...but add this to the Pick
for WorkerOptionsBindings
above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
if (!config.wrappedBindings) { | ||
config.wrappedBindings = {}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, we shouldn't be mutating the config
object passed in here. Instead, I would construct an empty wrappedBindings
object above this if
block with the type WorkerOptions["wrappedBindings"]
, then modify that here if AI is enabled:
const wrappedBindings: WorkerOptions["wrappedBindings"] = {};
if (bindings.ai?.binding) {
// ...
wrappedBindings[bindings.ai.binding] = {
scriptName: EXTERNAL_AI_WORKER_NAME,
};
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed and done
fe1b31d
to
60b392c
Compare
60b392c
to
a774a97
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5371 +/- ##
==========================================
+ Coverage 72.15% 72.27% +0.12%
==========================================
Files 326 326
Lines 16848 16853 +5
Branches 4311 4311
==========================================
+ Hits 12156 12180 +24
+ Misses 4692 4673 -19
|
Thanks, i've rebased the pr, implemented the suggestions and tests are now passing 👍 |
Co-authored-by: MrBBot <me@mrbbot.dev>
301eb02
to
c49bf87
Compare
Hey @mrbbot i don't have permissions to merge this pr, can you merge it please? |
What this PR solves / how to test
Adds native binding for workers ai.
CR-852557
Author has addressed the following