langchain 0.0.164 → 0.0.166
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.
- package/chat_models/portkey.cjs +1 -0
- package/chat_models/portkey.d.ts +1 -0
- package/chat_models/portkey.js +1 -0
- package/dist/cache/momento.cjs +7 -7
- package/dist/cache/momento.d.ts +1 -1
- package/dist/cache/momento.js +1 -1
- package/dist/chat_models/portkey.cjs +159 -0
- package/dist/chat_models/portkey.d.ts +17 -0
- package/dist/chat_models/portkey.js +155 -0
- package/dist/document_loaders/fs/unstructured.cjs +40 -0
- package/dist/document_loaders/fs/unstructured.d.ts +27 -0
- package/dist/document_loaders/fs/unstructured.js +40 -0
- package/dist/embeddings/minimax.cjs +1 -1
- package/dist/embeddings/minimax.js +1 -1
- package/dist/experimental/chat_models/anthropic_functions.cjs +34 -2
- package/dist/experimental/chat_models/anthropic_functions.d.ts +15 -5
- package/dist/experimental/chat_models/anthropic_functions.js +34 -2
- package/dist/llms/portkey.cjs +147 -0
- package/dist/llms/portkey.d.ts +33 -0
- package/dist/llms/portkey.js +138 -0
- package/dist/llms/sagemaker_endpoint.cjs +76 -14
- package/dist/llms/sagemaker_endpoint.d.ts +39 -20
- package/dist/llms/sagemaker_endpoint.js +77 -15
- package/dist/load/import_constants.cjs +4 -0
- package/dist/load/import_constants.js +4 -0
- package/dist/load/import_map.cjs +3 -1
- package/dist/load/import_map.d.ts +2 -0
- package/dist/load/import_map.js +2 -0
- package/dist/output_parsers/list.cjs +1 -1
- package/dist/output_parsers/list.js +1 -1
- package/dist/prompts/chat.cjs +19 -2
- package/dist/prompts/chat.d.ts +1 -0
- package/dist/prompts/chat.js +19 -2
- package/dist/retrievers/self_query/base.cjs +4 -1
- package/dist/retrievers/self_query/base.d.ts +3 -2
- package/dist/retrievers/self_query/base.js +4 -1
- package/dist/retrievers/self_query/index.cjs +2 -2
- package/dist/retrievers/self_query/index.d.ts +2 -0
- package/dist/retrievers/self_query/index.js +2 -2
- package/dist/runnables/remote.cjs +225 -0
- package/dist/runnables/remote.d.ts +28 -0
- package/dist/runnables/remote.js +221 -0
- package/dist/schema/index.cjs +1 -1
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/index.js +1 -1
- package/dist/schema/runnable/base.cjs +4 -4
- package/dist/schema/runnable/base.d.ts +9 -7
- package/dist/schema/runnable/base.js +4 -4
- package/dist/schema/runnable/remote.cjs +225 -0
- package/dist/schema/runnable/remote.d.ts +28 -0
- package/dist/schema/runnable/remote.js +221 -0
- package/dist/stores/message/momento.cjs +11 -11
- package/dist/stores/message/momento.d.ts +1 -1
- package/dist/stores/message/momento.js +1 -1
- package/dist/util/time.cjs +14 -0
- package/dist/util/time.d.ts +6 -0
- package/dist/util/time.js +10 -0
- package/dist/vectorstores/cassandra.cjs +212 -0
- package/dist/vectorstores/cassandra.d.ts +98 -0
- package/dist/vectorstores/cassandra.js +208 -0
- package/dist/vectorstores/momento_vector_index.cjs +292 -0
- package/dist/vectorstores/momento_vector_index.d.ts +135 -0
- package/dist/vectorstores/momento_vector_index.js +265 -0
- package/dist/vectorstores/mongodb_atlas.cjs +29 -39
- package/dist/vectorstores/mongodb_atlas.js +29 -39
- package/dist/vectorstores/supabase.cjs +37 -8
- package/dist/vectorstores/supabase.d.ts +28 -1
- package/dist/vectorstores/supabase.js +37 -8
- package/llms/portkey.cjs +1 -0
- package/llms/portkey.d.ts +1 -0
- package/llms/portkey.js +1 -0
- package/package.json +77 -4
- package/runnables/remote.cjs +1 -0
- package/runnables/remote.d.ts +1 -0
- package/runnables/remote.js +1 -0
- package/util/time.cjs +1 -0
- package/util/time.d.ts +1 -0
- package/util/time.js +1 -0
- package/vectorstores/cassandra.cjs +1 -0
- package/vectorstores/cassandra.d.ts +1 -0
- package/vectorstores/cassandra.js +1 -0
- package/vectorstores/momento_vector_index.cjs +1 -0
- package/vectorstores/momento_vector_index.d.ts +1 -0
- package/vectorstores/momento_vector_index.js +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/chat_models/portkey.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/chat_models/portkey.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/chat_models/portkey.js'
|
package/dist/cache/momento.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MomentoCache = void 0;
|
|
4
4
|
/* eslint-disable no-instanceof/no-instanceof */
|
|
5
|
-
const
|
|
5
|
+
const sdk_core_1 = require("@gomomento/sdk-core");
|
|
6
6
|
const index_js_1 = require("../schema/index.cjs");
|
|
7
7
|
const base_js_1 = require("./base.cjs");
|
|
8
8
|
const momento_js_1 = require("../util/momento.cjs");
|
|
@@ -62,7 +62,7 @@ class MomentoCache extends index_js_1.BaseCache {
|
|
|
62
62
|
*/
|
|
63
63
|
validateTtlSeconds(ttlSeconds) {
|
|
64
64
|
if (ttlSeconds !== undefined && ttlSeconds <= 0) {
|
|
65
|
-
throw new
|
|
65
|
+
throw new sdk_core_1.InvalidArgumentError("ttlSeconds must be positive.");
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
@@ -74,7 +74,7 @@ class MomentoCache extends index_js_1.BaseCache {
|
|
|
74
74
|
async lookup(prompt, llmKey) {
|
|
75
75
|
const key = (0, base_js_1.getCacheKey)(prompt, llmKey);
|
|
76
76
|
const getResponse = await this.client.get(this.cacheName, key);
|
|
77
|
-
if (getResponse instanceof
|
|
77
|
+
if (getResponse instanceof sdk_core_1.CacheGet.Hit) {
|
|
78
78
|
const value = getResponse.valueString();
|
|
79
79
|
const parsedValue = JSON.parse(value);
|
|
80
80
|
if (!Array.isArray(parsedValue)) {
|
|
@@ -82,10 +82,10 @@ class MomentoCache extends index_js_1.BaseCache {
|
|
|
82
82
|
}
|
|
83
83
|
return JSON.parse(value).map(base_js_1.deserializeStoredGeneration);
|
|
84
84
|
}
|
|
85
|
-
else if (getResponse instanceof
|
|
85
|
+
else if (getResponse instanceof sdk_core_1.CacheGet.Miss) {
|
|
86
86
|
return null;
|
|
87
87
|
}
|
|
88
|
-
else if (getResponse instanceof
|
|
88
|
+
else if (getResponse instanceof sdk_core_1.CacheGet.Error) {
|
|
89
89
|
throw getResponse.innerException();
|
|
90
90
|
}
|
|
91
91
|
else {
|
|
@@ -104,10 +104,10 @@ class MomentoCache extends index_js_1.BaseCache {
|
|
|
104
104
|
async update(prompt, llmKey, value) {
|
|
105
105
|
const key = (0, base_js_1.getCacheKey)(prompt, llmKey);
|
|
106
106
|
const setResponse = await this.client.set(this.cacheName, key, JSON.stringify(value.map(base_js_1.serializeGeneration)), { ttl: this.ttlSeconds });
|
|
107
|
-
if (setResponse instanceof
|
|
107
|
+
if (setResponse instanceof sdk_core_1.CacheSet.Success) {
|
|
108
108
|
// pass
|
|
109
109
|
}
|
|
110
|
-
else if (setResponse instanceof
|
|
110
|
+
else if (setResponse instanceof sdk_core_1.CacheSet.Error) {
|
|
111
111
|
throw setResponse.innerException();
|
|
112
112
|
}
|
|
113
113
|
else {
|
package/dist/cache/momento.d.ts
CHANGED
package/dist/cache/momento.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-instanceof/no-instanceof */
|
|
2
|
-
import { CacheGet, CacheSet, InvalidArgumentError, } from "@gomomento/sdk";
|
|
2
|
+
import { CacheGet, CacheSet, InvalidArgumentError, } from "@gomomento/sdk-core";
|
|
3
3
|
import { BaseCache } from "../schema/index.js";
|
|
4
4
|
import { deserializeStoredGeneration, getCacheKey, serializeGeneration, } from "./base.js";
|
|
5
5
|
import { ensureCacheExists } from "../util/momento.js";
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PortkeyChat = void 0;
|
|
4
|
+
const portkey_js_1 = require("../llms/portkey.cjs");
|
|
5
|
+
const index_js_1 = require("../schema/index.cjs");
|
|
6
|
+
const base_js_1 = require("./base.cjs");
|
|
7
|
+
function portkeyResponseToChatMessage(message) {
|
|
8
|
+
switch (message.role) {
|
|
9
|
+
case "user":
|
|
10
|
+
return new index_js_1.HumanMessage(message.content || "");
|
|
11
|
+
case "assistant":
|
|
12
|
+
return new index_js_1.AIMessage(message.content || "");
|
|
13
|
+
case "system":
|
|
14
|
+
return new index_js_1.SystemMessage(message.content || "");
|
|
15
|
+
default:
|
|
16
|
+
return new index_js_1.ChatMessage(message.content || "", message.role ?? "unknown");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function _convertDeltaToMessageChunk(
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
delta) {
|
|
22
|
+
const { role } = delta;
|
|
23
|
+
const content = delta.content ?? "";
|
|
24
|
+
let additional_kwargs;
|
|
25
|
+
if (delta.function_call) {
|
|
26
|
+
additional_kwargs = {
|
|
27
|
+
function_call: delta.function_call,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
additional_kwargs = {};
|
|
32
|
+
}
|
|
33
|
+
if (role === "user") {
|
|
34
|
+
return new index_js_1.HumanMessageChunk({ content });
|
|
35
|
+
}
|
|
36
|
+
else if (role === "assistant") {
|
|
37
|
+
return new index_js_1.AIMessageChunk({ content, additional_kwargs });
|
|
38
|
+
}
|
|
39
|
+
else if (role === "system") {
|
|
40
|
+
return new index_js_1.SystemMessageChunk({ content });
|
|
41
|
+
}
|
|
42
|
+
else if (role === "function") {
|
|
43
|
+
return new index_js_1.FunctionMessageChunk({
|
|
44
|
+
content,
|
|
45
|
+
additional_kwargs,
|
|
46
|
+
name: delta.name,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return new index_js_1.ChatMessageChunk({ content, role });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
class PortkeyChat extends base_js_1.BaseChatModel {
|
|
54
|
+
constructor(init) {
|
|
55
|
+
super(init ?? {});
|
|
56
|
+
Object.defineProperty(this, "apiKey", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
writable: true,
|
|
60
|
+
value: undefined
|
|
61
|
+
});
|
|
62
|
+
Object.defineProperty(this, "baseURL", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true,
|
|
66
|
+
value: undefined
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(this, "mode", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
configurable: true,
|
|
71
|
+
writable: true,
|
|
72
|
+
value: undefined
|
|
73
|
+
});
|
|
74
|
+
Object.defineProperty(this, "llms", {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
configurable: true,
|
|
77
|
+
writable: true,
|
|
78
|
+
value: undefined
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(this, "session", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
configurable: true,
|
|
83
|
+
writable: true,
|
|
84
|
+
value: void 0
|
|
85
|
+
});
|
|
86
|
+
this.apiKey = init?.apiKey;
|
|
87
|
+
this.baseURL = init?.baseURL;
|
|
88
|
+
this.mode = init?.mode;
|
|
89
|
+
this.llms = init?.llms;
|
|
90
|
+
this.session = (0, portkey_js_1.getPortkeySession)({
|
|
91
|
+
apiKey: this.apiKey,
|
|
92
|
+
baseURL: this.baseURL,
|
|
93
|
+
llms: this.llms,
|
|
94
|
+
mode: this.mode,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
_llmType() {
|
|
98
|
+
return "portkey";
|
|
99
|
+
}
|
|
100
|
+
async _generate(messages, options, _) {
|
|
101
|
+
const messagesList = messages.map((message) => ({
|
|
102
|
+
role: message._getType(),
|
|
103
|
+
content: message.content,
|
|
104
|
+
}));
|
|
105
|
+
const response = await this.session.portkey.chatCompletions.create({
|
|
106
|
+
messages: messagesList,
|
|
107
|
+
...options,
|
|
108
|
+
stream: false,
|
|
109
|
+
});
|
|
110
|
+
const generations = [];
|
|
111
|
+
for (const data of response.choices ?? []) {
|
|
112
|
+
const text = data.message?.content ?? "";
|
|
113
|
+
const generation = {
|
|
114
|
+
text,
|
|
115
|
+
message: portkeyResponseToChatMessage(data.message ?? {}),
|
|
116
|
+
};
|
|
117
|
+
if (data.finish_reason) {
|
|
118
|
+
generation.generationInfo = { finish_reason: data.finish_reason };
|
|
119
|
+
}
|
|
120
|
+
generations.push(generation);
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
generations,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
async *_streamResponseChunks(messages, options, runManager) {
|
|
127
|
+
const messagesList = messages.map((message) => ({
|
|
128
|
+
role: message._getType(),
|
|
129
|
+
content: message.content,
|
|
130
|
+
}));
|
|
131
|
+
const response = await this.session.portkey.chatCompletions.create({
|
|
132
|
+
messages: messagesList,
|
|
133
|
+
...options,
|
|
134
|
+
stream: true,
|
|
135
|
+
});
|
|
136
|
+
for await (const data of response) {
|
|
137
|
+
const choice = data?.choices[0];
|
|
138
|
+
if (!choice) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const chunk = new index_js_1.ChatGenerationChunk({
|
|
142
|
+
message: _convertDeltaToMessageChunk(choice.delta ?? {}),
|
|
143
|
+
text: choice.message?.content ?? "",
|
|
144
|
+
generationInfo: {
|
|
145
|
+
finishReason: choice.finish_reason,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
yield chunk;
|
|
149
|
+
void runManager?.handleLLMNewToken(chunk.text ?? "");
|
|
150
|
+
}
|
|
151
|
+
if (options.signal?.aborted) {
|
|
152
|
+
throw new Error("AbortError");
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
_combineLLMOutput() {
|
|
156
|
+
return {};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.PortkeyChat = PortkeyChat;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LLMOptions } from "portkey-ai";
|
|
2
|
+
import { CallbackManagerForLLMRun } from "../callbacks/manager.js";
|
|
3
|
+
import { PortkeySession } from "../llms/portkey.js";
|
|
4
|
+
import { BaseMessage, ChatGenerationChunk, ChatResult } from "../schema/index.js";
|
|
5
|
+
import { BaseChatModel } from "./base.js";
|
|
6
|
+
export declare class PortkeyChat extends BaseChatModel {
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
baseURL?: string;
|
|
9
|
+
mode?: string;
|
|
10
|
+
llms?: [LLMOptions] | null;
|
|
11
|
+
session: PortkeySession;
|
|
12
|
+
constructor(init?: Partial<PortkeyChat>);
|
|
13
|
+
_llmType(): string;
|
|
14
|
+
_generate(messages: BaseMessage[], options: this["ParsedCallOptions"], _?: CallbackManagerForLLMRun): Promise<ChatResult>;
|
|
15
|
+
_streamResponseChunks(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
16
|
+
_combineLLMOutput(): {};
|
|
17
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { getPortkeySession } from "../llms/portkey.js";
|
|
2
|
+
import { AIMessage, AIMessageChunk, ChatGenerationChunk, ChatMessage, ChatMessageChunk, FunctionMessageChunk, HumanMessage, HumanMessageChunk, SystemMessage, SystemMessageChunk, } from "../schema/index.js";
|
|
3
|
+
import { BaseChatModel } from "./base.js";
|
|
4
|
+
function portkeyResponseToChatMessage(message) {
|
|
5
|
+
switch (message.role) {
|
|
6
|
+
case "user":
|
|
7
|
+
return new HumanMessage(message.content || "");
|
|
8
|
+
case "assistant":
|
|
9
|
+
return new AIMessage(message.content || "");
|
|
10
|
+
case "system":
|
|
11
|
+
return new SystemMessage(message.content || "");
|
|
12
|
+
default:
|
|
13
|
+
return new ChatMessage(message.content || "", message.role ?? "unknown");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function _convertDeltaToMessageChunk(
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
delta) {
|
|
19
|
+
const { role } = delta;
|
|
20
|
+
const content = delta.content ?? "";
|
|
21
|
+
let additional_kwargs;
|
|
22
|
+
if (delta.function_call) {
|
|
23
|
+
additional_kwargs = {
|
|
24
|
+
function_call: delta.function_call,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
additional_kwargs = {};
|
|
29
|
+
}
|
|
30
|
+
if (role === "user") {
|
|
31
|
+
return new HumanMessageChunk({ content });
|
|
32
|
+
}
|
|
33
|
+
else if (role === "assistant") {
|
|
34
|
+
return new AIMessageChunk({ content, additional_kwargs });
|
|
35
|
+
}
|
|
36
|
+
else if (role === "system") {
|
|
37
|
+
return new SystemMessageChunk({ content });
|
|
38
|
+
}
|
|
39
|
+
else if (role === "function") {
|
|
40
|
+
return new FunctionMessageChunk({
|
|
41
|
+
content,
|
|
42
|
+
additional_kwargs,
|
|
43
|
+
name: delta.name,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return new ChatMessageChunk({ content, role });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export class PortkeyChat extends BaseChatModel {
|
|
51
|
+
constructor(init) {
|
|
52
|
+
super(init ?? {});
|
|
53
|
+
Object.defineProperty(this, "apiKey", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: undefined
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(this, "baseURL", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
writable: true,
|
|
63
|
+
value: undefined
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(this, "mode", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: undefined
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(this, "llms", {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
configurable: true,
|
|
74
|
+
writable: true,
|
|
75
|
+
value: undefined
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(this, "session", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
configurable: true,
|
|
80
|
+
writable: true,
|
|
81
|
+
value: void 0
|
|
82
|
+
});
|
|
83
|
+
this.apiKey = init?.apiKey;
|
|
84
|
+
this.baseURL = init?.baseURL;
|
|
85
|
+
this.mode = init?.mode;
|
|
86
|
+
this.llms = init?.llms;
|
|
87
|
+
this.session = getPortkeySession({
|
|
88
|
+
apiKey: this.apiKey,
|
|
89
|
+
baseURL: this.baseURL,
|
|
90
|
+
llms: this.llms,
|
|
91
|
+
mode: this.mode,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
_llmType() {
|
|
95
|
+
return "portkey";
|
|
96
|
+
}
|
|
97
|
+
async _generate(messages, options, _) {
|
|
98
|
+
const messagesList = messages.map((message) => ({
|
|
99
|
+
role: message._getType(),
|
|
100
|
+
content: message.content,
|
|
101
|
+
}));
|
|
102
|
+
const response = await this.session.portkey.chatCompletions.create({
|
|
103
|
+
messages: messagesList,
|
|
104
|
+
...options,
|
|
105
|
+
stream: false,
|
|
106
|
+
});
|
|
107
|
+
const generations = [];
|
|
108
|
+
for (const data of response.choices ?? []) {
|
|
109
|
+
const text = data.message?.content ?? "";
|
|
110
|
+
const generation = {
|
|
111
|
+
text,
|
|
112
|
+
message: portkeyResponseToChatMessage(data.message ?? {}),
|
|
113
|
+
};
|
|
114
|
+
if (data.finish_reason) {
|
|
115
|
+
generation.generationInfo = { finish_reason: data.finish_reason };
|
|
116
|
+
}
|
|
117
|
+
generations.push(generation);
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
generations,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
async *_streamResponseChunks(messages, options, runManager) {
|
|
124
|
+
const messagesList = messages.map((message) => ({
|
|
125
|
+
role: message._getType(),
|
|
126
|
+
content: message.content,
|
|
127
|
+
}));
|
|
128
|
+
const response = await this.session.portkey.chatCompletions.create({
|
|
129
|
+
messages: messagesList,
|
|
130
|
+
...options,
|
|
131
|
+
stream: true,
|
|
132
|
+
});
|
|
133
|
+
for await (const data of response) {
|
|
134
|
+
const choice = data?.choices[0];
|
|
135
|
+
if (!choice) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const chunk = new ChatGenerationChunk({
|
|
139
|
+
message: _convertDeltaToMessageChunk(choice.delta ?? {}),
|
|
140
|
+
text: choice.message?.content ?? "",
|
|
141
|
+
generationInfo: {
|
|
142
|
+
finishReason: choice.finish_reason,
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
yield chunk;
|
|
146
|
+
void runManager?.handleLLMNewToken(chunk.text ?? "");
|
|
147
|
+
}
|
|
148
|
+
if (options.signal?.aborted) {
|
|
149
|
+
throw new Error("AbortError");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
_combineLLMOutput() {
|
|
153
|
+
return {};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -92,6 +92,30 @@ class UnstructuredLoader extends base_js_1.BaseDocumentLoader {
|
|
|
92
92
|
writable: true,
|
|
93
93
|
value: void 0
|
|
94
94
|
});
|
|
95
|
+
Object.defineProperty(this, "skipInferTableTypes", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
configurable: true,
|
|
98
|
+
writable: true,
|
|
99
|
+
value: void 0
|
|
100
|
+
});
|
|
101
|
+
Object.defineProperty(this, "hiResModelName", {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
configurable: true,
|
|
104
|
+
writable: true,
|
|
105
|
+
value: void 0
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(this, "includePageBreaks", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
configurable: true,
|
|
110
|
+
writable: true,
|
|
111
|
+
value: void 0
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(this, "chunkingStrategy", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
configurable: true,
|
|
116
|
+
writable: true,
|
|
117
|
+
value: void 0
|
|
118
|
+
});
|
|
95
119
|
// Temporary shim to avoid breaking existing users
|
|
96
120
|
// Remove when API keys are enforced by Unstructured and existing code will break anyway
|
|
97
121
|
const isLegacySyntax = typeof optionsOrLegacyFilePath === "string";
|
|
@@ -110,6 +134,10 @@ class UnstructuredLoader extends base_js_1.BaseDocumentLoader {
|
|
|
110
134
|
this.coordinates = options.coordinates;
|
|
111
135
|
this.pdfInferTableStructure = options.pdfInferTableStructure;
|
|
112
136
|
this.xmlKeepTags = options.xmlKeepTags;
|
|
137
|
+
this.skipInferTableTypes = options.skipInferTableTypes;
|
|
138
|
+
this.hiResModelName = options.hiResModelName;
|
|
139
|
+
this.includePageBreaks = options.includePageBreaks;
|
|
140
|
+
this.chunkingStrategy = options.chunkingStrategy;
|
|
113
141
|
}
|
|
114
142
|
}
|
|
115
143
|
async _partition() {
|
|
@@ -137,6 +165,18 @@ class UnstructuredLoader extends base_js_1.BaseDocumentLoader {
|
|
|
137
165
|
if (this.xmlKeepTags === true) {
|
|
138
166
|
formData.append("xml_keep_tags", "true");
|
|
139
167
|
}
|
|
168
|
+
if (this.skipInferTableTypes) {
|
|
169
|
+
formData.append("skip_infer_table_types", JSON.stringify(this.skipInferTableTypes));
|
|
170
|
+
}
|
|
171
|
+
if (this.hiResModelName) {
|
|
172
|
+
formData.append("hi_res_model_name", this.hiResModelName);
|
|
173
|
+
}
|
|
174
|
+
if (this.includePageBreaks) {
|
|
175
|
+
formData.append("include_page_breaks", "true");
|
|
176
|
+
}
|
|
177
|
+
if (this.chunkingStrategy) {
|
|
178
|
+
formData.append("chunking_strategy", this.chunkingStrategy);
|
|
179
|
+
}
|
|
140
180
|
const headers = {
|
|
141
181
|
"UNSTRUCTURED-API-KEY": this.apiKey ?? "",
|
|
142
182
|
};
|
|
@@ -21,6 +21,25 @@ type Element = {
|
|
|
21
21
|
* be one of "hi_res", "fast", "ocr_only", or "auto".
|
|
22
22
|
*/
|
|
23
23
|
export type UnstructuredLoaderStrategy = "hi_res" | "fast" | "ocr_only" | "auto";
|
|
24
|
+
/**
|
|
25
|
+
* Represents the available hi-res models for the UnstructuredLoader. It can
|
|
26
|
+
* be one of "chipper".
|
|
27
|
+
*/
|
|
28
|
+
export type HiResModelName = "chipper";
|
|
29
|
+
/**
|
|
30
|
+
* To enable or disable table extraction for file types other than PDF, set
|
|
31
|
+
* the skipInferTableTypes property in the UnstructuredLoaderOptions object.
|
|
32
|
+
* The skipInferTableTypes property is an array of file types for which table
|
|
33
|
+
* extraction is disabled. For example, to disable table extraction for .docx
|
|
34
|
+
* and .doc files, set the skipInferTableTypes property to ["docx", "doc"].
|
|
35
|
+
* You can also disable table extraction for all file types other than PDF by
|
|
36
|
+
* setting the skipInferTableTypes property to [].
|
|
37
|
+
*/
|
|
38
|
+
export type SkipInferTableTypes = "txt" | "text" | "pdf" | "docx" | "doc" | "jpg" | "jpeg" | "eml" | "html" | "htm" | "md" | "pptx" | "ppt" | "msg" | "rtf" | "xlsx" | "xls" | "odt" | "epub";
|
|
39
|
+
/**
|
|
40
|
+
* Set the chunking_strategy to chunk text into larger or smaller elements. Defaults to None with optional arg of by_title
|
|
41
|
+
*/
|
|
42
|
+
type ChunkingStrategy = "None" | "by_title";
|
|
24
43
|
/**
|
|
25
44
|
* Represents a string value with autocomplete suggestions. It is used for
|
|
26
45
|
* the `strategy` property in the UnstructuredLoaderOptions.
|
|
@@ -35,6 +54,10 @@ export type UnstructuredLoaderOptions = {
|
|
|
35
54
|
coordinates?: boolean;
|
|
36
55
|
pdfInferTableStructure?: boolean;
|
|
37
56
|
xmlKeepTags?: boolean;
|
|
57
|
+
skipInferTableTypes?: Array<StringWithAutocomplete<SkipInferTableTypes>>;
|
|
58
|
+
hiResModelName?: StringWithAutocomplete<HiResModelName>;
|
|
59
|
+
includePageBreaks?: boolean;
|
|
60
|
+
chunkingStrategy?: StringWithAutocomplete<ChunkingStrategy>;
|
|
38
61
|
};
|
|
39
62
|
type UnstructuredDirectoryLoaderOptions = UnstructuredLoaderOptions & {
|
|
40
63
|
recursive?: boolean;
|
|
@@ -58,6 +81,10 @@ export declare class UnstructuredLoader extends BaseDocumentLoader {
|
|
|
58
81
|
private coordinates?;
|
|
59
82
|
private pdfInferTableStructure?;
|
|
60
83
|
private xmlKeepTags?;
|
|
84
|
+
private skipInferTableTypes?;
|
|
85
|
+
private hiResModelName?;
|
|
86
|
+
private includePageBreaks?;
|
|
87
|
+
private chunkingStrategy?;
|
|
61
88
|
constructor(filePathOrLegacyApiUrl: string, optionsOrLegacyFilePath?: UnstructuredLoaderOptions | string);
|
|
62
89
|
_partition(): Promise<Element[]>;
|
|
63
90
|
load(): Promise<Document[]>;
|
|
@@ -88,6 +88,30 @@ export class UnstructuredLoader extends BaseDocumentLoader {
|
|
|
88
88
|
writable: true,
|
|
89
89
|
value: void 0
|
|
90
90
|
});
|
|
91
|
+
Object.defineProperty(this, "skipInferTableTypes", {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
configurable: true,
|
|
94
|
+
writable: true,
|
|
95
|
+
value: void 0
|
|
96
|
+
});
|
|
97
|
+
Object.defineProperty(this, "hiResModelName", {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
configurable: true,
|
|
100
|
+
writable: true,
|
|
101
|
+
value: void 0
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(this, "includePageBreaks", {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
configurable: true,
|
|
106
|
+
writable: true,
|
|
107
|
+
value: void 0
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(this, "chunkingStrategy", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
configurable: true,
|
|
112
|
+
writable: true,
|
|
113
|
+
value: void 0
|
|
114
|
+
});
|
|
91
115
|
// Temporary shim to avoid breaking existing users
|
|
92
116
|
// Remove when API keys are enforced by Unstructured and existing code will break anyway
|
|
93
117
|
const isLegacySyntax = typeof optionsOrLegacyFilePath === "string";
|
|
@@ -106,6 +130,10 @@ export class UnstructuredLoader extends BaseDocumentLoader {
|
|
|
106
130
|
this.coordinates = options.coordinates;
|
|
107
131
|
this.pdfInferTableStructure = options.pdfInferTableStructure;
|
|
108
132
|
this.xmlKeepTags = options.xmlKeepTags;
|
|
133
|
+
this.skipInferTableTypes = options.skipInferTableTypes;
|
|
134
|
+
this.hiResModelName = options.hiResModelName;
|
|
135
|
+
this.includePageBreaks = options.includePageBreaks;
|
|
136
|
+
this.chunkingStrategy = options.chunkingStrategy;
|
|
109
137
|
}
|
|
110
138
|
}
|
|
111
139
|
async _partition() {
|
|
@@ -133,6 +161,18 @@ export class UnstructuredLoader extends BaseDocumentLoader {
|
|
|
133
161
|
if (this.xmlKeepTags === true) {
|
|
134
162
|
formData.append("xml_keep_tags", "true");
|
|
135
163
|
}
|
|
164
|
+
if (this.skipInferTableTypes) {
|
|
165
|
+
formData.append("skip_infer_table_types", JSON.stringify(this.skipInferTableTypes));
|
|
166
|
+
}
|
|
167
|
+
if (this.hiResModelName) {
|
|
168
|
+
formData.append("hi_res_model_name", this.hiResModelName);
|
|
169
|
+
}
|
|
170
|
+
if (this.includePageBreaks) {
|
|
171
|
+
formData.append("include_page_breaks", "true");
|
|
172
|
+
}
|
|
173
|
+
if (this.chunkingStrategy) {
|
|
174
|
+
formData.append("chunking_strategy", this.chunkingStrategy);
|
|
175
|
+
}
|
|
136
176
|
const headers = {
|
|
137
177
|
"UNSTRUCTURED-API-KEY": this.apiKey ?? "",
|
|
138
178
|
};
|
|
@@ -81,8 +81,8 @@ class MinimaxEmbeddings extends base_js_1.Embeddings {
|
|
|
81
81
|
this.type = fieldsWithDefaults?.type ?? this.type;
|
|
82
82
|
this.stripNewLines =
|
|
83
83
|
fieldsWithDefaults?.stripNewLines ?? this.stripNewLines;
|
|
84
|
-
this.apiUrl = `${this.basePath}/embeddings`;
|
|
85
84
|
this.basePath = fields?.configuration?.basePath ?? this.basePath;
|
|
85
|
+
this.apiUrl = `${this.basePath}/embeddings`;
|
|
86
86
|
this.headers = fields?.configuration?.headers ?? this.headers;
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
@@ -78,8 +78,8 @@ export class MinimaxEmbeddings extends Embeddings {
|
|
|
78
78
|
this.type = fieldsWithDefaults?.type ?? this.type;
|
|
79
79
|
this.stripNewLines =
|
|
80
80
|
fieldsWithDefaults?.stripNewLines ?? this.stripNewLines;
|
|
81
|
-
this.apiUrl = `${this.basePath}/embeddings`;
|
|
82
81
|
this.basePath = fields?.configuration?.basePath ?? this.basePath;
|
|
82
|
+
this.apiUrl = `${this.basePath}/embeddings`;
|
|
83
83
|
this.headers = fields?.configuration?.headers ?? this.headers;
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AnthropicFunctions = void 0;
|
|
4
4
|
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
5
|
+
const base_js_1 = require("../../chat_models/base.cjs");
|
|
5
6
|
const index_js_1 = require("../../schema/index.cjs");
|
|
6
7
|
const anthropic_js_1 = require("../../chat_models/anthropic.cjs");
|
|
7
8
|
const prompt_js_1 = require("../../prompts/prompt.cjs");
|
|
@@ -26,12 +27,43 @@ for the weather in SF you would respond:
|
|
|
26
27
|
|
|
27
28
|
<tool>search</tool><tool_input><query>weather in SF</query></tool_input>
|
|
28
29
|
<observation>64 degrees</observation>`);
|
|
29
|
-
class AnthropicFunctions extends
|
|
30
|
+
class AnthropicFunctions extends base_js_1.BaseChatModel {
|
|
30
31
|
static lc_name() {
|
|
31
32
|
return "AnthropicFunctions";
|
|
32
33
|
}
|
|
33
34
|
constructor(fields) {
|
|
34
35
|
super(fields ?? {});
|
|
36
|
+
Object.defineProperty(this, "llm", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true,
|
|
40
|
+
value: void 0
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(this, "stopSequences", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
writable: true,
|
|
46
|
+
value: void 0
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
configurable: true,
|
|
51
|
+
writable: true,
|
|
52
|
+
value: ["langchain", "experimental", "chat_models"]
|
|
53
|
+
});
|
|
54
|
+
this.llm = fields?.llm ?? new anthropic_js_1.ChatAnthropic(fields);
|
|
55
|
+
this.stopSequences =
|
|
56
|
+
fields?.stopSequences ?? this.llm.stopSequences;
|
|
57
|
+
}
|
|
58
|
+
invocationParams() {
|
|
59
|
+
return this.llm.invocationParams();
|
|
60
|
+
}
|
|
61
|
+
/** @ignore */
|
|
62
|
+
_identifyingParams() {
|
|
63
|
+
return this.llm._identifyingParams();
|
|
64
|
+
}
|
|
65
|
+
async *_streamResponseChunks(messages, options, runManager) {
|
|
66
|
+
yield* this.llm._streamResponseChunks(messages, options, runManager);
|
|
35
67
|
}
|
|
36
68
|
async _generate(messages, options, runManager) {
|
|
37
69
|
let promptMessages = messages;
|
|
@@ -78,7 +110,7 @@ class AnthropicFunctions extends anthropic_js_1.ChatAnthropic {
|
|
|
78
110
|
else if (options.function_call !== undefined) {
|
|
79
111
|
throw new Error(`If "function_call" is provided, "functions" must also be.`);
|
|
80
112
|
}
|
|
81
|
-
const chatResult = await
|
|
113
|
+
const chatResult = await this.llm._generate(promptMessages, options, runManager);
|
|
82
114
|
const chatGenerationContent = chatResult.generations[0].message.content;
|
|
83
115
|
if (forced) {
|
|
84
116
|
const parser = new fast_xml_parser_1.XMLParser();
|