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

cloudflare[minor]: use native Cloudflare Workers AI binding #5287

Merged
merged 12 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions libs/langchain-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@
"author": "LangChain",
Copy link

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!

"license": "MIT",
"dependencies": {
"@cloudflare/ai": "1.0.47",
"@langchain/core": ">0.1.0 <0.3.0",
"uuid": "^10.0.0"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20231218.0",
"@cloudflare/workers-types": "^4.20240502.0",
jacoblee93 marked this conversation as resolved.
Show resolved Hide resolved
"@jest/globals": "^29.5.0",
"@langchain/langgraph": "~0.0.31",
"@langchain/scripts": ">=0.1.0 <0.2.0",
Expand Down
7 changes: 3 additions & 4 deletions libs/langchain-cloudflare/src/embeddings.ts
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";

Expand All @@ -14,7 +13,7 @@ type AiTextEmbeddingsOutput = {

export interface CloudflareWorkersAIEmbeddingsParams extends EmbeddingsParams {
/** Binding */
binding: Fetcher;
binding: Ai;

jacoblee93 marked this conversation as resolved.
Show resolved Hide resolved
/**
* Model name to use
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 5 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8432,24 +8432,17 @@ __metadata:
languageName: node
linkType: hard

"@cloudflare/ai@npm:1.0.47":
version: 1.0.47
resolution: "@cloudflare/ai@npm:1.0.47"
checksum: a9e371f789256bb5795c0cb60d975749b07d6cb50141b997da6b5c94380ddf18e851cba518e246414fcab4239d8f4438c5fe29172e6f06c136be3be19a3b65e0
languageName: node
linkType: hard

"@cloudflare/workers-types@npm:^4.20230922.0":
version: 4.20230922.0
resolution: "@cloudflare/workers-types@npm:4.20230922.0"
checksum: 629bab47cdbcb74e3c42fc9486f5186734b6dd734154cea7a0983ad83ee053b4fb1ae13ff618a7287612bc3b3d19ad72d6a34a84289a903623cb8a13af57596b
languageName: node
linkType: hard

"@cloudflare/workers-types@npm:^4.20231218.0":
version: 4.20231218.0
resolution: "@cloudflare/workers-types@npm:4.20231218.0"
checksum: b7e50a76ee8e9d662227bbb74798b93b6102acc224f1071a9c99a9adb419ad0b3bdabf7561e7e1b4a320a6a4616badeecdfb1848fbdaada197c7b37d845b8774
"@cloudflare/workers-types@npm:^4.20240502.0":
version: 4.20240512.0
resolution: "@cloudflare/workers-types@npm:4.20240512.0"
checksum: 4a8671a7884c75a305b064c34470e7fb09ab2c967a9388be6bc046030d6ad4e46a2ca9e92288c2eb6d49624e357683f0e1f4bd0d2de1f540a9964635faf87a3b
languageName: node
linkType: hard

Expand Down Expand Up @@ -11071,8 +11064,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@langchain/cloudflare@workspace:libs/langchain-cloudflare"
dependencies:
"@cloudflare/ai": 1.0.47
"@cloudflare/workers-types": ^4.20231218.0
"@cloudflare/workers-types": ^4.20240502.0
"@jest/globals": ^29.5.0
"@langchain/core": ">0.1.0 <0.3.0"
"@langchain/langgraph": ~0.0.31
Expand Down
Loading