langchain 0.0.179 → 0.0.180

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.
Files changed (46) hide show
  1. package/chat_models/bedrock/web.cjs +1 -0
  2. package/chat_models/bedrock/web.d.ts +1 -0
  3. package/chat_models/bedrock/web.js +1 -0
  4. package/chat_models/bedrock.cjs +1 -1
  5. package/chat_models/bedrock.d.ts +1 -1
  6. package/chat_models/bedrock.js +1 -1
  7. package/dist/chains/combine_documents/reduce.cjs +3 -1
  8. package/dist/chains/combine_documents/reduce.js +3 -1
  9. package/dist/chat_models/baiduwenxin.cjs +16 -2
  10. package/dist/chat_models/baiduwenxin.js +16 -2
  11. package/dist/chat_models/bedrock/index.cjs +24 -0
  12. package/dist/chat_models/bedrock/index.d.ts +12 -0
  13. package/dist/chat_models/bedrock/index.js +18 -0
  14. package/dist/chat_models/{bedrock.cjs → bedrock/web.cjs} +44 -15
  15. package/dist/chat_models/{bedrock.d.ts → bedrock/web.d.ts} +14 -5
  16. package/dist/chat_models/{bedrock.js → bedrock/web.js} +42 -13
  17. package/dist/llms/bedrock/index.cjs +17 -0
  18. package/dist/llms/bedrock/index.d.ts +7 -0
  19. package/dist/llms/bedrock/index.js +13 -0
  20. package/dist/llms/{bedrock.cjs → bedrock/web.cjs} +46 -12
  21. package/dist/llms/{bedrock.d.ts → bedrock/web.d.ts} +17 -4
  22. package/dist/llms/{bedrock.js → bedrock/web.js} +46 -12
  23. package/dist/load/import_constants.cjs +3 -0
  24. package/dist/load/import_constants.js +3 -0
  25. package/dist/stores/message/cassandra.cjs +135 -0
  26. package/dist/stores/message/cassandra.d.ts +44 -0
  27. package/dist/stores/message/cassandra.js +131 -0
  28. package/dist/util/bedrock.cjs +13 -1
  29. package/dist/util/bedrock.d.ts +5 -2
  30. package/dist/util/bedrock.js +13 -1
  31. package/dist/vectorstores/cassandra.cjs +197 -47
  32. package/dist/vectorstores/cassandra.d.ts +47 -4
  33. package/dist/vectorstores/cassandra.js +197 -47
  34. package/llms/bedrock/web.cjs +1 -0
  35. package/llms/bedrock/web.d.ts +1 -0
  36. package/llms/bedrock/web.js +1 -0
  37. package/llms/bedrock.cjs +1 -1
  38. package/llms/bedrock.d.ts +1 -1
  39. package/llms/bedrock.js +1 -1
  40. package/package.json +25 -1
  41. package/stores/message/cassandra.cjs +1 -0
  42. package/stores/message/cassandra.d.ts +1 -0
  43. package/stores/message/cassandra.js +1 -0
  44. package/dist/schema/runnable/remote.cjs +0 -225
  45. package/dist/schema/runnable/remote.d.ts +0 -28
  46. package/dist/schema/runnable/remote.js +0 -221
@@ -1,221 +0,0 @@
1
- import { Runnable } from "./base.js";
2
- import { IterableReadableStream } from "../../util/stream.js";
3
- import { getBytes, getLines, getMessages, } from "../../util/event-source-parse.js";
4
- import { Document } from "../../document.js";
5
- import { AIMessage, AIMessageChunk, ChatMessage, ChatMessageChunk, FunctionMessage, FunctionMessageChunk, HumanMessage, HumanMessageChunk, SystemMessage, SystemMessageChunk, } from "../index.js";
6
- import { StringPromptValue } from "../../prompts/base.js";
7
- import { ChatPromptValue } from "../../prompts/chat.js";
8
- function isSuperset(set, subset) {
9
- for (const elem of subset) {
10
- if (!set.has(elem)) {
11
- return false;
12
- }
13
- }
14
- return true;
15
- }
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
- function revive(obj) {
18
- if (Array.isArray(obj))
19
- return obj.map(revive);
20
- if (typeof obj === "object") {
21
- const keysArr = Object.keys(obj);
22
- const keys = new Set(keysArr);
23
- if (isSuperset(keys, new Set(["page_content", "metadata"])))
24
- return new Document({
25
- pageContent: obj.page_content,
26
- metadata: obj.metadata,
27
- });
28
- if (isSuperset(keys, new Set(["content", "type", "is_chunk"]))) {
29
- if (!obj.is_chunk) {
30
- if (obj.type === "human") {
31
- return new HumanMessage({
32
- content: obj.content,
33
- });
34
- }
35
- if (obj.type === "system") {
36
- return new SystemMessage({
37
- content: obj.content,
38
- });
39
- }
40
- if (obj.type === "chat") {
41
- return new ChatMessage({
42
- content: obj.content,
43
- role: obj.role,
44
- });
45
- }
46
- if (obj.type === "function") {
47
- return new FunctionMessage({
48
- content: obj.content,
49
- name: obj.name,
50
- });
51
- }
52
- if (obj.type === "ai") {
53
- return new AIMessage({
54
- content: obj.content,
55
- });
56
- }
57
- }
58
- else {
59
- if (obj.type === "human") {
60
- return new HumanMessageChunk({
61
- content: obj.content,
62
- });
63
- }
64
- if (obj.type === "system") {
65
- return new SystemMessageChunk({
66
- content: obj.content,
67
- });
68
- }
69
- if (obj.type === "chat") {
70
- return new ChatMessageChunk({
71
- content: obj.content,
72
- role: obj.role,
73
- });
74
- }
75
- if (obj.type === "function") {
76
- return new FunctionMessageChunk({
77
- content: obj.content,
78
- name: obj.name,
79
- });
80
- }
81
- if (obj.type === "ai") {
82
- return new AIMessageChunk({
83
- content: obj.content,
84
- });
85
- }
86
- }
87
- }
88
- if (isSuperset(keys, new Set(["text"]))) {
89
- return new StringPromptValue(obj.text);
90
- }
91
- if (isSuperset(keys, new Set(["messages"]))) {
92
- return new ChatPromptValue({
93
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
- messages: obj.messages.map((msg) => revive(msg)),
95
- });
96
- }
97
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
98
- const innerRevive = (key) => [
99
- key,
100
- revive(obj[key]),
101
- ];
102
- const rtn = Object.fromEntries(keysArr.map(innerRevive));
103
- return rtn;
104
- }
105
- return obj;
106
- }
107
- function deserialize(str) {
108
- const obj = JSON.parse(str);
109
- return revive(obj);
110
- }
111
- function removeCallbacks(options) {
112
- const rest = { ...options };
113
- delete rest.callbacks;
114
- return rest;
115
- }
116
- export class RemoteRunnable extends Runnable {
117
- constructor(fields) {
118
- super(fields);
119
- Object.defineProperty(this, "url", {
120
- enumerable: true,
121
- configurable: true,
122
- writable: true,
123
- value: void 0
124
- });
125
- Object.defineProperty(this, "options", {
126
- enumerable: true,
127
- configurable: true,
128
- writable: true,
129
- value: void 0
130
- });
131
- Object.defineProperty(this, "lc_namespace", {
132
- enumerable: true,
133
- configurable: true,
134
- writable: true,
135
- value: ["langchain", "schema", "runnable", "remote"]
136
- });
137
- const { url, options } = fields;
138
- this.url = url.replace(/\/$/, ""); // remove trailing slash
139
- this.options = options;
140
- }
141
- async post(path, body) {
142
- return await fetch(`${this.url}${path}`, {
143
- method: "POST",
144
- body: JSON.stringify(body),
145
- headers: {
146
- "Content-Type": "application/json",
147
- },
148
- signal: AbortSignal.timeout(this.options?.timeout ?? 5000),
149
- });
150
- }
151
- async invoke(input, options) {
152
- const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
153
- const response = await this.post("/invoke", {
154
- input,
155
- config: removeCallbacks(config),
156
- kwargs: kwargs ?? {},
157
- });
158
- return revive((await response.json()).output);
159
- }
160
- async _batch(inputs, options, _, batchOptions) {
161
- if (batchOptions?.returnExceptions) {
162
- throw new Error("returnExceptions is not supported for remote clients");
163
- }
164
- const configsAndKwargsArray = options?.map((opts) => this._separateRunnableConfigFromCallOptions(opts));
165
- const [configs, kwargs] = configsAndKwargsArray?.reduce(([pc, pk], [c, k]) => [
166
- [...pc, c],
167
- [...pk, k],
168
- ], [[], []]) ?? [[], []];
169
- const response = await this.post("/batch", {
170
- inputs,
171
- config: (configs ?? [])
172
- .map(removeCallbacks)
173
- .map((config) => ({ ...config, ...batchOptions })),
174
- kwargs,
175
- });
176
- const body = await response.json();
177
- if (!body.output)
178
- throw new Error("Invalid response from remote runnable");
179
- return revive(body.output);
180
- }
181
- async batch(inputs, options, batchOptions) {
182
- if (batchOptions?.returnExceptions) {
183
- throw Error("returnExceptions is not supported for remote clients");
184
- }
185
- return this._batchWithConfig(this._batch.bind(this), inputs, options, batchOptions);
186
- }
187
- async stream(input, options) {
188
- const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
189
- const response = await this.post("/stream", {
190
- input,
191
- config,
192
- kwargs,
193
- });
194
- if (!response.ok) {
195
- const json = await response.json();
196
- const error = new Error(`RemoteRunnable call failed with status code ${response.status}: ${json.message}`);
197
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
198
- error.response = response;
199
- throw error;
200
- }
201
- const { body } = response;
202
- if (!body) {
203
- throw new Error("Could not begin remote stream. Please check the given URL and try again.");
204
- }
205
- const stream = new ReadableStream({
206
- async start(controller) {
207
- const enqueueLine = getMessages((msg) => {
208
- if (msg.data)
209
- controller.enqueue(deserialize(msg.data));
210
- });
211
- const onLine = (line, fieldLength, flush) => {
212
- enqueueLine(line, fieldLength, flush);
213
- if (flush)
214
- controller.close();
215
- };
216
- await getBytes(body, getLines(onLine));
217
- },
218
- });
219
- return IterableReadableStream.fromReadableStream(stream);
220
- }
221
- }