langchain 0.0.188 → 0.0.189

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,12 +27,6 @@ class CohereEmbeddings extends base_js_1.Embeddings {
27
27
  writable: true,
28
28
  value: 48
29
29
  });
30
- Object.defineProperty(this, "inputType", {
31
- enumerable: true,
32
- configurable: true,
33
- writable: true,
34
- value: void 0
35
- });
36
30
  Object.defineProperty(this, "apiKey", {
37
31
  enumerable: true,
38
32
  configurable: true,
@@ -51,7 +45,6 @@ class CohereEmbeddings extends base_js_1.Embeddings {
51
45
  }
52
46
  this.modelName = fieldsWithDefaults?.modelName ?? this.modelName;
53
47
  this.batchSize = fieldsWithDefaults?.batchSize ?? this.batchSize;
54
- this.inputType = fieldsWithDefaults?.inputType;
55
48
  this.apiKey = apiKey;
56
49
  }
57
50
  /**
@@ -65,15 +58,14 @@ class CohereEmbeddings extends base_js_1.Embeddings {
65
58
  const batchRequests = batches.map((batch) => this.embeddingWithRetry({
66
59
  model: this.modelName,
67
60
  texts: batch,
68
- inputType: this.inputType,
69
61
  }));
70
62
  const batchResponses = await Promise.all(batchRequests);
71
63
  const embeddings = [];
72
64
  for (let i = 0; i < batchResponses.length; i += 1) {
73
65
  const batch = batches[i];
74
- const { embeddings: batchResponse } = batchResponses[i];
66
+ const { body: batchResponse } = batchResponses[i];
75
67
  for (let j = 0; j < batch.length; j += 1) {
76
- embeddings.push(batchResponse[j]);
68
+ embeddings.push(batchResponse.embeddings[j]);
77
69
  }
78
70
  }
79
71
  return embeddings;
@@ -85,11 +77,11 @@ class CohereEmbeddings extends base_js_1.Embeddings {
85
77
  */
86
78
  async embedQuery(text) {
87
79
  await this.maybeInitClient();
88
- const { embeddings } = await this.embeddingWithRetry({
80
+ const { body } = await this.embeddingWithRetry({
89
81
  model: this.modelName,
90
82
  texts: [text],
91
83
  });
92
- return embeddings[0];
84
+ return body.embeddings[0];
93
85
  }
94
86
  /**
95
87
  * Generates embeddings with retry capabilities.
@@ -105,17 +97,16 @@ class CohereEmbeddings extends base_js_1.Embeddings {
105
97
  */
106
98
  async maybeInitClient() {
107
99
  if (!this.client) {
108
- const { CohereClient } = await CohereEmbeddings.imports();
109
- this.client = new CohereClient({
110
- token: this.apiKey,
111
- });
100
+ const { cohere } = await CohereEmbeddings.imports();
101
+ this.client = cohere;
102
+ this.client.init(this.apiKey);
112
103
  }
113
104
  }
114
105
  /** @ignore */
115
106
  static async imports() {
116
107
  try {
117
- const { CohereClient } = await import("cohere-ai");
118
- return { CohereClient };
108
+ const { default: cohere } = await import("cohere-ai");
109
+ return { cohere };
119
110
  }
120
111
  catch (e) {
121
112
  throw new Error("Please install cohere-ai as a dependency with, e.g. `yarn add cohere-ai`");
@@ -10,17 +10,6 @@ export interface CohereEmbeddingsParams extends EmbeddingsParams {
10
10
  * limited by the Cohere API to a maximum of 96.
11
11
  */
12
12
  batchSize?: number;
13
- /**
14
- * Specifies the type of input you're giving to the model.
15
- * Not required for older versions of the embedding models (i.e. anything lower than v3),
16
- * but is required for more recent versions (i.e. anything bigger than v2).
17
- *
18
- * * `search_document` - Use this when you encode documents for embeddings that you store in a vector database for search use-cases.
19
- * * `search_query` - Use this when you query your vector DB to find relevant documents.
20
- * * `classification` - Use this when you use the embeddings as an input to a text classifier.
21
- * * `clustering` - Use this when you want to cluster the embeddings.
22
- */
23
- inputType?: string;
24
13
  }
25
14
  /**
26
15
  * A class for generating embeddings using the Cohere API.
@@ -28,7 +17,6 @@ export interface CohereEmbeddingsParams extends EmbeddingsParams {
28
17
  export declare class CohereEmbeddings extends Embeddings implements CohereEmbeddingsParams {
29
18
  modelName: string;
30
19
  batchSize: number;
31
- inputType: string | undefined;
32
20
  private apiKey;
33
21
  private client;
34
22
  /**
@@ -63,6 +51,6 @@ export declare class CohereEmbeddings extends Embeddings implements CohereEmbedd
63
51
  private maybeInitClient;
64
52
  /** @ignore */
65
53
  static imports(): Promise<{
66
- CohereClient: typeof import("cohere-ai").CohereClient;
54
+ cohere: typeof import("cohere-ai");
67
55
  }>;
68
56
  }
@@ -24,12 +24,6 @@ export class CohereEmbeddings extends Embeddings {
24
24
  writable: true,
25
25
  value: 48
26
26
  });
27
- Object.defineProperty(this, "inputType", {
28
- enumerable: true,
29
- configurable: true,
30
- writable: true,
31
- value: void 0
32
- });
33
27
  Object.defineProperty(this, "apiKey", {
34
28
  enumerable: true,
35
29
  configurable: true,
@@ -48,7 +42,6 @@ export class CohereEmbeddings extends Embeddings {
48
42
  }
49
43
  this.modelName = fieldsWithDefaults?.modelName ?? this.modelName;
50
44
  this.batchSize = fieldsWithDefaults?.batchSize ?? this.batchSize;
51
- this.inputType = fieldsWithDefaults?.inputType;
52
45
  this.apiKey = apiKey;
53
46
  }
54
47
  /**
@@ -62,15 +55,14 @@ export class CohereEmbeddings extends Embeddings {
62
55
  const batchRequests = batches.map((batch) => this.embeddingWithRetry({
63
56
  model: this.modelName,
64
57
  texts: batch,
65
- inputType: this.inputType,
66
58
  }));
67
59
  const batchResponses = await Promise.all(batchRequests);
68
60
  const embeddings = [];
69
61
  for (let i = 0; i < batchResponses.length; i += 1) {
70
62
  const batch = batches[i];
71
- const { embeddings: batchResponse } = batchResponses[i];
63
+ const { body: batchResponse } = batchResponses[i];
72
64
  for (let j = 0; j < batch.length; j += 1) {
73
- embeddings.push(batchResponse[j]);
65
+ embeddings.push(batchResponse.embeddings[j]);
74
66
  }
75
67
  }
76
68
  return embeddings;
@@ -82,11 +74,11 @@ export class CohereEmbeddings extends Embeddings {
82
74
  */
83
75
  async embedQuery(text) {
84
76
  await this.maybeInitClient();
85
- const { embeddings } = await this.embeddingWithRetry({
77
+ const { body } = await this.embeddingWithRetry({
86
78
  model: this.modelName,
87
79
  texts: [text],
88
80
  });
89
- return embeddings[0];
81
+ return body.embeddings[0];
90
82
  }
91
83
  /**
92
84
  * Generates embeddings with retry capabilities.
@@ -102,17 +94,16 @@ export class CohereEmbeddings extends Embeddings {
102
94
  */
103
95
  async maybeInitClient() {
104
96
  if (!this.client) {
105
- const { CohereClient } = await CohereEmbeddings.imports();
106
- this.client = new CohereClient({
107
- token: this.apiKey,
108
- });
97
+ const { cohere } = await CohereEmbeddings.imports();
98
+ this.client = cohere;
99
+ this.client.init(this.apiKey);
109
100
  }
110
101
  }
111
102
  /** @ignore */
112
103
  static async imports() {
113
104
  try {
114
- const { CohereClient } = await import("cohere-ai");
115
- return { CohereClient };
105
+ const { default: cohere } = await import("cohere-ai");
106
+ return { cohere };
116
107
  }
117
108
  catch (e) {
118
109
  throw new Error("Please install cohere-ai as a dependency with, e.g. `yarn add cohere-ai`");
@@ -67,20 +67,18 @@ class Cohere extends base_js_1.LLM {
67
67
  }
68
68
  /** @ignore */
69
69
  async _call(prompt, options) {
70
- const { CohereClient } = await Cohere.imports();
71
- const cohere = new CohereClient({
72
- token: this.apiKey,
73
- });
70
+ const { cohere } = await Cohere.imports();
71
+ cohere.init(this.apiKey);
74
72
  // Hit the `generate` endpoint on the `large` model
75
73
  const generateResponse = await this.caller.callWithOptions({ signal: options.signal }, cohere.generate.bind(cohere), {
76
74
  prompt,
77
75
  model: this.model,
78
- maxTokens: this.maxTokens,
76
+ max_tokens: this.maxTokens,
79
77
  temperature: this.temperature,
80
- endSequences: options.stop,
78
+ end_sequences: options.stop,
81
79
  });
82
80
  try {
83
- return generateResponse.generations[0].text;
81
+ return generateResponse.body.generations[0].text;
84
82
  }
85
83
  catch {
86
84
  console.log(generateResponse);
@@ -90,8 +88,8 @@ class Cohere extends base_js_1.LLM {
90
88
  /** @ignore */
91
89
  static async imports() {
92
90
  try {
93
- const { CohereClient } = await import("cohere-ai");
94
- return { CohereClient };
91
+ const { default: cohere } = await import("cohere-ai");
92
+ return { cohere };
95
93
  }
96
94
  catch (e) {
97
95
  throw new Error("Please install cohere-ai as a dependency with, e.g. `yarn add cohere-ai`");
@@ -36,6 +36,6 @@ export declare class Cohere extends LLM implements CohereInput {
36
36
  _call(prompt: string, options: this["ParsedCallOptions"]): Promise<string>;
37
37
  /** @ignore */
38
38
  static imports(): Promise<{
39
- CohereClient: typeof import("cohere-ai").CohereClient;
39
+ cohere: typeof import("cohere-ai");
40
40
  }>;
41
41
  }
@@ -64,20 +64,18 @@ export class Cohere extends LLM {
64
64
  }
65
65
  /** @ignore */
66
66
  async _call(prompt, options) {
67
- const { CohereClient } = await Cohere.imports();
68
- const cohere = new CohereClient({
69
- token: this.apiKey,
70
- });
67
+ const { cohere } = await Cohere.imports();
68
+ cohere.init(this.apiKey);
71
69
  // Hit the `generate` endpoint on the `large` model
72
70
  const generateResponse = await this.caller.callWithOptions({ signal: options.signal }, cohere.generate.bind(cohere), {
73
71
  prompt,
74
72
  model: this.model,
75
- maxTokens: this.maxTokens,
73
+ max_tokens: this.maxTokens,
76
74
  temperature: this.temperature,
77
- endSequences: options.stop,
75
+ end_sequences: options.stop,
78
76
  });
79
77
  try {
80
- return generateResponse.generations[0].text;
78
+ return generateResponse.body.generations[0].text;
81
79
  }
82
80
  catch {
83
81
  console.log(generateResponse);
@@ -87,8 +85,8 @@ export class Cohere extends LLM {
87
85
  /** @ignore */
88
86
  static async imports() {
89
87
  try {
90
- const { CohereClient } = await import("cohere-ai");
91
- return { CohereClient };
88
+ const { default: cohere } = await import("cohere-ai");
89
+ return { cohere };
92
90
  }
93
91
  catch (e) {
94
92
  throw new Error("Please install cohere-ai as a dependency with, e.g. `yarn add cohere-ai`");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langchain",
3
- "version": "0.0.188",
3
+ "version": "0.0.189",
4
4
  "description": "Typescript bindings for langchain",
5
5
  "type": "module",
6
6
  "engines": {
@@ -902,7 +902,7 @@
902
902
  "closevector-common": "0.1.0-alpha.1",
903
903
  "closevector-node": "0.1.0-alpha.10",
904
904
  "closevector-web": "0.1.0-alpha.15",
905
- "cohere-ai": "^7.2.0",
905
+ "cohere-ai": ">=6.0.0",
906
906
  "convex": "^1.3.1",
907
907
  "d3-dsv": "^2.0.0",
908
908
  "dotenv": "^16.0.3",
@@ -1020,7 +1020,7 @@
1020
1020
  "closevector-common": "0.1.0-alpha.1",
1021
1021
  "closevector-node": "0.1.0-alpha.10",
1022
1022
  "closevector-web": "0.1.0-alpha.16",
1023
- "cohere-ai": "^7.2.0",
1023
+ "cohere-ai": ">=6.0.0",
1024
1024
  "convex": "^1.3.1",
1025
1025
  "d3-dsv": "^2.0.0",
1026
1026
  "epub2": "^3.0.1",