-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
cloudflare[minor]: use native Cloudflare Workers AI binding #5287
base: main
Are you sure you want to change the base?
Changes from all commits
4b91921
e19caaa
f96a244
0342a20
ec86a33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,12 +35,11 @@ | |
"author": "LangChain", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@cloudflare/ai": "^1.0.47", | ||
"@langchain/core": ">0.1.0 <0.3.0", | ||
"uuid": "^9.0.1" | ||
}, | ||
"devDependencies": { | ||
"@cloudflare/workers-types": "^4.20231218.0", | ||
"@cloudflare/workers-types": "^4.20240502.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're replacing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"@jest/globals": "^29.5.0", | ||
"@langchain/scripts": "~0.0.14", | ||
"@langchain/standard-tests": "workspace:*", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import { Ai } from "@cloudflare/ai"; | ||
import { Fetcher } from "@cloudflare/workers-types"; | ||
import { Ai } from "@cloudflare/workers-types"; | ||
import { Embeddings, EmbeddingsParams } from "@langchain/core/embeddings"; | ||
import { chunkArray } from "@langchain/core/utils/chunk_array"; | ||
|
||
|
@@ -14,7 +13,7 @@ type AiTextEmbeddingsOutput = { | |
|
||
export interface CloudflareWorkersAIEmbeddingsParams extends EmbeddingsParams { | ||
/** Binding */ | ||
binding: Fetcher; | ||
binding: Ai; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be a breaking change. Instead of this we should deprecate the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, good thoughts. The confusion here might come from the fact that the new AI binding is more of a binding than the old one (the old one is often referred to as a "wrapped binding" in the cf dev ecosystem), so I don't have a good name for this. Do you have a suggestion for what this could be called? Or would it make sense to just cut a breaking change given how this is in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, let's make this a minor version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense to me! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this also break people using this outside Cloudflare Workers? We'll also want to update the docs but I can take care of that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The external usage outside of Cloudflare Workers seems to be in https://github.com/Cherry/langchainjs/blob/4b9192176440b4acab9eac60a140200640d8bee2/libs/langchain-cloudflare/src/chat_models.ts#L78, which hasn't changed. This update to the |
||
|
||
/** | ||
* Model name to use | ||
|
@@ -57,7 +56,7 @@ export class CloudflareWorkersAIEmbeddings extends Embeddings { | |
"Must supply a Workers AI binding, eg { binding: env.AI }" | ||
); | ||
} | ||
this.ai = new Ai(fields.binding); | ||
this.ai = fields.binding; | ||
this.modelName = fields?.model ?? fields.modelName ?? this.model; | ||
this.model = this.modelName; | ||
this.stripNewLines = fields.stripNewLines ?? this.stripNewLines; | ||
|
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.
Hey there! I noticed that this PR includes a change in dependencies, specifically the removal of "@cloudflare/ai" as a hard dependency and an update to the version of "@cloudflare/workers-types" as a dev dependency. I'm flagging this for your review to ensure it aligns with our dependency management strategy. Thanks!