langchain 0.0.74 → 0.0.76
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/client.cjs +1 -0
- package/client.d.ts +1 -0
- package/client.js +1 -0
- package/dist/base_language/count_tokens.cjs +5 -21
- package/dist/base_language/count_tokens.d.ts +1 -6
- package/dist/base_language/count_tokens.js +4 -19
- package/dist/base_language/index.cjs +16 -24
- package/dist/base_language/index.d.ts +22 -3
- package/dist/base_language/index.js +17 -25
- package/dist/cache/redis.d.ts +3 -1
- package/dist/callbacks/base.d.ts +17 -3
- package/dist/callbacks/handlers/console.cjs +15 -28
- package/dist/callbacks/handlers/console.d.ts +11 -20
- package/dist/callbacks/handlers/console.js +14 -27
- package/dist/callbacks/handlers/initialize.cjs +8 -3
- package/dist/callbacks/handlers/initialize.d.ts +4 -2
- package/dist/callbacks/handlers/initialize.js +6 -2
- package/dist/callbacks/handlers/tracer.cjs +193 -0
- package/dist/callbacks/handlers/tracer.d.ts +65 -0
- package/dist/callbacks/handlers/tracer.js +189 -0
- package/dist/callbacks/handlers/tracer_langchain.cjs +163 -0
- package/dist/callbacks/handlers/tracer_langchain.d.ts +39 -0
- package/dist/callbacks/handlers/tracer_langchain.js +159 -0
- package/dist/callbacks/handlers/tracer_langchain_v1.cjs +202 -0
- package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +57 -0
- package/dist/callbacks/handlers/tracer_langchain_v1.js +198 -0
- package/dist/callbacks/index.cjs +10 -5
- package/dist/callbacks/index.d.ts +5 -3
- package/dist/callbacks/index.js +5 -3
- package/dist/callbacks/manager.cjs +39 -9
- package/dist/callbacks/manager.d.ts +5 -2
- package/dist/callbacks/manager.js +40 -10
- package/dist/chains/llm_chain.cjs +17 -5
- package/dist/chains/llm_chain.d.ts +9 -3
- package/dist/chains/llm_chain.js +17 -5
- package/dist/chains/question_answering/map_reduce_prompts.cjs +5 -5
- package/dist/chains/question_answering/map_reduce_prompts.d.ts +1 -1
- package/dist/chains/question_answering/map_reduce_prompts.js +1 -1
- package/dist/chains/question_answering/refine_prompts.cjs +5 -5
- package/dist/chains/question_answering/refine_prompts.d.ts +1 -1
- package/dist/chains/question_answering/refine_prompts.js +1 -1
- package/dist/chains/question_answering/stuff_prompts.cjs +2 -2
- package/dist/chains/question_answering/stuff_prompts.d.ts +1 -1
- package/dist/chains/question_answering/stuff_prompts.js +1 -1
- package/dist/chains/sequential_chain.cjs +2 -2
- package/dist/chains/sequential_chain.d.ts +2 -2
- package/dist/chains/sequential_chain.js +2 -2
- package/dist/chains/sql_db/sql_db_prompt.cjs +20 -1
- package/dist/chains/sql_db/sql_db_prompt.d.ts +1 -0
- package/dist/chains/sql_db/sql_db_prompt.js +19 -0
- package/dist/chains/summarization/load.cjs +14 -5
- package/dist/chains/summarization/load.d.ts +7 -2
- package/dist/chains/summarization/load.js +14 -5
- package/dist/chat_models/anthropic.cjs +36 -9
- package/dist/chat_models/anthropic.d.ts +6 -3
- package/dist/chat_models/anthropic.js +36 -9
- package/dist/chat_models/base.cjs +40 -13
- package/dist/chat_models/base.d.ts +14 -7
- package/dist/chat_models/base.js +41 -14
- package/dist/chat_models/openai.cjs +20 -14
- package/dist/chat_models/openai.d.ts +2 -1
- package/dist/chat_models/openai.js +20 -14
- package/dist/client/index.cjs +5 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.js +1 -0
- package/dist/client/langchainplus.cjs +405 -0
- package/dist/client/langchainplus.d.ts +65 -0
- package/dist/client/langchainplus.js +398 -0
- package/dist/document_loaders/fs/unstructured.cjs +8 -0
- package/dist/document_loaders/fs/unstructured.d.ts +3 -0
- package/dist/document_loaders/fs/unstructured.js +8 -0
- package/dist/document_loaders/web/apify_dataset.cjs +64 -0
- package/dist/document_loaders/web/apify_dataset.d.ts +28 -0
- package/dist/document_loaders/web/apify_dataset.js +60 -0
- package/dist/embeddings/openai.cjs +2 -2
- package/dist/embeddings/openai.js +2 -2
- package/dist/llms/base.cjs +43 -17
- package/dist/llms/base.d.ts +16 -9
- package/dist/llms/base.js +44 -18
- package/dist/llms/cohere.cjs +3 -2
- package/dist/llms/cohere.d.ts +1 -1
- package/dist/llms/cohere.js +3 -2
- package/dist/llms/hf.cjs +2 -2
- package/dist/llms/hf.d.ts +1 -1
- package/dist/llms/hf.js +2 -2
- package/dist/llms/openai-chat.cjs +13 -14
- package/dist/llms/openai-chat.d.ts +2 -1
- package/dist/llms/openai-chat.js +13 -14
- package/dist/llms/openai.cjs +15 -13
- package/dist/llms/openai.d.ts +4 -3
- package/dist/llms/openai.js +15 -13
- package/dist/llms/replicate.cjs +2 -2
- package/dist/llms/replicate.d.ts +1 -1
- package/dist/llms/replicate.js +2 -2
- package/dist/memory/base.cjs +9 -1
- package/dist/memory/base.d.ts +1 -0
- package/dist/memory/base.js +7 -0
- package/dist/memory/entity_memory.cjs +151 -0
- package/dist/memory/entity_memory.d.ts +35 -0
- package/dist/memory/entity_memory.js +147 -0
- package/dist/memory/index.cjs +5 -1
- package/dist/memory/index.d.ts +2 -0
- package/dist/memory/index.js +2 -0
- package/dist/memory/prompt.cjs +84 -1
- package/dist/memory/prompt.d.ts +6 -0
- package/dist/memory/prompt.js +83 -0
- package/dist/memory/stores/entity/in_memory.cjs +32 -0
- package/dist/memory/stores/entity/in_memory.d.ts +10 -0
- package/dist/memory/stores/entity/in_memory.js +28 -0
- package/dist/prompts/index.cjs +6 -1
- package/dist/prompts/index.d.ts +1 -0
- package/dist/prompts/index.js +1 -0
- package/dist/{chains/prompt_selector.d.ts → prompts/selectors/conditional.d.ts} +4 -4
- package/dist/retrievers/document_compressors/chain_extract.cjs +9 -11
- package/dist/retrievers/document_compressors/chain_extract.js +9 -11
- package/dist/schema/index.cjs +13 -1
- package/dist/schema/index.d.ts +19 -0
- package/dist/schema/index.js +11 -0
- package/dist/stores/message/dynamodb.cjs +8 -6
- package/dist/stores/message/dynamodb.js +8 -6
- package/dist/stores/message/redis.cjs +69 -0
- package/dist/stores/message/redis.d.ts +18 -0
- package/dist/stores/message/redis.js +65 -0
- package/dist/stores/message/utils.cjs +30 -15
- package/dist/stores/message/utils.d.ts +4 -2
- package/dist/stores/message/utils.js +28 -14
- package/dist/text_splitter.cjs +3 -23
- package/dist/text_splitter.d.ts +1 -3
- package/dist/text_splitter.js +3 -23
- package/dist/tools/webbrowser.cjs +5 -7
- package/dist/tools/webbrowser.js +3 -5
- package/dist/types/openai-types.d.ts +3 -2
- package/dist/util/async_caller.cjs +16 -0
- package/dist/util/async_caller.d.ts +4 -0
- package/dist/util/async_caller.js +16 -0
- package/dist/util/axios-fetch-adapter.cjs +6 -0
- package/dist/util/axios-fetch-adapter.js +6 -0
- package/dist/util/env.cjs +39 -7
- package/dist/util/env.d.ts +19 -0
- package/dist/util/env.js +32 -6
- package/dist/util/sql_utils.cjs +18 -0
- package/dist/util/sql_utils.js +19 -1
- package/dist/util/tiktoken.cjs +26 -0
- package/dist/util/tiktoken.d.ts +9 -0
- package/dist/util/tiktoken.js +21 -0
- package/dist/vectorstores/redis.cjs +236 -0
- package/dist/vectorstores/redis.d.ts +80 -0
- package/dist/vectorstores/redis.js +232 -0
- package/document_loaders/web/apify_dataset.cjs +1 -0
- package/document_loaders/web/apify_dataset.d.ts +1 -0
- package/document_loaders/web/apify_dataset.js +1 -0
- package/package.json +41 -5
- package/stores/message/redis.cjs +1 -0
- package/stores/message/redis.d.ts +1 -0
- package/stores/message/redis.js +1 -0
- package/vectorstores/redis.cjs +1 -0
- package/vectorstores/redis.d.ts +1 -0
- package/vectorstores/redis.js +1 -0
- package/dist/callbacks/handlers/tracers.cjs +0 -341
- package/dist/callbacks/handlers/tracers.d.ts +0 -100
- package/dist/callbacks/handlers/tracers.js +0 -336
- /package/dist/{chains/prompt_selector.cjs → prompts/selectors/conditional.cjs} +0 -0
- /package/dist/{chains/prompt_selector.js → prompts/selectors/conditional.js} +0 -0
package/dist/memory/prompt.js
CHANGED
|
@@ -25,3 +25,86 @@ export const SUMMARY_PROMPT = /*#__PURE__*/ new PromptTemplate({
|
|
|
25
25
|
inputVariables: ["summary", "new_lines"],
|
|
26
26
|
template: _DEFAULT_SUMMARIZER_TEMPLATE,
|
|
27
27
|
});
|
|
28
|
+
export const _DEFAULT_ENTITY_MEMORY_CONVERSATION_TEMPLATE = `You are an assistant to a human, powered by a large language model trained by OpenAI.
|
|
29
|
+
|
|
30
|
+
You are designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, you are able to generate human-like text based on the input you receive, allowing you to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand.
|
|
31
|
+
|
|
32
|
+
You are constantly learning and improving, and your capabilities are constantly evolving. You are able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. You have access to some personalized information provided by the human in the Context section below. Additionally, you are able to generate your own text based on the input you receive, allowing you to engage in discussions and provide explanations and descriptions on a wide range of topics.
|
|
33
|
+
|
|
34
|
+
Overall, you are a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether the human needs help with a specific question or just wants to have a conversation about a particular topic, you are here to assist.
|
|
35
|
+
|
|
36
|
+
Context:
|
|
37
|
+
{entities}
|
|
38
|
+
|
|
39
|
+
Current conversation:
|
|
40
|
+
{history}
|
|
41
|
+
Last line:
|
|
42
|
+
Human: {input}
|
|
43
|
+
You:`;
|
|
44
|
+
export const ENTITY_MEMORY_CONVERSATION_TEMPLATE =
|
|
45
|
+
// eslint-disable-next-line spaced-comment
|
|
46
|
+
/*#__PURE__*/ new PromptTemplate({
|
|
47
|
+
inputVariables: ["entities", "history", "input"],
|
|
48
|
+
template: _DEFAULT_ENTITY_MEMORY_CONVERSATION_TEMPLATE,
|
|
49
|
+
});
|
|
50
|
+
export const _DEFAULT_ENTITY_EXTRACTION_TEMPLATE = `You are an AI assistant reading the transcript of a conversation between an AI and a human. Extract all of the proper nouns from the last line of conversation. As a guideline, a proper noun is generally capitalized. You should definitely extract all names and places.
|
|
51
|
+
|
|
52
|
+
The conversation history is provided just in case of a coreference (e.g. "What do you know about him" where "him" is defined in a previous line) -- ignore items mentioned there that are not in the last line.
|
|
53
|
+
|
|
54
|
+
Return the output as a single comma-separated list, or NONE if there is nothing of note to return (e.g. the user is just issuing a greeting or having a simple conversation).
|
|
55
|
+
|
|
56
|
+
EXAMPLE
|
|
57
|
+
Conversation history:
|
|
58
|
+
Person #1: my name is Jacob. how's it going today?
|
|
59
|
+
AI: "It's going great! How about you?"
|
|
60
|
+
Person #1: good! busy working on Langchain. lots to do.
|
|
61
|
+
AI: "That sounds like a lot of work! What kind of things are you doing to make Langchain better?"
|
|
62
|
+
Last line:
|
|
63
|
+
Person #1: i'm trying to improve Langchain's interfaces, the UX, its integrations with various products the user might want ... a lot of stuff.
|
|
64
|
+
Output: Jacob,Langchain
|
|
65
|
+
END OF EXAMPLE
|
|
66
|
+
|
|
67
|
+
EXAMPLE
|
|
68
|
+
Conversation history:
|
|
69
|
+
Person #1: how's it going today?
|
|
70
|
+
AI: "It's going great! How about you?"
|
|
71
|
+
Person #1: good! busy working on Langchain. lots to do.
|
|
72
|
+
AI: "That sounds like a lot of work! What kind of things are you doing to make Langchain better?"
|
|
73
|
+
Last line:
|
|
74
|
+
Person #1: i'm trying to improve Langchain's interfaces, the UX, its integrations with various products the user might want ... a lot of stuff. I'm working with Person #2.
|
|
75
|
+
Output: Langchain, Person #2
|
|
76
|
+
END OF EXAMPLE
|
|
77
|
+
|
|
78
|
+
Conversation history (for reference only):
|
|
79
|
+
{history}
|
|
80
|
+
Last line of conversation (for extraction):
|
|
81
|
+
Human: {input}
|
|
82
|
+
|
|
83
|
+
Output:`;
|
|
84
|
+
// eslint-disable-next-line spaced-comment
|
|
85
|
+
export const ENTITY_EXTRACTION_PROMPT = /*#__PURE__*/ new PromptTemplate({
|
|
86
|
+
inputVariables: ["history", "input"],
|
|
87
|
+
template: _DEFAULT_ENTITY_EXTRACTION_TEMPLATE,
|
|
88
|
+
});
|
|
89
|
+
export const _DEFAULT_ENTITY_SUMMARIZATION_TEMPLATE = `You are an AI assistant helping a human keep track of facts about relevant people, places, and concepts in their life. Update and add to the summary of the provided entity in the "Entity" section based on the last line of your conversation with the human. If you are writing the summary for the first time, return a single sentence.
|
|
90
|
+
The update should only include facts that are relayed in the last line of conversation about the provided entity, and should only contain facts about the provided entity.
|
|
91
|
+
|
|
92
|
+
If there is no new information about the provided entity or the information is not worth noting (not an important or relevant fact to remember long-term), output the exact string "UNCHANGED" below.
|
|
93
|
+
|
|
94
|
+
Full conversation history (for context):
|
|
95
|
+
{history}
|
|
96
|
+
|
|
97
|
+
Entity to summarize:
|
|
98
|
+
{entity}
|
|
99
|
+
|
|
100
|
+
Existing summary of {entity}:
|
|
101
|
+
{summary}
|
|
102
|
+
|
|
103
|
+
Last line of conversation:
|
|
104
|
+
Human: {input}
|
|
105
|
+
Updated summary (or the exact string "UNCHANGED" if there is no new information about {entity} above):`;
|
|
106
|
+
// eslint-disable-next-line spaced-comment
|
|
107
|
+
export const ENTITY_SUMMARIZATION_PROMPT = /*#__PURE__*/ new PromptTemplate({
|
|
108
|
+
inputVariables: ["entity", "summary", "history", "input"],
|
|
109
|
+
template: _DEFAULT_ENTITY_SUMMARIZATION_TEMPLATE,
|
|
110
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InMemoryEntityStore = void 0;
|
|
4
|
+
const index_js_1 = require("../../../schema/index.cjs");
|
|
5
|
+
class InMemoryEntityStore extends index_js_1.BaseEntityStore {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
Object.defineProperty(this, "store", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: void 0
|
|
13
|
+
});
|
|
14
|
+
this.store = Object.create(null);
|
|
15
|
+
}
|
|
16
|
+
async get(key, defaultValue) {
|
|
17
|
+
return key in this.store ? this.store[key] : defaultValue;
|
|
18
|
+
}
|
|
19
|
+
async set(key, value) {
|
|
20
|
+
this.store[key] = value;
|
|
21
|
+
}
|
|
22
|
+
async delete(key) {
|
|
23
|
+
delete this.store[key];
|
|
24
|
+
}
|
|
25
|
+
async exists(key) {
|
|
26
|
+
return key in this.store;
|
|
27
|
+
}
|
|
28
|
+
async clear() {
|
|
29
|
+
this.store = Object.create(null);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.InMemoryEntityStore = InMemoryEntityStore;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseEntityStore } from "../../../schema/index.js";
|
|
2
|
+
export declare class InMemoryEntityStore extends BaseEntityStore {
|
|
3
|
+
private store;
|
|
4
|
+
constructor();
|
|
5
|
+
get(key: string, defaultValue: string | undefined): Promise<string | undefined>;
|
|
6
|
+
set(key: string, value: string | undefined): Promise<void>;
|
|
7
|
+
delete(key: string): Promise<void>;
|
|
8
|
+
exists(key: string): Promise<boolean>;
|
|
9
|
+
clear(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BaseEntityStore } from "../../../schema/index.js";
|
|
2
|
+
export class InMemoryEntityStore extends BaseEntityStore {
|
|
3
|
+
constructor() {
|
|
4
|
+
super();
|
|
5
|
+
Object.defineProperty(this, "store", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value: void 0
|
|
10
|
+
});
|
|
11
|
+
this.store = Object.create(null);
|
|
12
|
+
}
|
|
13
|
+
async get(key, defaultValue) {
|
|
14
|
+
return key in this.store ? this.store[key] : defaultValue;
|
|
15
|
+
}
|
|
16
|
+
async set(key, value) {
|
|
17
|
+
this.store[key] = value;
|
|
18
|
+
}
|
|
19
|
+
async delete(key) {
|
|
20
|
+
delete this.store[key];
|
|
21
|
+
}
|
|
22
|
+
async exists(key) {
|
|
23
|
+
return key in this.store;
|
|
24
|
+
}
|
|
25
|
+
async clear() {
|
|
26
|
+
this.store = Object.create(null);
|
|
27
|
+
}
|
|
28
|
+
}
|
package/dist/prompts/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkValidTemplate = exports.renderTemplate = exports.parseTemplate = exports.BaseChatPromptTemplate = exports.MessagesPlaceholder = exports.ChatMessagePromptTemplate = exports.SystemMessagePromptTemplate = exports.AIMessagePromptTemplate = exports.HumanMessagePromptTemplate = exports.ChatPromptTemplate = exports.FewShotPromptTemplate = exports.SemanticSimilarityExampleSelector = exports.LengthBasedExampleSelector = exports.PromptTemplate = exports.BaseStringPromptTemplate = exports.StringPromptValue = exports.BasePromptTemplate = exports.BaseExampleSelector = void 0;
|
|
3
|
+
exports.checkValidTemplate = exports.renderTemplate = exports.parseTemplate = exports.BaseChatPromptTemplate = exports.MessagesPlaceholder = exports.ChatMessagePromptTemplate = exports.SystemMessagePromptTemplate = exports.AIMessagePromptTemplate = exports.HumanMessagePromptTemplate = exports.ChatPromptTemplate = exports.FewShotPromptTemplate = exports.SemanticSimilarityExampleSelector = exports.LengthBasedExampleSelector = exports.isLLM = exports.isChatModel = exports.ConditionalPromptSelector = exports.BasePromptSelector = exports.PromptTemplate = exports.BaseStringPromptTemplate = exports.StringPromptValue = exports.BasePromptTemplate = exports.BaseExampleSelector = void 0;
|
|
4
4
|
var base_js_1 = require("./base.cjs");
|
|
5
5
|
Object.defineProperty(exports, "BaseExampleSelector", { enumerable: true, get: function () { return base_js_1.BaseExampleSelector; } });
|
|
6
6
|
Object.defineProperty(exports, "BasePromptTemplate", { enumerable: true, get: function () { return base_js_1.BasePromptTemplate; } });
|
|
@@ -8,6 +8,11 @@ Object.defineProperty(exports, "StringPromptValue", { enumerable: true, get: fun
|
|
|
8
8
|
Object.defineProperty(exports, "BaseStringPromptTemplate", { enumerable: true, get: function () { return base_js_1.BaseStringPromptTemplate; } });
|
|
9
9
|
var prompt_js_1 = require("./prompt.cjs");
|
|
10
10
|
Object.defineProperty(exports, "PromptTemplate", { enumerable: true, get: function () { return prompt_js_1.PromptTemplate; } });
|
|
11
|
+
var conditional_js_1 = require("./selectors/conditional.cjs");
|
|
12
|
+
Object.defineProperty(exports, "BasePromptSelector", { enumerable: true, get: function () { return conditional_js_1.BasePromptSelector; } });
|
|
13
|
+
Object.defineProperty(exports, "ConditionalPromptSelector", { enumerable: true, get: function () { return conditional_js_1.ConditionalPromptSelector; } });
|
|
14
|
+
Object.defineProperty(exports, "isChatModel", { enumerable: true, get: function () { return conditional_js_1.isChatModel; } });
|
|
15
|
+
Object.defineProperty(exports, "isLLM", { enumerable: true, get: function () { return conditional_js_1.isLLM; } });
|
|
11
16
|
var LengthBasedExampleSelector_js_1 = require("./selectors/LengthBasedExampleSelector.cjs");
|
|
12
17
|
Object.defineProperty(exports, "LengthBasedExampleSelector", { enumerable: true, get: function () { return LengthBasedExampleSelector_js_1.LengthBasedExampleSelector; } });
|
|
13
18
|
var SemanticSimilarityExampleSelector_js_1 = require("./selectors/SemanticSimilarityExampleSelector.cjs");
|
package/dist/prompts/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { BaseExampleSelector, BasePromptTemplate, BasePromptTemplateInput, StringPromptValue, BaseStringPromptTemplate, } from "./base.js";
|
|
2
2
|
export { PromptTemplate, PromptTemplateInput } from "./prompt.js";
|
|
3
|
+
export { BasePromptSelector, ConditionalPromptSelector, isChatModel, isLLM, } from "./selectors/conditional.js";
|
|
3
4
|
export { LengthBasedExampleSelector, LengthBasedExampleSelectorInput, } from "./selectors/LengthBasedExampleSelector.js";
|
|
4
5
|
export { SemanticSimilarityExampleSelector, SemanticSimilarityExampleSelectorInput, } from "./selectors/SemanticSimilarityExampleSelector.js";
|
|
5
6
|
export { FewShotPromptTemplate, FewShotPromptTemplateInput, } from "./few_shot.js";
|
package/dist/prompts/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { BaseExampleSelector, BasePromptTemplate, StringPromptValue, BaseStringPromptTemplate, } from "./base.js";
|
|
2
2
|
export { PromptTemplate } from "./prompt.js";
|
|
3
|
+
export { BasePromptSelector, ConditionalPromptSelector, isChatModel, isLLM, } from "./selectors/conditional.js";
|
|
3
4
|
export { LengthBasedExampleSelector, } from "./selectors/LengthBasedExampleSelector.js";
|
|
4
5
|
export { SemanticSimilarityExampleSelector, } from "./selectors/SemanticSimilarityExampleSelector.js";
|
|
5
6
|
export { FewShotPromptTemplate, } from "./few_shot.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BaseChatModel } from "
|
|
2
|
-
import { BasePromptTemplate } from "../
|
|
3
|
-
import { BaseLanguageModel } from "
|
|
4
|
-
import { BaseLLM } from "
|
|
1
|
+
import { BaseChatModel } from "../../chat_models/base.js";
|
|
2
|
+
import { BasePromptTemplate } from "../base.js";
|
|
3
|
+
import { BaseLanguageModel } from "../../base_language/index.js";
|
|
4
|
+
import { BaseLLM } from "../../llms/base.js";
|
|
5
5
|
export declare abstract class BasePromptSelector {
|
|
6
6
|
abstract getPrompt(llm: BaseLanguageModel): BasePromptTemplate;
|
|
7
7
|
}
|
|
@@ -59,19 +59,17 @@ class LLMChainExtractor extends index_js_2.BaseDocumentCompressor {
|
|
|
59
59
|
this.getInput = getInput;
|
|
60
60
|
}
|
|
61
61
|
async compressDocuments(documents, query) {
|
|
62
|
-
const compressedDocs =
|
|
63
|
-
for (const doc of documents) {
|
|
62
|
+
const compressedDocs = await Promise.all(documents.map(async (doc) => {
|
|
64
63
|
const input = this.getInput(query, doc);
|
|
65
64
|
const output = await this.llmChain.predict(input);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return compressedDocs;
|
|
65
|
+
return output.length > 0
|
|
66
|
+
? new document_js_1.Document({
|
|
67
|
+
pageContent: output,
|
|
68
|
+
metadata: doc.metadata,
|
|
69
|
+
})
|
|
70
|
+
: undefined;
|
|
71
|
+
}));
|
|
72
|
+
return compressedDocs.filter((doc) => doc !== undefined);
|
|
75
73
|
}
|
|
76
74
|
static fromLLM(llm, prompt, getInput) {
|
|
77
75
|
const _prompt = prompt || getDefaultChainPrompt();
|
|
@@ -56,19 +56,17 @@ export class LLMChainExtractor extends BaseDocumentCompressor {
|
|
|
56
56
|
this.getInput = getInput;
|
|
57
57
|
}
|
|
58
58
|
async compressDocuments(documents, query) {
|
|
59
|
-
const compressedDocs =
|
|
60
|
-
for (const doc of documents) {
|
|
59
|
+
const compressedDocs = await Promise.all(documents.map(async (doc) => {
|
|
61
60
|
const input = this.getInput(query, doc);
|
|
62
61
|
const output = await this.llmChain.predict(input);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return compressedDocs;
|
|
62
|
+
return output.length > 0
|
|
63
|
+
? new Document({
|
|
64
|
+
pageContent: output,
|
|
65
|
+
metadata: doc.metadata,
|
|
66
|
+
})
|
|
67
|
+
: undefined;
|
|
68
|
+
}));
|
|
69
|
+
return compressedDocs.filter((doc) => doc !== undefined);
|
|
72
70
|
}
|
|
73
71
|
static fromLLM(llm, prompt, getInput) {
|
|
74
72
|
const _prompt = prompt || getDefaultChainPrompt();
|
package/dist/schema/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseFileStore = exports.BaseCache = exports.BaseListChatMessageHistory = exports.BaseChatMessageHistory = exports.BaseRetriever = exports.BasePromptValue = exports.ChatMessage = exports.SystemChatMessage = exports.AIChatMessage = exports.HumanChatMessage = exports.BaseChatMessage = exports.RUN_KEY = void 0;
|
|
3
|
+
exports.BaseEntityStore = exports.BaseFileStore = exports.BaseCache = exports.BaseListChatMessageHistory = exports.BaseChatMessageHistory = exports.BaseRetriever = exports.BasePromptValue = exports.ChatMessage = exports.SystemChatMessage = exports.AIChatMessage = exports.HumanChatMessage = exports.BaseChatMessage = exports.RUN_KEY = void 0;
|
|
4
4
|
exports.RUN_KEY = "__run";
|
|
5
5
|
class BaseChatMessage {
|
|
6
6
|
constructor(text) {
|
|
@@ -20,6 +20,15 @@ class BaseChatMessage {
|
|
|
20
20
|
});
|
|
21
21
|
this.text = text;
|
|
22
22
|
}
|
|
23
|
+
toJSON() {
|
|
24
|
+
return {
|
|
25
|
+
type: this._getType(),
|
|
26
|
+
data: {
|
|
27
|
+
content: this.text,
|
|
28
|
+
role: "role" in this ? this.role : undefined,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
23
32
|
}
|
|
24
33
|
exports.BaseChatMessage = BaseChatMessage;
|
|
25
34
|
class HumanChatMessage extends BaseChatMessage {
|
|
@@ -86,3 +95,6 @@ exports.BaseCache = BaseCache;
|
|
|
86
95
|
class BaseFileStore {
|
|
87
96
|
}
|
|
88
97
|
exports.BaseFileStore = BaseFileStore;
|
|
98
|
+
class BaseEntityStore {
|
|
99
|
+
}
|
|
100
|
+
exports.BaseEntityStore = BaseEntityStore;
|
package/dist/schema/index.d.ts
CHANGED
|
@@ -34,6 +34,15 @@ export type LLMResult = {
|
|
|
34
34
|
*/
|
|
35
35
|
[RUN_KEY]?: Record<string, any>;
|
|
36
36
|
};
|
|
37
|
+
export interface StoredMessageData {
|
|
38
|
+
content: string;
|
|
39
|
+
role: string | undefined;
|
|
40
|
+
additional_kwargs?: Record<string, any>;
|
|
41
|
+
}
|
|
42
|
+
export interface StoredMessage {
|
|
43
|
+
type: string;
|
|
44
|
+
data: StoredMessageData;
|
|
45
|
+
}
|
|
37
46
|
export type MessageType = "human" | "ai" | "generic" | "system";
|
|
38
47
|
export declare abstract class BaseChatMessage {
|
|
39
48
|
/** The text of the message. */
|
|
@@ -43,6 +52,7 @@ export declare abstract class BaseChatMessage {
|
|
|
43
52
|
/** The type of the message. */
|
|
44
53
|
abstract _getType(): MessageType;
|
|
45
54
|
constructor(text: string);
|
|
55
|
+
toJSON(): StoredMessage;
|
|
46
56
|
}
|
|
47
57
|
export declare class HumanChatMessage extends BaseChatMessage {
|
|
48
58
|
_getType(): MessageType;
|
|
@@ -86,6 +96,8 @@ export type AgentStep = {
|
|
|
86
96
|
observation: string;
|
|
87
97
|
};
|
|
88
98
|
export type ChainValues = Record<string, any>;
|
|
99
|
+
export type RunInputs = Record<string, any>;
|
|
100
|
+
export type RunOutputs = Record<string, any>;
|
|
89
101
|
/**
|
|
90
102
|
* Base Index class. All indexes should extend this class.
|
|
91
103
|
*/
|
|
@@ -111,3 +123,10 @@ export declare abstract class BaseFileStore {
|
|
|
111
123
|
abstract readFile(path: string): Promise<string>;
|
|
112
124
|
abstract writeFile(path: string, contents: string): Promise<void>;
|
|
113
125
|
}
|
|
126
|
+
export declare abstract class BaseEntityStore {
|
|
127
|
+
abstract get(key: string, defaultValue?: string): Promise<string | undefined>;
|
|
128
|
+
abstract set(key: string, value?: string): Promise<void>;
|
|
129
|
+
abstract delete(key: string): Promise<void>;
|
|
130
|
+
abstract exists(key: string): Promise<boolean>;
|
|
131
|
+
abstract clear(): Promise<void>;
|
|
132
|
+
}
|
package/dist/schema/index.js
CHANGED
|
@@ -17,6 +17,15 @@ export class BaseChatMessage {
|
|
|
17
17
|
});
|
|
18
18
|
this.text = text;
|
|
19
19
|
}
|
|
20
|
+
toJSON() {
|
|
21
|
+
return {
|
|
22
|
+
type: this._getType(),
|
|
23
|
+
data: {
|
|
24
|
+
content: this.text,
|
|
25
|
+
role: "role" in this ? this.role : undefined,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
20
29
|
}
|
|
21
30
|
export class HumanChatMessage extends BaseChatMessage {
|
|
22
31
|
_getType() {
|
|
@@ -72,3 +81,5 @@ export class BaseCache {
|
|
|
72
81
|
}
|
|
73
82
|
export class BaseFileStore {
|
|
74
83
|
}
|
|
84
|
+
export class BaseEntityStore {
|
|
85
|
+
}
|
|
@@ -74,10 +74,12 @@ class DynamoDBChatMessageHistory extends index_js_1.BaseListChatMessageHistory {
|
|
|
74
74
|
const messages = items
|
|
75
75
|
.map((item) => ({
|
|
76
76
|
type: item.M?.type.S,
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
data: {
|
|
78
|
+
role: item.M?.role?.S,
|
|
79
|
+
content: item.M?.text.S,
|
|
80
|
+
},
|
|
79
81
|
}))
|
|
80
|
-
.filter((x) => x.type !== undefined && x.
|
|
82
|
+
.filter((x) => x.type !== undefined && x.data.content !== undefined);
|
|
81
83
|
return (0, utils_js_1.mapStoredMessagesToChatMessages)(messages);
|
|
82
84
|
}
|
|
83
85
|
async clear() {
|
|
@@ -107,12 +109,12 @@ class DynamoDBChatMessageHistory extends index_js_1.BaseListChatMessageHistory {
|
|
|
107
109
|
S: message.type,
|
|
108
110
|
},
|
|
109
111
|
text: {
|
|
110
|
-
S: message.
|
|
112
|
+
S: message.data.content,
|
|
111
113
|
},
|
|
112
114
|
},
|
|
113
115
|
};
|
|
114
|
-
if (message.role) {
|
|
115
|
-
dynamoSerializedMessage.M.role = { S: message.role };
|
|
116
|
+
if (message.data.role) {
|
|
117
|
+
dynamoSerializedMessage.M.role = { S: message.data.role };
|
|
116
118
|
}
|
|
117
119
|
return dynamoSerializedMessage;
|
|
118
120
|
}),
|
|
@@ -71,10 +71,12 @@ export class DynamoDBChatMessageHistory extends BaseListChatMessageHistory {
|
|
|
71
71
|
const messages = items
|
|
72
72
|
.map((item) => ({
|
|
73
73
|
type: item.M?.type.S,
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
data: {
|
|
75
|
+
role: item.M?.role?.S,
|
|
76
|
+
content: item.M?.text.S,
|
|
77
|
+
},
|
|
76
78
|
}))
|
|
77
|
-
.filter((x) => x.type !== undefined && x.
|
|
79
|
+
.filter((x) => x.type !== undefined && x.data.content !== undefined);
|
|
78
80
|
return mapStoredMessagesToChatMessages(messages);
|
|
79
81
|
}
|
|
80
82
|
async clear() {
|
|
@@ -104,12 +106,12 @@ export class DynamoDBChatMessageHistory extends BaseListChatMessageHistory {
|
|
|
104
106
|
S: message.type,
|
|
105
107
|
},
|
|
106
108
|
text: {
|
|
107
|
-
S: message.
|
|
109
|
+
S: message.data.content,
|
|
108
110
|
},
|
|
109
111
|
},
|
|
110
112
|
};
|
|
111
|
-
if (message.role) {
|
|
112
|
-
dynamoSerializedMessage.M.role = { S: message.role };
|
|
113
|
+
if (message.data.role) {
|
|
114
|
+
dynamoSerializedMessage.M.role = { S: message.data.role };
|
|
113
115
|
}
|
|
114
116
|
return dynamoSerializedMessage;
|
|
115
117
|
}),
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RedisChatMessageHistory = void 0;
|
|
4
|
+
const redis_1 = require("redis");
|
|
5
|
+
const index_js_1 = require("../../schema/index.cjs");
|
|
6
|
+
const utils_js_1 = require("./utils.cjs");
|
|
7
|
+
class RedisChatMessageHistory extends index_js_1.BaseListChatMessageHistory {
|
|
8
|
+
constructor(fields) {
|
|
9
|
+
const { sessionId, sessionTTL, config, client } = fields;
|
|
10
|
+
super();
|
|
11
|
+
Object.defineProperty(this, "client", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: void 0
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "sessionId", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: void 0
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "sessionTTL", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
this.client = (client ?? (0, redis_1.createClient)(config ?? {}));
|
|
30
|
+
this.sessionId = sessionId;
|
|
31
|
+
this.sessionTTL = sessionTTL;
|
|
32
|
+
}
|
|
33
|
+
async ensureReadiness() {
|
|
34
|
+
if (!this.client.isReady) {
|
|
35
|
+
await this.client.connect();
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
async getMessages() {
|
|
40
|
+
await this.ensureReadiness();
|
|
41
|
+
const rawStoredMessages = await this.client.lRange(this.sessionId, 0, -1);
|
|
42
|
+
const orderedMessages = rawStoredMessages
|
|
43
|
+
.reverse()
|
|
44
|
+
.map((message) => JSON.parse(message));
|
|
45
|
+
const previousMessages = orderedMessages
|
|
46
|
+
.map((item) => ({
|
|
47
|
+
type: item.type,
|
|
48
|
+
data: {
|
|
49
|
+
role: item.role,
|
|
50
|
+
content: item.text,
|
|
51
|
+
},
|
|
52
|
+
}))
|
|
53
|
+
.filter((x) => x.type !== undefined && x.data.content !== undefined);
|
|
54
|
+
return (0, utils_js_1.mapStoredMessagesToChatMessages)(previousMessages);
|
|
55
|
+
}
|
|
56
|
+
async addMessage(message) {
|
|
57
|
+
await this.ensureReadiness();
|
|
58
|
+
const messageToAdd = (0, utils_js_1.mapChatMessagesToStoredMessages)([message]);
|
|
59
|
+
await this.client.lPush(this.sessionId, JSON.stringify(messageToAdd[0]));
|
|
60
|
+
if (this.sessionTTL) {
|
|
61
|
+
await this.client.expire(this.sessionId, this.sessionTTL);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async clear() {
|
|
65
|
+
await this.ensureReadiness();
|
|
66
|
+
await this.client.del(this.sessionId);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.RedisChatMessageHistory = RedisChatMessageHistory;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RedisClientOptions, RedisClientType, RedisModules, RedisFunctions, RedisScripts } from "redis";
|
|
2
|
+
import { BaseChatMessage, BaseListChatMessageHistory } from "../../schema/index.js";
|
|
3
|
+
export type RedisChatMessageHistoryInput = {
|
|
4
|
+
sessionId: string;
|
|
5
|
+
sessionTTL?: number;
|
|
6
|
+
config?: RedisClientOptions;
|
|
7
|
+
client?: any;
|
|
8
|
+
};
|
|
9
|
+
export declare class RedisChatMessageHistory extends BaseListChatMessageHistory {
|
|
10
|
+
client: RedisClientType<RedisModules, RedisFunctions, RedisScripts>;
|
|
11
|
+
private sessionId;
|
|
12
|
+
private sessionTTL?;
|
|
13
|
+
constructor(fields: RedisChatMessageHistoryInput);
|
|
14
|
+
ensureReadiness(): Promise<boolean>;
|
|
15
|
+
getMessages(): Promise<BaseChatMessage[]>;
|
|
16
|
+
addMessage(message: BaseChatMessage): Promise<void>;
|
|
17
|
+
clear(): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createClient, } from "redis";
|
|
2
|
+
import { BaseListChatMessageHistory, } from "../../schema/index.js";
|
|
3
|
+
import { mapChatMessagesToStoredMessages, mapStoredMessagesToChatMessages, } from "./utils.js";
|
|
4
|
+
export class RedisChatMessageHistory extends BaseListChatMessageHistory {
|
|
5
|
+
constructor(fields) {
|
|
6
|
+
const { sessionId, sessionTTL, config, client } = fields;
|
|
7
|
+
super();
|
|
8
|
+
Object.defineProperty(this, "client", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: void 0
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(this, "sessionId", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: void 0
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(this, "sessionTTL", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: void 0
|
|
25
|
+
});
|
|
26
|
+
this.client = (client ?? createClient(config ?? {}));
|
|
27
|
+
this.sessionId = sessionId;
|
|
28
|
+
this.sessionTTL = sessionTTL;
|
|
29
|
+
}
|
|
30
|
+
async ensureReadiness() {
|
|
31
|
+
if (!this.client.isReady) {
|
|
32
|
+
await this.client.connect();
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
async getMessages() {
|
|
37
|
+
await this.ensureReadiness();
|
|
38
|
+
const rawStoredMessages = await this.client.lRange(this.sessionId, 0, -1);
|
|
39
|
+
const orderedMessages = rawStoredMessages
|
|
40
|
+
.reverse()
|
|
41
|
+
.map((message) => JSON.parse(message));
|
|
42
|
+
const previousMessages = orderedMessages
|
|
43
|
+
.map((item) => ({
|
|
44
|
+
type: item.type,
|
|
45
|
+
data: {
|
|
46
|
+
role: item.role,
|
|
47
|
+
content: item.text,
|
|
48
|
+
},
|
|
49
|
+
}))
|
|
50
|
+
.filter((x) => x.type !== undefined && x.data.content !== undefined);
|
|
51
|
+
return mapStoredMessagesToChatMessages(previousMessages);
|
|
52
|
+
}
|
|
53
|
+
async addMessage(message) {
|
|
54
|
+
await this.ensureReadiness();
|
|
55
|
+
const messageToAdd = mapChatMessagesToStoredMessages([message]);
|
|
56
|
+
await this.client.lPush(this.sessionId, JSON.stringify(messageToAdd[0]));
|
|
57
|
+
if (this.sessionTTL) {
|
|
58
|
+
await this.client.expire(this.sessionId, this.sessionTTL);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async clear() {
|
|
62
|
+
await this.ensureReadiness();
|
|
63
|
+
await this.client.del(this.sessionId);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -1,31 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapChatMessagesToStoredMessages = exports.mapStoredMessagesToChatMessages = void 0;
|
|
3
|
+
exports.mapChatMessagesToStoredMessages = exports.mapStoredMessagesToChatMessages = exports.mapV1MessageToStoredMessage = void 0;
|
|
4
4
|
const index_js_1 = require("../../schema/index.cjs");
|
|
5
|
+
function mapV1MessageToStoredMessage(message) {
|
|
6
|
+
// TODO: Remove this mapper when we deprecate the old message format.
|
|
7
|
+
if (message.data !== undefined) {
|
|
8
|
+
return message;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
const v1Message = message;
|
|
12
|
+
return {
|
|
13
|
+
type: v1Message.type,
|
|
14
|
+
data: {
|
|
15
|
+
content: v1Message.text,
|
|
16
|
+
role: v1Message.role,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.mapV1MessageToStoredMessage = mapV1MessageToStoredMessage;
|
|
5
22
|
function mapStoredMessagesToChatMessages(messages) {
|
|
6
23
|
return messages.map((message) => {
|
|
7
|
-
|
|
24
|
+
const storedMessage = mapV1MessageToStoredMessage(message);
|
|
25
|
+
switch (storedMessage.type) {
|
|
8
26
|
case "human":
|
|
9
|
-
return new index_js_1.HumanChatMessage(
|
|
27
|
+
return new index_js_1.HumanChatMessage(storedMessage.data.content);
|
|
10
28
|
case "ai":
|
|
11
|
-
return new index_js_1.AIChatMessage(
|
|
29
|
+
return new index_js_1.AIChatMessage(storedMessage.data.content);
|
|
12
30
|
case "system":
|
|
13
|
-
return new index_js_1.SystemChatMessage(
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
throw new Error("Role must be defined for
|
|
31
|
+
return new index_js_1.SystemChatMessage(storedMessage.data.content);
|
|
32
|
+
case "chat":
|
|
33
|
+
if (storedMessage.data?.additional_kwargs?.role === undefined) {
|
|
34
|
+
throw new Error("Role must be defined for chat messages");
|
|
17
35
|
}
|
|
18
|
-
return new index_js_1.ChatMessage(
|
|
19
|
-
|
|
36
|
+
return new index_js_1.ChatMessage(storedMessage.data.content, storedMessage.data.additional_kwargs.role);
|
|
37
|
+
default:
|
|
38
|
+
throw new Error(`Got unexpected type: ${storedMessage.type}`);
|
|
20
39
|
}
|
|
21
40
|
});
|
|
22
41
|
}
|
|
23
42
|
exports.mapStoredMessagesToChatMessages = mapStoredMessagesToChatMessages;
|
|
24
43
|
function mapChatMessagesToStoredMessages(messages) {
|
|
25
|
-
return messages.map((message) => (
|
|
26
|
-
type: message._getType(),
|
|
27
|
-
role: "role" in message ? message.role : undefined,
|
|
28
|
-
text: message.text,
|
|
29
|
-
}));
|
|
44
|
+
return messages.map((message) => message.toJSON());
|
|
30
45
|
}
|
|
31
46
|
exports.mapChatMessagesToStoredMessages = mapChatMessagesToStoredMessages;
|