Skip to content

Commit

Permalink
cloudflare[minor]: use native Cloudflare Workers AI binding (#5287)
Browse files Browse the repository at this point in the history
Co-authored-by: Brace Sproul <braceasproul@gmail.com>
Co-authored-by: jacoblee93 <jacoblee93@gmail.com>
  • Loading branch information
3 people authored Sep 11, 2024
1 parent 07c0268 commit 68910a7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion langchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@
"@aws-sdk/types": "^3.357.0",
"@azure/storage-blob": "^12.15.0",
"@browserbasehq/sdk": "^1.1.5",
"@cloudflare/workers-types": "^4.20230922.0",
"@cloudflare/workers-types": "^4.20240909.0",
"@faker-js/faker": "^7.6.0",
"@gomomento/sdk": "^1.51.1",
"@gomomento/sdk-core": "^1.51.1",
Expand Down
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",
"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.20240909.0",
"@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;

/**
* 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
20 changes: 6 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8473,24 +8473,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.20240909.0":
version: 4.20240909.0
resolution: "@cloudflare/workers-types@npm:4.20240909.0"
checksum: 82fe9b22510d6a23533830684018651bf8a679692cc487cf82d15816e4c91b95ca5e759a6702d6b1268cd93cda8f0b45f3bf9e6ac27e926112ed4f3c7ef65968
languageName: node
linkType: hard

Expand Down Expand Up @@ -11113,8 +11106,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.20240909.0
"@jest/globals": ^29.5.0
"@langchain/core": ">0.1.0 <0.3.0"
"@langchain/langgraph": ~0.0.31
Expand Down Expand Up @@ -32219,7 +32211,7 @@ __metadata:
"@aws-sdk/types": ^3.357.0
"@azure/storage-blob": ^12.15.0
"@browserbasehq/sdk": ^1.1.5
"@cloudflare/workers-types": ^4.20230922.0
"@cloudflare/workers-types": ^4.20240909.0
"@faker-js/faker": ^7.6.0
"@gomomento/sdk": ^1.51.1
"@gomomento/sdk-core": ^1.51.1
Expand Down

0 comments on commit 68910a7

Please sign in to comment.