langchain 0.0.172 → 0.0.174
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/agents/openai/output_parser.cjs +1 -0
- package/agents/openai/output_parser.d.ts +1 -0
- package/agents/openai/output_parser.js +1 -0
- package/agents/xml/output_parser.cjs +1 -0
- package/agents/xml/output_parser.d.ts +1 -0
- package/agents/xml/output_parser.js +1 -0
- package/dist/agents/index.cjs +3 -1
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.js +1 -0
- package/dist/agents/openai/index.cjs +8 -31
- package/dist/agents/openai/index.d.ts +2 -0
- package/dist/agents/openai/index.js +8 -31
- package/dist/agents/openai/output_parser.cjs +65 -0
- package/dist/agents/openai/output_parser.d.ts +22 -0
- package/dist/agents/openai/output_parser.js +61 -0
- package/dist/agents/toolkits/conversational_retrieval/tool.cjs +2 -1
- package/dist/agents/toolkits/conversational_retrieval/tool.js +2 -1
- package/dist/agents/xml/index.cjs +9 -25
- package/dist/agents/xml/index.d.ts +2 -7
- package/dist/agents/xml/index.js +8 -23
- package/dist/agents/xml/output_parser.cjs +44 -0
- package/dist/agents/xml/output_parser.d.ts +14 -0
- package/dist/agents/xml/output_parser.js +40 -0
- package/dist/callbacks/manager.cjs +2 -1
- package/dist/callbacks/manager.js +2 -1
- package/dist/document_loaders/fs/pdf.cjs +2 -1
- package/dist/document_loaders/fs/pdf.js +2 -1
- package/dist/document_loaders/web/pdf.cjs +2 -1
- package/dist/document_loaders/web/pdf.js +2 -1
- package/dist/load/import_map.cjs +5 -2
- package/dist/load/import_map.d.ts +3 -0
- package/dist/load/import_map.js +3 -0
- package/dist/memory/index.cjs +2 -1
- package/dist/memory/index.d.ts +1 -1
- package/dist/memory/index.js +1 -1
- package/dist/memory/vector_store.cjs +2 -1
- package/dist/memory/vector_store.js +2 -1
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +15 -18
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +12 -6
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +15 -18
- package/dist/storage/file_system.cjs +31 -11
- package/dist/storage/file_system.js +9 -9
- package/dist/tools/index.cjs +3 -1
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.js +1 -0
- package/dist/tools/render.cjs +19 -1
- package/dist/tools/render.d.ts +12 -0
- package/dist/tools/render.js +17 -0
- package/dist/tools/serpapi.d.ts +2 -2
- package/dist/tools/webbrowser.cjs +2 -1
- package/dist/tools/webbrowser.js +2 -1
- package/dist/util/document.cjs +12 -0
- package/dist/util/document.d.ts +9 -0
- package/dist/util/document.js +8 -0
- package/dist/vectorstores/cassandra.cjs +130 -35
- package/dist/vectorstores/cassandra.d.ts +21 -10
- package/dist/vectorstores/cassandra.js +130 -35
- package/dist/vectorstores/pgvector.cjs +13 -7
- package/dist/vectorstores/pgvector.d.ts +7 -0
- package/dist/vectorstores/pgvector.js +13 -7
- package/dist/vectorstores/pinecone.cjs +46 -9
- package/dist/vectorstores/pinecone.d.ts +20 -2
- package/dist/vectorstores/pinecone.js +46 -9
- package/package.json +27 -3
- package/util/document.cjs +1 -0
- package/util/document.d.ts +1 -0
- package/util/document.js +1 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Document } from "../../document.js";
|
|
2
2
|
import { BufferLoader } from "./buffer.js";
|
|
3
|
+
import { formatDocumentsAsString } from "../../util/document.js";
|
|
3
4
|
/**
|
|
4
5
|
* A class that extends the `BufferLoader` class. It represents a document
|
|
5
6
|
* loader that loads documents from PDF files.
|
|
@@ -82,7 +83,7 @@ export class PDFLoader extends BufferLoader {
|
|
|
82
83
|
}
|
|
83
84
|
return [
|
|
84
85
|
new Document({
|
|
85
|
-
pageContent: documents
|
|
86
|
+
pageContent: formatDocumentsAsString(documents),
|
|
86
87
|
metadata: {
|
|
87
88
|
...metadata,
|
|
88
89
|
pdf: {
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WebPDFLoader = void 0;
|
|
4
4
|
const document_js_1 = require("../../document.cjs");
|
|
5
5
|
const base_js_1 = require("../base.cjs");
|
|
6
|
+
const document_js_2 = require("../../util/document.cjs");
|
|
6
7
|
/**
|
|
7
8
|
* A document loader for loading data from PDFs.
|
|
8
9
|
*/
|
|
@@ -77,7 +78,7 @@ class WebPDFLoader extends base_js_1.BaseDocumentLoader {
|
|
|
77
78
|
}
|
|
78
79
|
return [
|
|
79
80
|
new document_js_1.Document({
|
|
80
|
-
pageContent:
|
|
81
|
+
pageContent: (0, document_js_2.formatDocumentsAsString)(documents),
|
|
81
82
|
metadata: {
|
|
82
83
|
pdf: {
|
|
83
84
|
version,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Document } from "../../document.js";
|
|
2
2
|
import { BaseDocumentLoader } from "../base.js";
|
|
3
|
+
import { formatDocumentsAsString } from "../../util/document.js";
|
|
3
4
|
/**
|
|
4
5
|
* A document loader for loading data from PDFs.
|
|
5
6
|
*/
|
|
@@ -74,7 +75,7 @@ export class WebPDFLoader extends BaseDocumentLoader {
|
|
|
74
75
|
}
|
|
75
76
|
return [
|
|
76
77
|
new Document({
|
|
77
|
-
pageContent: documents
|
|
78
|
+
pageContent: formatDocumentsAsString(documents),
|
|
78
79
|
metadata: {
|
|
79
80
|
pdf: {
|
|
80
81
|
version,
|
package/dist/load/import_map.cjs
CHANGED
|
@@ -24,8 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
return result;
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.
|
|
28
|
-
exports.runnables__remote = exports.evaluation = exports.experimental__chains__violation_of_expectations = exports.experimental__chat_models__bittensor = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__autogpt = exports.util__time = exports.util__math = exports.storage__in_memory = exports.storage__encoder_backed = exports.stores__message__in_memory = exports.stores__file__in_memory = exports.stores__doc__in_memory = exports.cache = exports.retrievers__vespa = exports.retrievers__score_threshold = exports.retrievers__hyde = exports.retrievers__document_compressors__embeddings_filter = exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__tavily_search_api = exports.retrievers__parent_document = exports.retrievers__multi_vector = exports.retrievers__multi_query = exports.retrievers__document_compressors = exports.retrievers__contextual_compression = exports.retrievers__databerry = exports.retrievers__chaindesk = exports.retrievers__remote = exports.output_parsers = exports.callbacks = exports.schema__storage = exports.schema__runnable = exports.schema__retriever = exports.schema__query_constructor = exports.schema__output_parser = exports.schema__document = exports.schema = exports.chat_models__fake = exports.chat_models__yandex = void 0;
|
|
27
|
+
exports.chat_models__baiduwenxin = exports.chat_models__fireworks = exports.chat_models__cloudflare_workersai = exports.chat_models__anthropic = exports.chat_models__openai = exports.chat_models__base = exports.document_transformers__openai_functions = exports.document_loaders__web__sort_xyz_blockchain = exports.document_loaders__web__serpapi = exports.document_loaders__web__searchapi = exports.document_loaders__base = exports.document = exports.memory = exports.text_splitter = exports.vectorstores__xata = exports.vectorstores__vectara = exports.vectorstores__prisma = exports.vectorstores__memory = exports.vectorstores__base = exports.prompts = exports.llms__fake = exports.llms__yandex = exports.llms__fireworks = exports.llms__ollama = exports.llms__cloudflare_workersai = exports.llms__aleph_alpha = exports.llms__ai21 = exports.llms__openai = exports.llms__base = exports.embeddings__minimax = exports.embeddings__openai = exports.embeddings__ollama = exports.embeddings__fake = exports.embeddings__cache_backed = exports.embeddings__base = exports.chains__openai_functions = exports.chains = exports.tools__render = exports.tools = exports.base_language = exports.agents__openai__output_parser = exports.agents__xml__output_parser = exports.agents__react__output_parser = exports.agents__format_scratchpad__log_to_message = exports.agents__format_scratchpad__xml = exports.agents__format_scratchpad__log = exports.agents__format_scratchpad = exports.agents__toolkits = exports.agents = exports.load__serializable = void 0;
|
|
28
|
+
exports.runnables__remote = exports.evaluation = exports.experimental__chains__violation_of_expectations = exports.experimental__chat_models__bittensor = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__autogpt = exports.util__time = exports.util__math = exports.util__document = exports.storage__in_memory = exports.storage__encoder_backed = exports.stores__message__in_memory = exports.stores__file__in_memory = exports.stores__doc__in_memory = exports.cache = exports.retrievers__vespa = exports.retrievers__score_threshold = exports.retrievers__hyde = exports.retrievers__document_compressors__embeddings_filter = exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__tavily_search_api = exports.retrievers__parent_document = exports.retrievers__multi_vector = exports.retrievers__multi_query = exports.retrievers__document_compressors = exports.retrievers__contextual_compression = exports.retrievers__databerry = exports.retrievers__chaindesk = exports.retrievers__remote = exports.output_parsers = exports.callbacks = exports.schema__storage = exports.schema__runnable = exports.schema__retriever = exports.schema__query_constructor = exports.schema__output_parser = exports.schema__document = exports.schema = exports.chat_models__fake = exports.chat_models__yandex = exports.chat_models__minimax = exports.chat_models__ollama = void 0;
|
|
29
29
|
exports.load__serializable = __importStar(require("../load/serializable.cjs"));
|
|
30
30
|
exports.agents = __importStar(require("../agents/index.cjs"));
|
|
31
31
|
exports.agents__toolkits = __importStar(require("../agents/toolkits/index.cjs"));
|
|
@@ -34,6 +34,8 @@ exports.agents__format_scratchpad__log = __importStar(require("../agents/format_
|
|
|
34
34
|
exports.agents__format_scratchpad__xml = __importStar(require("../agents/format_scratchpad/xml.cjs"));
|
|
35
35
|
exports.agents__format_scratchpad__log_to_message = __importStar(require("../agents/format_scratchpad/log_to_message.cjs"));
|
|
36
36
|
exports.agents__react__output_parser = __importStar(require("../agents/react/output_parser.cjs"));
|
|
37
|
+
exports.agents__xml__output_parser = __importStar(require("../agents/xml/output_parser.cjs"));
|
|
38
|
+
exports.agents__openai__output_parser = __importStar(require("../agents/openai/output_parser.cjs"));
|
|
37
39
|
exports.base_language = __importStar(require("../base_language/index.cjs"));
|
|
38
40
|
exports.tools = __importStar(require("../tools/index.cjs"));
|
|
39
41
|
exports.tools__render = __importStar(require("../tools/render.cjs"));
|
|
@@ -108,6 +110,7 @@ exports.stores__file__in_memory = __importStar(require("../stores/file/in_memory
|
|
|
108
110
|
exports.stores__message__in_memory = __importStar(require("../stores/message/in_memory.cjs"));
|
|
109
111
|
exports.storage__encoder_backed = __importStar(require("../storage/encoder_backed.cjs"));
|
|
110
112
|
exports.storage__in_memory = __importStar(require("../storage/in_memory.cjs"));
|
|
113
|
+
exports.util__document = __importStar(require("../util/document.cjs"));
|
|
111
114
|
exports.util__math = __importStar(require("../util/math.cjs"));
|
|
112
115
|
exports.util__time = __importStar(require("../util/time.cjs"));
|
|
113
116
|
exports.experimental__autogpt = __importStar(require("../experimental/autogpt/index.cjs"));
|
|
@@ -6,6 +6,8 @@ export * as agents__format_scratchpad__log from "../agents/format_scratchpad/log
|
|
|
6
6
|
export * as agents__format_scratchpad__xml from "../agents/format_scratchpad/xml.js";
|
|
7
7
|
export * as agents__format_scratchpad__log_to_message from "../agents/format_scratchpad/log_to_message.js";
|
|
8
8
|
export * as agents__react__output_parser from "../agents/react/output_parser.js";
|
|
9
|
+
export * as agents__xml__output_parser from "../agents/xml/output_parser.js";
|
|
10
|
+
export * as agents__openai__output_parser from "../agents/openai/output_parser.js";
|
|
9
11
|
export * as base_language from "../base_language/index.js";
|
|
10
12
|
export * as tools from "../tools/index.js";
|
|
11
13
|
export * as tools__render from "../tools/render.js";
|
|
@@ -80,6 +82,7 @@ export * as stores__file__in_memory from "../stores/file/in_memory.js";
|
|
|
80
82
|
export * as stores__message__in_memory from "../stores/message/in_memory.js";
|
|
81
83
|
export * as storage__encoder_backed from "../storage/encoder_backed.js";
|
|
82
84
|
export * as storage__in_memory from "../storage/in_memory.js";
|
|
85
|
+
export * as util__document from "../util/document.js";
|
|
83
86
|
export * as util__math from "../util/math.js";
|
|
84
87
|
export * as util__time from "../util/time.js";
|
|
85
88
|
export * as experimental__autogpt from "../experimental/autogpt/index.js";
|
package/dist/load/import_map.js
CHANGED
|
@@ -7,6 +7,8 @@ export * as agents__format_scratchpad__log from "../agents/format_scratchpad/log
|
|
|
7
7
|
export * as agents__format_scratchpad__xml from "../agents/format_scratchpad/xml.js";
|
|
8
8
|
export * as agents__format_scratchpad__log_to_message from "../agents/format_scratchpad/log_to_message.js";
|
|
9
9
|
export * as agents__react__output_parser from "../agents/react/output_parser.js";
|
|
10
|
+
export * as agents__xml__output_parser from "../agents/xml/output_parser.js";
|
|
11
|
+
export * as agents__openai__output_parser from "../agents/openai/output_parser.js";
|
|
10
12
|
export * as base_language from "../base_language/index.js";
|
|
11
13
|
export * as tools from "../tools/index.js";
|
|
12
14
|
export * as tools__render from "../tools/render.js";
|
|
@@ -81,6 +83,7 @@ export * as stores__file__in_memory from "../stores/file/in_memory.js";
|
|
|
81
83
|
export * as stores__message__in_memory from "../stores/message/in_memory.js";
|
|
82
84
|
export * as storage__encoder_backed from "../storage/encoder_backed.js";
|
|
83
85
|
export * as storage__in_memory from "../storage/in_memory.js";
|
|
86
|
+
export * as util__document from "../util/document.js";
|
|
84
87
|
export * as util__math from "../util/math.js";
|
|
85
88
|
export * as util__time from "../util/time.js";
|
|
86
89
|
export * as experimental__autogpt from "../experimental/autogpt/index.js";
|
package/dist/memory/index.cjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConversationSummaryBufferMemory = exports.CombinedMemory = exports.ENTITY_MEMORY_CONVERSATION_TEMPLATE = exports.EntityMemory = exports.VectorStoreRetrieverMemory = exports.MotorheadMemory = exports.ChatMessageHistory = exports.BaseChatMemory = exports.BufferWindowMemory = exports.BaseConversationSummaryMemory = exports.ConversationSummaryMemory = exports.getBufferString = exports.getInputValue = exports.BaseMemory = exports.BufferMemory = void 0;
|
|
3
|
+
exports.ConversationSummaryBufferMemory = exports.CombinedMemory = exports.ENTITY_MEMORY_CONVERSATION_TEMPLATE = exports.EntityMemory = exports.VectorStoreRetrieverMemory = exports.MotorheadMemory = exports.ChatMessageHistory = exports.BaseChatMemory = exports.BufferWindowMemory = exports.BaseConversationSummaryMemory = exports.ConversationSummaryMemory = exports.getBufferString = exports.getOutputValue = exports.getInputValue = exports.BaseMemory = exports.BufferMemory = void 0;
|
|
4
4
|
var buffer_memory_js_1 = require("./buffer_memory.cjs");
|
|
5
5
|
Object.defineProperty(exports, "BufferMemory", { enumerable: true, get: function () { return buffer_memory_js_1.BufferMemory; } });
|
|
6
6
|
var base_js_1 = require("./base.cjs");
|
|
7
7
|
Object.defineProperty(exports, "BaseMemory", { enumerable: true, get: function () { return base_js_1.BaseMemory; } });
|
|
8
8
|
Object.defineProperty(exports, "getInputValue", { enumerable: true, get: function () { return base_js_1.getInputValue; } });
|
|
9
|
+
Object.defineProperty(exports, "getOutputValue", { enumerable: true, get: function () { return base_js_1.getOutputValue; } });
|
|
9
10
|
Object.defineProperty(exports, "getBufferString", { enumerable: true, get: function () { return base_js_1.getBufferString; } });
|
|
10
11
|
var summary_js_1 = require("./summary.cjs");
|
|
11
12
|
Object.defineProperty(exports, "ConversationSummaryMemory", { enumerable: true, get: function () { return summary_js_1.ConversationSummaryMemory; } });
|
package/dist/memory/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { BufferMemory, type BufferMemoryInput } from "./buffer_memory.js";
|
|
2
|
-
export { BaseMemory, getInputValue, getBufferString, type InputValues, type OutputValues, type MemoryVariables, } from "./base.js";
|
|
2
|
+
export { BaseMemory, getInputValue, getOutputValue, getBufferString, type InputValues, type OutputValues, type MemoryVariables, } from "./base.js";
|
|
3
3
|
export { ConversationSummaryMemory, type ConversationSummaryMemoryInput, BaseConversationSummaryMemory, type BaseConversationSummaryMemoryInput, } from "./summary.js";
|
|
4
4
|
export { BufferWindowMemory, type BufferWindowMemoryInput, } from "./buffer_window_memory.js";
|
|
5
5
|
export { BaseChatMemory, type BaseChatMemoryInput } from "./chat_memory.js";
|
package/dist/memory/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { BufferMemory } from "./buffer_memory.js";
|
|
2
|
-
export { BaseMemory, getInputValue, getBufferString, } from "./base.js";
|
|
2
|
+
export { BaseMemory, getInputValue, getOutputValue, getBufferString, } from "./base.js";
|
|
3
3
|
export { ConversationSummaryMemory, BaseConversationSummaryMemory, } from "./summary.js";
|
|
4
4
|
export { BufferWindowMemory, } from "./buffer_window_memory.js";
|
|
5
5
|
export { BaseChatMemory } from "./chat_memory.js";
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VectorStoreRetrieverMemory = void 0;
|
|
4
4
|
const document_js_1 = require("../document.cjs");
|
|
5
|
+
const document_js_2 = require("../util/document.cjs");
|
|
5
6
|
const base_js_1 = require("./base.cjs");
|
|
6
7
|
/**
|
|
7
8
|
* Class for managing long-term memory in Large Language Model (LLM)
|
|
@@ -58,7 +59,7 @@ class VectorStoreRetrieverMemory extends base_js_1.BaseMemory {
|
|
|
58
59
|
return {
|
|
59
60
|
[this.memoryKey]: this.returnDocs
|
|
60
61
|
? results
|
|
61
|
-
:
|
|
62
|
+
: (0, document_js_2.formatDocumentsAsString)(results, "\n"),
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
65
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Document } from "../document.js";
|
|
2
|
+
import { formatDocumentsAsString } from "../util/document.js";
|
|
2
3
|
import { BaseMemory, getInputValue, } from "./base.js";
|
|
3
4
|
/**
|
|
4
5
|
* Class for managing long-term memory in Large Language Model (LLM)
|
|
@@ -55,7 +56,7 @@ export class VectorStoreRetrieverMemory extends BaseMemory {
|
|
|
55
56
|
return {
|
|
56
57
|
[this.memoryKey]: this.returnDocs
|
|
57
58
|
? results
|
|
58
|
-
: results
|
|
59
|
+
: formatDocumentsAsString(results, "\n"),
|
|
59
60
|
};
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
@@ -15,18 +15,12 @@ function sortedValues(values) {
|
|
|
15
15
|
class SemanticSimilarityExampleSelector extends base_js_1.BaseExampleSelector {
|
|
16
16
|
constructor(data) {
|
|
17
17
|
super(data);
|
|
18
|
-
Object.defineProperty(this, "
|
|
18
|
+
Object.defineProperty(this, "vectorStoreRetriever", {
|
|
19
19
|
enumerable: true,
|
|
20
20
|
configurable: true,
|
|
21
21
|
writable: true,
|
|
22
22
|
value: void 0
|
|
23
23
|
});
|
|
24
|
-
Object.defineProperty(this, "k", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
configurable: true,
|
|
27
|
-
writable: true,
|
|
28
|
-
value: 4
|
|
29
|
-
});
|
|
30
24
|
Object.defineProperty(this, "exampleKeys", {
|
|
31
25
|
enumerable: true,
|
|
32
26
|
configurable: true,
|
|
@@ -39,17 +33,20 @@ class SemanticSimilarityExampleSelector extends base_js_1.BaseExampleSelector {
|
|
|
39
33
|
writable: true,
|
|
40
34
|
value: void 0
|
|
41
35
|
});
|
|
42
|
-
Object.defineProperty(this, "filter", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
configurable: true,
|
|
45
|
-
writable: true,
|
|
46
|
-
value: void 0
|
|
47
|
-
});
|
|
48
|
-
this.vectorStore = data.vectorStore;
|
|
49
|
-
this.k = data.k ?? 4;
|
|
50
36
|
this.exampleKeys = data.exampleKeys;
|
|
51
37
|
this.inputKeys = data.inputKeys;
|
|
52
|
-
|
|
38
|
+
if (data.vectorStore !== undefined) {
|
|
39
|
+
this.vectorStoreRetriever = data.vectorStore.asRetriever({
|
|
40
|
+
k: data.k ?? 4,
|
|
41
|
+
filter: data.filter,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
else if (data.vectorStoreRetriever) {
|
|
45
|
+
this.vectorStoreRetriever = data.vectorStoreRetriever;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
throw new Error(`You must specify one of "vectorStore" and "vectorStoreRetriever".`);
|
|
49
|
+
}
|
|
53
50
|
}
|
|
54
51
|
/**
|
|
55
52
|
* Method that adds a new example to the vectorStore. The example is
|
|
@@ -60,7 +57,7 @@ class SemanticSimilarityExampleSelector extends base_js_1.BaseExampleSelector {
|
|
|
60
57
|
async addExample(example) {
|
|
61
58
|
const inputKeys = this.inputKeys ?? Object.keys(example);
|
|
62
59
|
const stringExample = sortedValues(inputKeys.reduce((acc, key) => ({ ...acc, [key]: example[key] }), {})).join(" ");
|
|
63
|
-
await this.
|
|
60
|
+
await this.vectorStoreRetriever.addDocuments([
|
|
64
61
|
new document_js_1.Document({
|
|
65
62
|
pageContent: stringExample,
|
|
66
63
|
metadata: example,
|
|
@@ -77,7 +74,7 @@ class SemanticSimilarityExampleSelector extends base_js_1.BaseExampleSelector {
|
|
|
77
74
|
async selectExamples(inputVariables) {
|
|
78
75
|
const inputKeys = this.inputKeys ?? Object.keys(inputVariables);
|
|
79
76
|
const query = sortedValues(inputKeys.reduce((acc, key) => ({ ...acc, [key]: inputVariables[key] }), {})).join(" ");
|
|
80
|
-
const exampleDocs = await this.
|
|
77
|
+
const exampleDocs = await this.vectorStoreRetriever.invoke(query);
|
|
81
78
|
const examples = exampleDocs.map((doc) => doc.metadata);
|
|
82
79
|
if (this.exampleKeys) {
|
|
83
80
|
// If example keys are provided, filter examples to those keys.
|
|
@@ -1,28 +1,34 @@
|
|
|
1
1
|
import { Embeddings } from "../../embeddings/base.js";
|
|
2
|
-
import { VectorStore } from "../../vectorstores/base.js";
|
|
2
|
+
import { VectorStore, VectorStoreRetriever } from "../../vectorstores/base.js";
|
|
3
3
|
import { Example } from "../../schema/index.js";
|
|
4
4
|
import { BaseExampleSelector } from "../base.js";
|
|
5
5
|
/**
|
|
6
6
|
* Interface for the input data of the SemanticSimilarityExampleSelector
|
|
7
7
|
* class.
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
9
|
+
export type SemanticSimilarityExampleSelectorInput<V extends VectorStore = VectorStore> = {
|
|
10
10
|
vectorStore: V;
|
|
11
11
|
k?: number;
|
|
12
12
|
filter?: V["FilterType"];
|
|
13
13
|
exampleKeys?: string[];
|
|
14
14
|
inputKeys?: string[];
|
|
15
|
-
|
|
15
|
+
vectorStoreRetriever?: never;
|
|
16
|
+
} | {
|
|
17
|
+
vectorStoreRetriever: VectorStoreRetriever<V>;
|
|
18
|
+
exampleKeys?: string[];
|
|
19
|
+
inputKeys?: string[];
|
|
20
|
+
vectorStore?: never;
|
|
21
|
+
k?: never;
|
|
22
|
+
filter?: never;
|
|
23
|
+
};
|
|
16
24
|
/**
|
|
17
25
|
* Class that selects examples based on semantic similarity. It extends
|
|
18
26
|
* the BaseExampleSelector class.
|
|
19
27
|
*/
|
|
20
28
|
export declare class SemanticSimilarityExampleSelector<V extends VectorStore = VectorStore> extends BaseExampleSelector {
|
|
21
|
-
|
|
22
|
-
k: number;
|
|
29
|
+
vectorStoreRetriever: VectorStoreRetriever<V>;
|
|
23
30
|
exampleKeys?: string[];
|
|
24
31
|
inputKeys?: string[];
|
|
25
|
-
filter?: V["FilterType"];
|
|
26
32
|
constructor(data: SemanticSimilarityExampleSelectorInput<V>);
|
|
27
33
|
/**
|
|
28
34
|
* Method that adds a new example to the vectorStore. The example is
|
|
@@ -12,18 +12,12 @@ function sortedValues(values) {
|
|
|
12
12
|
export class SemanticSimilarityExampleSelector extends BaseExampleSelector {
|
|
13
13
|
constructor(data) {
|
|
14
14
|
super(data);
|
|
15
|
-
Object.defineProperty(this, "
|
|
15
|
+
Object.defineProperty(this, "vectorStoreRetriever", {
|
|
16
16
|
enumerable: true,
|
|
17
17
|
configurable: true,
|
|
18
18
|
writable: true,
|
|
19
19
|
value: void 0
|
|
20
20
|
});
|
|
21
|
-
Object.defineProperty(this, "k", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true,
|
|
25
|
-
value: 4
|
|
26
|
-
});
|
|
27
21
|
Object.defineProperty(this, "exampleKeys", {
|
|
28
22
|
enumerable: true,
|
|
29
23
|
configurable: true,
|
|
@@ -36,17 +30,20 @@ export class SemanticSimilarityExampleSelector extends BaseExampleSelector {
|
|
|
36
30
|
writable: true,
|
|
37
31
|
value: void 0
|
|
38
32
|
});
|
|
39
|
-
Object.defineProperty(this, "filter", {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
configurable: true,
|
|
42
|
-
writable: true,
|
|
43
|
-
value: void 0
|
|
44
|
-
});
|
|
45
|
-
this.vectorStore = data.vectorStore;
|
|
46
|
-
this.k = data.k ?? 4;
|
|
47
33
|
this.exampleKeys = data.exampleKeys;
|
|
48
34
|
this.inputKeys = data.inputKeys;
|
|
49
|
-
|
|
35
|
+
if (data.vectorStore !== undefined) {
|
|
36
|
+
this.vectorStoreRetriever = data.vectorStore.asRetriever({
|
|
37
|
+
k: data.k ?? 4,
|
|
38
|
+
filter: data.filter,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else if (data.vectorStoreRetriever) {
|
|
42
|
+
this.vectorStoreRetriever = data.vectorStoreRetriever;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
throw new Error(`You must specify one of "vectorStore" and "vectorStoreRetriever".`);
|
|
46
|
+
}
|
|
50
47
|
}
|
|
51
48
|
/**
|
|
52
49
|
* Method that adds a new example to the vectorStore. The example is
|
|
@@ -57,7 +54,7 @@ export class SemanticSimilarityExampleSelector extends BaseExampleSelector {
|
|
|
57
54
|
async addExample(example) {
|
|
58
55
|
const inputKeys = this.inputKeys ?? Object.keys(example);
|
|
59
56
|
const stringExample = sortedValues(inputKeys.reduce((acc, key) => ({ ...acc, [key]: example[key] }), {})).join(" ");
|
|
60
|
-
await this.
|
|
57
|
+
await this.vectorStoreRetriever.addDocuments([
|
|
61
58
|
new Document({
|
|
62
59
|
pageContent: stringExample,
|
|
63
60
|
metadata: example,
|
|
@@ -74,7 +71,7 @@ export class SemanticSimilarityExampleSelector extends BaseExampleSelector {
|
|
|
74
71
|
async selectExamples(inputVariables) {
|
|
75
72
|
const inputKeys = this.inputKeys ?? Object.keys(inputVariables);
|
|
76
73
|
const query = sortedValues(inputKeys.reduce((acc, key) => ({ ...acc, [key]: inputVariables[key] }), {})).join(" ");
|
|
77
|
-
const exampleDocs = await this.
|
|
74
|
+
const exampleDocs = await this.vectorStoreRetriever.invoke(query);
|
|
78
75
|
const examples = exampleDocs.map((doc) => doc.metadata);
|
|
79
76
|
if (this.exampleKeys) {
|
|
80
77
|
// If example keys are provided, filter examples to those keys.
|
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
4
24
|
};
|
|
5
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
26
|
exports.LocalFileStore = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
27
|
+
const fs = __importStar(require("node:fs/promises"));
|
|
28
|
+
const path = __importStar(require("node:path"));
|
|
9
29
|
const storage_js_1 = require("../schema/storage.cjs");
|
|
10
30
|
/**
|
|
11
31
|
* File system implementation of the BaseStore using a dictionary. Used for
|
|
@@ -35,7 +55,7 @@ class LocalFileStore extends storage_js_1.BaseStore {
|
|
|
35
55
|
*/
|
|
36
56
|
async getParsedFile(key) {
|
|
37
57
|
try {
|
|
38
|
-
const fileContent = await
|
|
58
|
+
const fileContent = await fs.readFile(this.getFullPath(key));
|
|
39
59
|
if (!fileContent) {
|
|
40
60
|
return undefined;
|
|
41
61
|
}
|
|
@@ -57,7 +77,7 @@ class LocalFileStore extends storage_js_1.BaseStore {
|
|
|
57
77
|
*/
|
|
58
78
|
async setFileContent(content, key) {
|
|
59
79
|
try {
|
|
60
|
-
await
|
|
80
|
+
await fs.writeFile(this.getFullPath(key), content);
|
|
61
81
|
}
|
|
62
82
|
catch (error) {
|
|
63
83
|
throw new Error(`Error writing file at path: ${this.getFullPath(key)}.\nError: ${JSON.stringify(error)}`);
|
|
@@ -70,7 +90,7 @@ class LocalFileStore extends storage_js_1.BaseStore {
|
|
|
70
90
|
getFullPath(key) {
|
|
71
91
|
try {
|
|
72
92
|
const keyAsTxtFile = `${key}.txt`;
|
|
73
|
-
const fullPath =
|
|
93
|
+
const fullPath = path.join(this.rootPath, keyAsTxtFile);
|
|
74
94
|
return fullPath;
|
|
75
95
|
}
|
|
76
96
|
catch (e) {
|
|
@@ -104,7 +124,7 @@ class LocalFileStore extends storage_js_1.BaseStore {
|
|
|
104
124
|
* @returns Promise that resolves when all keys have been deleted.
|
|
105
125
|
*/
|
|
106
126
|
async mdelete(keys) {
|
|
107
|
-
await Promise.all(keys.map((key) =>
|
|
127
|
+
await Promise.all(keys.map((key) => fs.unlink(this.getFullPath(key))));
|
|
108
128
|
}
|
|
109
129
|
/**
|
|
110
130
|
* Asynchronous generator that yields keys from the store. If a prefix is
|
|
@@ -113,7 +133,7 @@ class LocalFileStore extends storage_js_1.BaseStore {
|
|
|
113
133
|
* @returns AsyncGenerator that yields keys from the store.
|
|
114
134
|
*/
|
|
115
135
|
async *yieldKeys(prefix) {
|
|
116
|
-
const allFiles = await
|
|
136
|
+
const allFiles = await fs.readdir(this.rootPath);
|
|
117
137
|
const allKeys = allFiles.map((file) => file.replace(".txt", ""));
|
|
118
138
|
for (const key of allKeys) {
|
|
119
139
|
if (prefix === undefined || key.startsWith(prefix)) {
|
|
@@ -130,12 +150,12 @@ class LocalFileStore extends storage_js_1.BaseStore {
|
|
|
130
150
|
static async fromPath(rootPath) {
|
|
131
151
|
try {
|
|
132
152
|
// Verifies the directory exists at the provided path, and that it is readable and writable.
|
|
133
|
-
await
|
|
153
|
+
await fs.access(rootPath, fs.constants.R_OK | fs.constants.W_OK);
|
|
134
154
|
}
|
|
135
155
|
catch (_) {
|
|
136
156
|
try {
|
|
137
157
|
// Directory does not exist, create it.
|
|
138
|
-
await
|
|
158
|
+
await fs.mkdir(rootPath, { recursive: true });
|
|
139
159
|
}
|
|
140
160
|
catch (error) {
|
|
141
161
|
throw new Error(`An error occurred creating directory at: ${rootPath}.\nError: ${JSON.stringify(error)}`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import * as path from "node:path";
|
|
3
3
|
import { BaseStore } from "../schema/storage.js";
|
|
4
4
|
/**
|
|
5
5
|
* File system implementation of the BaseStore using a dictionary. Used for
|
|
@@ -29,7 +29,7 @@ export class LocalFileStore extends BaseStore {
|
|
|
29
29
|
*/
|
|
30
30
|
async getParsedFile(key) {
|
|
31
31
|
try {
|
|
32
|
-
const fileContent = await
|
|
32
|
+
const fileContent = await fs.readFile(this.getFullPath(key));
|
|
33
33
|
if (!fileContent) {
|
|
34
34
|
return undefined;
|
|
35
35
|
}
|
|
@@ -51,7 +51,7 @@ export class LocalFileStore extends BaseStore {
|
|
|
51
51
|
*/
|
|
52
52
|
async setFileContent(content, key) {
|
|
53
53
|
try {
|
|
54
|
-
await
|
|
54
|
+
await fs.writeFile(this.getFullPath(key), content);
|
|
55
55
|
}
|
|
56
56
|
catch (error) {
|
|
57
57
|
throw new Error(`Error writing file at path: ${this.getFullPath(key)}.\nError: ${JSON.stringify(error)}`);
|
|
@@ -64,7 +64,7 @@ export class LocalFileStore extends BaseStore {
|
|
|
64
64
|
getFullPath(key) {
|
|
65
65
|
try {
|
|
66
66
|
const keyAsTxtFile = `${key}.txt`;
|
|
67
|
-
const fullPath =
|
|
67
|
+
const fullPath = path.join(this.rootPath, keyAsTxtFile);
|
|
68
68
|
return fullPath;
|
|
69
69
|
}
|
|
70
70
|
catch (e) {
|
|
@@ -98,7 +98,7 @@ export class LocalFileStore extends BaseStore {
|
|
|
98
98
|
* @returns Promise that resolves when all keys have been deleted.
|
|
99
99
|
*/
|
|
100
100
|
async mdelete(keys) {
|
|
101
|
-
await Promise.all(keys.map((key) =>
|
|
101
|
+
await Promise.all(keys.map((key) => fs.unlink(this.getFullPath(key))));
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
104
104
|
* Asynchronous generator that yields keys from the store. If a prefix is
|
|
@@ -107,7 +107,7 @@ export class LocalFileStore extends BaseStore {
|
|
|
107
107
|
* @returns AsyncGenerator that yields keys from the store.
|
|
108
108
|
*/
|
|
109
109
|
async *yieldKeys(prefix) {
|
|
110
|
-
const allFiles = await
|
|
110
|
+
const allFiles = await fs.readdir(this.rootPath);
|
|
111
111
|
const allKeys = allFiles.map((file) => file.replace(".txt", ""));
|
|
112
112
|
for (const key of allKeys) {
|
|
113
113
|
if (prefix === undefined || key.startsWith(prefix)) {
|
|
@@ -124,12 +124,12 @@ export class LocalFileStore extends BaseStore {
|
|
|
124
124
|
static async fromPath(rootPath) {
|
|
125
125
|
try {
|
|
126
126
|
// Verifies the directory exists at the provided path, and that it is readable and writable.
|
|
127
|
-
await
|
|
127
|
+
await fs.access(rootPath, fs.constants.R_OK | fs.constants.W_OK);
|
|
128
128
|
}
|
|
129
129
|
catch (_) {
|
|
130
130
|
try {
|
|
131
131
|
// Directory does not exist, create it.
|
|
132
|
-
await
|
|
132
|
+
await fs.mkdir(rootPath, { recursive: true });
|
|
133
133
|
}
|
|
134
134
|
catch (error) {
|
|
135
135
|
throw new Error(`An error occurred creating directory at: ${rootPath}.\nError: ${JSON.stringify(error)}`);
|
package/dist/tools/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SearchApi = exports.SearxngSearch = exports.DataForSeoAPISearch = exports.WolframAlphaTool = exports.WikipediaQueryRun = exports.BraveSearch = exports.WriteFileTool = exports.ReadFileTool = exports.AIPluginTool = exports.GoogleCustomSearch = exports.Serper = exports.ZapierNLAWrapper = exports.ZapierNLARunAction = exports.VectorStoreQATool = exports.RequestsPostTool = exports.RequestsGetTool = exports.JsonGetValueTool = exports.JsonListKeysTool = exports.JsonSpec = exports.ChainTool = exports.IFTTTWebhook = exports.DynamicStructuredTool = exports.DynamicTool = exports.StructuredTool = exports.Tool = exports.BingSerpAPI = exports.DadJokeAPI = exports.SerpAPI = void 0;
|
|
3
|
+
exports.formatToOpenAIFunction = exports.SearchApi = exports.SearxngSearch = exports.DataForSeoAPISearch = exports.WolframAlphaTool = exports.WikipediaQueryRun = exports.BraveSearch = exports.WriteFileTool = exports.ReadFileTool = exports.AIPluginTool = exports.GoogleCustomSearch = exports.Serper = exports.ZapierNLAWrapper = exports.ZapierNLARunAction = exports.VectorStoreQATool = exports.RequestsPostTool = exports.RequestsGetTool = exports.JsonGetValueTool = exports.JsonListKeysTool = exports.JsonSpec = exports.ChainTool = exports.IFTTTWebhook = exports.DynamicStructuredTool = exports.DynamicTool = exports.StructuredTool = exports.Tool = exports.BingSerpAPI = exports.DadJokeAPI = exports.SerpAPI = void 0;
|
|
4
4
|
var serpapi_js_1 = require("./serpapi.cjs");
|
|
5
5
|
Object.defineProperty(exports, "SerpAPI", { enumerable: true, get: function () { return serpapi_js_1.SerpAPI; } });
|
|
6
6
|
var dadjokeapi_js_1 = require("./dadjokeapi.cjs");
|
|
@@ -50,3 +50,5 @@ var searxng_search_js_1 = require("./searxng_search.cjs");
|
|
|
50
50
|
Object.defineProperty(exports, "SearxngSearch", { enumerable: true, get: function () { return searxng_search_js_1.SearxngSearch; } });
|
|
51
51
|
var searchapi_js_1 = require("./searchapi.cjs");
|
|
52
52
|
Object.defineProperty(exports, "SearchApi", { enumerable: true, get: function () { return searchapi_js_1.SearchApi; } });
|
|
53
|
+
var convert_to_openai_js_1 = require("./convert_to_openai.cjs");
|
|
54
|
+
Object.defineProperty(exports, "formatToOpenAIFunction", { enumerable: true, get: function () { return convert_to_openai_js_1.formatToOpenAIFunction; } });
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -19,3 +19,4 @@ export { WolframAlphaTool } from "./wolframalpha.js";
|
|
|
19
19
|
export { DataForSeoAPISearch, type DataForSeoApiConfig, } from "./dataforseo_api_search.js";
|
|
20
20
|
export { SearxngSearch } from "./searxng_search.js";
|
|
21
21
|
export { SearchApi, type SearchApiParameters } from "./searchapi.js";
|
|
22
|
+
export { formatToOpenAIFunction } from "./convert_to_openai.js";
|
package/dist/tools/index.js
CHANGED
|
@@ -19,3 +19,4 @@ export { WolframAlphaTool } from "./wolframalpha.js";
|
|
|
19
19
|
export { DataForSeoAPISearch, } from "./dataforseo_api_search.js";
|
|
20
20
|
export { SearxngSearch } from "./searxng_search.js";
|
|
21
21
|
export { SearchApi } from "./searchapi.js";
|
|
22
|
+
export { formatToOpenAIFunction } from "./convert_to_openai.js";
|
package/dist/tools/render.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.renderTextDescription = void 0;
|
|
3
|
+
exports.renderTextDescriptionAndArgs = exports.renderTextDescription = void 0;
|
|
4
|
+
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
4
5
|
/**
|
|
5
6
|
* Render the tool name and description in plain text.
|
|
6
7
|
*
|
|
@@ -16,3 +17,20 @@ function renderTextDescription(tools) {
|
|
|
16
17
|
return tools.map((tool) => `${tool.name}: ${tool.description}`).join("\n");
|
|
17
18
|
}
|
|
18
19
|
exports.renderTextDescription = renderTextDescription;
|
|
20
|
+
/**
|
|
21
|
+
* Render the tool name, description, and args in plain text.
|
|
22
|
+
* Output will be in the format of:'
|
|
23
|
+
* ```
|
|
24
|
+
* search: This tool is used for search, args: {"query": {"type": "string"}}
|
|
25
|
+
* calculator: This tool is used for math,
|
|
26
|
+
* args: {"expression": {"type": "string"}}
|
|
27
|
+
* ```
|
|
28
|
+
* @param tools
|
|
29
|
+
* @returns a string of all tools, their descriptions and a stringified version of their schemas
|
|
30
|
+
*/
|
|
31
|
+
function renderTextDescriptionAndArgs(tools) {
|
|
32
|
+
return tools
|
|
33
|
+
.map((tool) => `${tool.name}: ${tool.description}, args: ${JSON.stringify((0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema).properties)}`)
|
|
34
|
+
.join("\n");
|
|
35
|
+
}
|
|
36
|
+
exports.renderTextDescriptionAndArgs = renderTextDescriptionAndArgs;
|
package/dist/tools/render.d.ts
CHANGED
|
@@ -11,3 +11,15 @@ import { StructuredTool } from "./base.js";
|
|
|
11
11
|
* @returns a string of all tools and their descriptions
|
|
12
12
|
*/
|
|
13
13
|
export declare function renderTextDescription(tools: StructuredTool[]): string;
|
|
14
|
+
/**
|
|
15
|
+
* Render the tool name, description, and args in plain text.
|
|
16
|
+
* Output will be in the format of:'
|
|
17
|
+
* ```
|
|
18
|
+
* search: This tool is used for search, args: {"query": {"type": "string"}}
|
|
19
|
+
* calculator: This tool is used for math,
|
|
20
|
+
* args: {"expression": {"type": "string"}}
|
|
21
|
+
* ```
|
|
22
|
+
* @param tools
|
|
23
|
+
* @returns a string of all tools, their descriptions and a stringified version of their schemas
|
|
24
|
+
*/
|
|
25
|
+
export declare function renderTextDescriptionAndArgs(tools: StructuredTool[]): string;
|
package/dist/tools/render.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
1
2
|
/**
|
|
2
3
|
* Render the tool name and description in plain text.
|
|
3
4
|
*
|
|
@@ -12,3 +13,19 @@
|
|
|
12
13
|
export function renderTextDescription(tools) {
|
|
13
14
|
return tools.map((tool) => `${tool.name}: ${tool.description}`).join("\n");
|
|
14
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Render the tool name, description, and args in plain text.
|
|
18
|
+
* Output will be in the format of:'
|
|
19
|
+
* ```
|
|
20
|
+
* search: This tool is used for search, args: {"query": {"type": "string"}}
|
|
21
|
+
* calculator: This tool is used for math,
|
|
22
|
+
* args: {"expression": {"type": "string"}}
|
|
23
|
+
* ```
|
|
24
|
+
* @param tools
|
|
25
|
+
* @returns a string of all tools, their descriptions and a stringified version of their schemas
|
|
26
|
+
*/
|
|
27
|
+
export function renderTextDescriptionAndArgs(tools) {
|
|
28
|
+
return tools
|
|
29
|
+
.map((tool) => `${tool.name}: ${tool.description}, args: ${JSON.stringify(zodToJsonSchema(tool.schema).properties)}`)
|
|
30
|
+
.join("\n");
|
|
31
|
+
}
|