langchain 0.1.1 → 0.1.3
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/dist/agents/agent.cjs +1 -1
- package/dist/agents/agent.d.ts +1 -1
- package/dist/agents/agent.js +1 -1
- package/dist/agents/openai_functions/index.cjs +3 -3
- package/dist/agents/openai_functions/index.js +3 -3
- package/dist/agents/openai_functions/output_parser.cjs +1 -1
- package/dist/agents/openai_functions/output_parser.d.ts +1 -1
- package/dist/agents/openai_functions/output_parser.js +1 -1
- package/dist/agents/openai_tools/index.cjs +2 -2
- package/dist/agents/openai_tools/index.js +2 -2
- package/dist/agents/openai_tools/output_parser.cjs +1 -1
- package/dist/agents/openai_tools/output_parser.d.ts +1 -1
- package/dist/agents/openai_tools/output_parser.js +1 -1
- package/dist/cache/cloudflare_kv.cjs +2 -1
- package/dist/cache/cloudflare_kv.js +2 -1
- package/dist/chains/history_aware_retriever.cjs +1 -1
- package/dist/chains/history_aware_retriever.d.ts +1 -1
- package/dist/chains/history_aware_retriever.js +1 -1
- package/dist/chains/openai_functions/index.d.ts +1 -1
- package/dist/chains/sql_db/sql_db_prompt.cjs +20 -1
- package/dist/chains/sql_db/sql_db_prompt.d.ts +6 -0
- package/dist/chains/sql_db/sql_db_prompt.js +19 -0
- package/dist/chat_models/cloudflare_workersai.cjs +2 -0
- package/dist/chat_models/cloudflare_workersai.js +2 -0
- package/dist/embeddings/cloudflare_workersai.cjs +2 -0
- package/dist/embeddings/cloudflare_workersai.js +2 -0
- package/dist/evaluation/agents/trajectory.d.ts +2 -2
- package/dist/evaluation/base.d.ts +7 -6
- package/dist/evaluation/comparison/pairwise.d.ts +2 -2
- package/dist/evaluation/criteria/criteria.d.ts +2 -2
- package/dist/experimental/chat_models/anthropic_functions.cjs +2 -2
- package/dist/experimental/chat_models/anthropic_functions.js +2 -2
- package/dist/experimental/chat_models/ollama_functions.d.ts +1 -0
- package/dist/experimental/prompts/custom_format.cjs +68 -0
- package/dist/experimental/prompts/custom_format.d.ts +24 -0
- package/dist/experimental/prompts/custom_format.js +64 -0
- package/dist/experimental/prompts/handlebars.cjs +71 -0
- package/dist/experimental/prompts/handlebars.d.ts +13 -0
- package/dist/experimental/prompts/handlebars.js +62 -0
- package/dist/llms/cloudflare_workersai.cjs +2 -0
- package/dist/llms/cloudflare_workersai.js +2 -0
- package/dist/load/import_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- package/dist/load/import_map.cjs +2 -1
- package/dist/load/import_map.d.ts +1 -0
- package/dist/load/import_map.js +1 -0
- package/dist/output_parsers/datetime.cjs +63 -0
- package/dist/output_parsers/datetime.d.ts +27 -0
- package/dist/output_parsers/datetime.js +59 -0
- package/dist/output_parsers/index.cjs +3 -1
- package/dist/output_parsers/index.d.ts +1 -0
- package/dist/output_parsers/index.js +1 -0
- package/dist/output_parsers/openai_functions.cjs +8 -3
- package/dist/output_parsers/openai_functions.d.ts +3 -0
- package/dist/output_parsers/openai_functions.js +8 -3
- package/dist/output_parsers/openai_tools.cjs +18 -5
- package/dist/output_parsers/openai_tools.d.ts +4 -0
- package/dist/output_parsers/openai_tools.js +18 -5
- package/dist/stores/message/cloudflare_d1.cjs +2 -0
- package/dist/stores/message/cloudflare_d1.js +2 -0
- package/dist/tools/convert_to_openai.cjs +3 -26
- package/dist/tools/convert_to_openai.d.ts +2 -8
- package/dist/tools/convert_to_openai.js +2 -24
- package/dist/util/sql_utils.cjs +23 -0
- package/dist/util/sql_utils.js +24 -1
- package/dist/vectorstores/cloudflare_vectorize.cjs +2 -0
- package/dist/vectorstores/cloudflare_vectorize.js +2 -0
- package/experimental/prompts/custom_format.cjs +1 -0
- package/experimental/prompts/custom_format.d.ts +1 -0
- package/experimental/prompts/custom_format.js +1 -0
- package/experimental/prompts/handlebars.cjs +1 -0
- package/experimental/prompts/handlebars.d.ts +1 -0
- package/experimental/prompts/handlebars.js +1 -0
- package/package.json +26 -4
package/dist/agents/agent.cjs
CHANGED
|
@@ -82,7 +82,7 @@ function isAgentAction(input) {
|
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
84
|
* Class representing a single action agent which accepts runnables.
|
|
85
|
-
* Extends the
|
|
85
|
+
* Extends the BaseMultiActionAgent class and provides methods for
|
|
86
86
|
* planning agent actions with runnables.
|
|
87
87
|
*/
|
|
88
88
|
class RunnableAgent extends BaseMultiActionAgent {
|
package/dist/agents/agent.d.ts
CHANGED
|
@@ -77,7 +77,7 @@ export declare abstract class BaseMultiActionAgent extends BaseAgent {
|
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
79
|
* Class representing a single action agent which accepts runnables.
|
|
80
|
-
* Extends the
|
|
80
|
+
* Extends the BaseMultiActionAgent class and provides methods for
|
|
81
81
|
* planning agent actions with runnables.
|
|
82
82
|
*/
|
|
83
83
|
export declare class RunnableAgent extends BaseMultiActionAgent {
|
package/dist/agents/agent.js
CHANGED
|
@@ -76,7 +76,7 @@ function isAgentAction(input) {
|
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* Class representing a single action agent which accepts runnables.
|
|
79
|
-
* Extends the
|
|
79
|
+
* Extends the BaseMultiActionAgent class and provides methods for
|
|
80
80
|
* planning agent actions with runnables.
|
|
81
81
|
*/
|
|
82
82
|
export class RunnableAgent extends BaseMultiActionAgent {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createOpenAIFunctionsAgent = exports.OpenAIAgent = exports._formatIntermediateSteps = void 0;
|
|
4
4
|
const runnables_1 = require("@langchain/core/runnables");
|
|
5
|
-
const
|
|
5
|
+
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
6
6
|
const messages_1 = require("@langchain/core/messages");
|
|
7
7
|
const prompts_1 = require("@langchain/core/prompts");
|
|
8
8
|
const agent_js_1 = require("../agent.cjs");
|
|
@@ -145,7 +145,7 @@ class OpenAIAgent extends agent_js_1.Agent {
|
|
|
145
145
|
const llm = this.llmChain.llm;
|
|
146
146
|
const valuesForPrompt = { ...newInputs };
|
|
147
147
|
const valuesForLLM = {
|
|
148
|
-
functions: this.tools.map(
|
|
148
|
+
functions: this.tools.map(function_calling_1.convertToOpenAIFunction),
|
|
149
149
|
};
|
|
150
150
|
const callKeys = "callKeys" in this.llmChain.llm ? this.llmChain.llm.callKeys : [];
|
|
151
151
|
for (const key of callKeys) {
|
|
@@ -227,7 +227,7 @@ async function createOpenAIFunctionsAgent({ llm, tools, prompt, }) {
|
|
|
227
227
|
].join("\n"));
|
|
228
228
|
}
|
|
229
229
|
const llmWithTools = llm.bind({
|
|
230
|
-
functions: tools.map(
|
|
230
|
+
functions: tools.map(function_calling_1.convertToOpenAIFunction),
|
|
231
231
|
});
|
|
232
232
|
const agent = runnables_1.RunnableSequence.from([
|
|
233
233
|
runnables_1.RunnablePassthrough.assign({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RunnablePassthrough, RunnableSequence, } from "@langchain/core/runnables";
|
|
2
|
-
import {
|
|
2
|
+
import { convertToOpenAIFunction } from "@langchain/core/utils/function_calling";
|
|
3
3
|
import { AIMessage, FunctionMessage, } from "@langchain/core/messages";
|
|
4
4
|
import { ChatPromptTemplate, HumanMessagePromptTemplate, MessagesPlaceholder, SystemMessagePromptTemplate, } from "@langchain/core/prompts";
|
|
5
5
|
import { Agent } from "../agent.js";
|
|
@@ -141,7 +141,7 @@ export class OpenAIAgent extends Agent {
|
|
|
141
141
|
const llm = this.llmChain.llm;
|
|
142
142
|
const valuesForPrompt = { ...newInputs };
|
|
143
143
|
const valuesForLLM = {
|
|
144
|
-
functions: this.tools.map(
|
|
144
|
+
functions: this.tools.map(convertToOpenAIFunction),
|
|
145
145
|
};
|
|
146
146
|
const callKeys = "callKeys" in this.llmChain.llm ? this.llmChain.llm.callKeys : [];
|
|
147
147
|
for (const key of callKeys) {
|
|
@@ -222,7 +222,7 @@ export async function createOpenAIFunctionsAgent({ llm, tools, prompt, }) {
|
|
|
222
222
|
].join("\n"));
|
|
223
223
|
}
|
|
224
224
|
const llmWithTools = llm.bind({
|
|
225
|
-
functions: tools.map(
|
|
225
|
+
functions: tools.map(convertToOpenAIFunction),
|
|
226
226
|
});
|
|
227
227
|
const agent = RunnableSequence.from([
|
|
228
228
|
RunnablePassthrough.assign({
|
|
@@ -18,7 +18,7 @@ const types_js_1 = require("../types.cjs");
|
|
|
18
18
|
* modelName: "gpt-4",
|
|
19
19
|
* temperature: 0,
|
|
20
20
|
* }).bind({
|
|
21
|
-
* functions: tools.map((tool) =>
|
|
21
|
+
* functions: tools.map((tool) => convertToOpenAIFunction(tool)),
|
|
22
22
|
* });
|
|
23
23
|
*
|
|
24
24
|
* const runnableAgent = RunnableSequence.from([
|
|
@@ -22,7 +22,7 @@ export type FunctionsAgentAction = AgentAction & {
|
|
|
22
22
|
* modelName: "gpt-4",
|
|
23
23
|
* temperature: 0,
|
|
24
24
|
* }).bind({
|
|
25
|
-
* functions: tools.map((tool) =>
|
|
25
|
+
* functions: tools.map((tool) => convertToOpenAIFunction(tool)),
|
|
26
26
|
* });
|
|
27
27
|
*
|
|
28
28
|
* const runnableAgent = RunnableSequence.from([
|
|
@@ -15,7 +15,7 @@ import { AgentActionOutputParser } from "../types.js";
|
|
|
15
15
|
* modelName: "gpt-4",
|
|
16
16
|
* temperature: 0,
|
|
17
17
|
* }).bind({
|
|
18
|
-
* functions: tools.map((tool) =>
|
|
18
|
+
* functions: tools.map((tool) => convertToOpenAIFunction(tool)),
|
|
19
19
|
* });
|
|
20
20
|
*
|
|
21
21
|
* const runnableAgent = RunnableSequence.from([
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createOpenAIToolsAgent = exports.OpenAIToolsAgentOutputParser = void 0;
|
|
4
4
|
const runnables_1 = require("@langchain/core/runnables");
|
|
5
|
-
const
|
|
5
|
+
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
6
6
|
const openai_tools_js_1 = require("../format_scratchpad/openai_tools.cjs");
|
|
7
7
|
const output_parser_js_1 = require("../openai/output_parser.cjs");
|
|
8
8
|
Object.defineProperty(exports, "OpenAIToolsAgentOutputParser", { enumerable: true, get: function () { return output_parser_js_1.OpenAIToolsAgentOutputParser; } });
|
|
@@ -69,7 +69,7 @@ async function createOpenAIToolsAgent({ llm, tools, prompt, }) {
|
|
|
69
69
|
`Found ${JSON.stringify(prompt.inputVariables)} instead.`,
|
|
70
70
|
].join("\n"));
|
|
71
71
|
}
|
|
72
|
-
const modelWithTools = llm.bind({ tools: tools.map(
|
|
72
|
+
const modelWithTools = llm.bind({ tools: tools.map(function_calling_1.convertToOpenAITool) });
|
|
73
73
|
const agent = runnables_1.RunnableSequence.from([
|
|
74
74
|
runnables_1.RunnablePassthrough.assign({
|
|
75
75
|
agent_scratchpad: (input) => (0, openai_tools_js_1.formatToOpenAIToolMessages)(input.steps),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RunnablePassthrough, RunnableSequence, } from "@langchain/core/runnables";
|
|
2
|
-
import {
|
|
2
|
+
import { convertToOpenAITool } from "@langchain/core/utils/function_calling";
|
|
3
3
|
import { formatToOpenAIToolMessages } from "../format_scratchpad/openai_tools.js";
|
|
4
4
|
import { OpenAIToolsAgentOutputParser, } from "../openai/output_parser.js";
|
|
5
5
|
export { OpenAIToolsAgentOutputParser };
|
|
@@ -66,7 +66,7 @@ export async function createOpenAIToolsAgent({ llm, tools, prompt, }) {
|
|
|
66
66
|
`Found ${JSON.stringify(prompt.inputVariables)} instead.`,
|
|
67
67
|
].join("\n"));
|
|
68
68
|
}
|
|
69
|
-
const modelWithTools = llm.bind({ tools: tools.map(
|
|
69
|
+
const modelWithTools = llm.bind({ tools: tools.map(convertToOpenAITool) });
|
|
70
70
|
const agent = RunnableSequence.from([
|
|
71
71
|
RunnablePassthrough.assign({
|
|
72
72
|
agent_scratchpad: (input) => formatToOpenAIToolMessages(input.steps),
|
|
@@ -24,7 +24,7 @@ const types_js_1 = require("../types.cjs");
|
|
|
24
24
|
* new ChatOpenAI({
|
|
25
25
|
* modelName: "gpt-3.5-turbo-1106",
|
|
26
26
|
* temperature: 0,
|
|
27
|
-
* }).bind({ tools: tools.map(
|
|
27
|
+
* }).bind({ tools: tools.map(convertToOpenAITool) }),
|
|
28
28
|
* new OpenAIToolsAgentOutputParser(),
|
|
29
29
|
* ]).withConfig({ runName: "OpenAIToolsAgent" });
|
|
30
30
|
*
|
|
@@ -32,7 +32,7 @@ export type ToolsAgentStep = AgentStep & {
|
|
|
32
32
|
* new ChatOpenAI({
|
|
33
33
|
* modelName: "gpt-3.5-turbo-1106",
|
|
34
34
|
* temperature: 0,
|
|
35
|
-
* }).bind({ tools: tools.map(
|
|
35
|
+
* }).bind({ tools: tools.map(convertToOpenAITool) }),
|
|
36
36
|
* new OpenAIToolsAgentOutputParser(),
|
|
37
37
|
* ]).withConfig({ runName: "OpenAIToolsAgent" });
|
|
38
38
|
*
|
|
@@ -21,7 +21,7 @@ import { AgentMultiActionOutputParser } from "../types.js";
|
|
|
21
21
|
* new ChatOpenAI({
|
|
22
22
|
* modelName: "gpt-3.5-turbo-1106",
|
|
23
23
|
* temperature: 0,
|
|
24
|
-
* }).bind({ tools: tools.map(
|
|
24
|
+
* }).bind({ tools: tools.map(convertToOpenAITool) }),
|
|
25
25
|
* new OpenAIToolsAgentOutputParser(),
|
|
26
26
|
* ]).withConfig({ runName: "OpenAIToolsAgent" });
|
|
27
27
|
*
|
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
const entrypoint_deprecation_js_1 = require("../util/entrypoint_deprecation.cjs");
|
|
18
18
|
/* #__PURE__ */ (0, entrypoint_deprecation_js_1.logVersion010MigrationWarning)({
|
|
19
19
|
oldEntrypointName: "cache/cloudflare_kv",
|
|
20
|
-
newEntrypointName: "
|
|
20
|
+
newEntrypointName: "",
|
|
21
|
+
newPackageName: "@langchain/cloudflare",
|
|
21
22
|
});
|
|
22
23
|
__exportStar(require("@langchain/community/caches/cloudflare_kv"), exports);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { logVersion010MigrationWarning } from "../util/entrypoint_deprecation.js";
|
|
2
2
|
/* #__PURE__ */ logVersion010MigrationWarning({
|
|
3
3
|
oldEntrypointName: "cache/cloudflare_kv",
|
|
4
|
-
newEntrypointName: "
|
|
4
|
+
newEntrypointName: "",
|
|
5
|
+
newPackageName: "@langchain/cloudflare",
|
|
5
6
|
});
|
|
6
7
|
export * from "@langchain/community/caches/cloudflare_kv";
|
|
@@ -24,7 +24,7 @@ const output_parsers_1 = require("@langchain/core/output_parsers");
|
|
|
24
24
|
* const rephrasePrompt = await pull("langchain-ai/chat-langchain-rephrase");
|
|
25
25
|
* const llm = new ChatOpenAI({});
|
|
26
26
|
* const retriever = ...
|
|
27
|
-
* const
|
|
27
|
+
* const chain = await createHistoryAwareRetriever({
|
|
28
28
|
* llm,
|
|
29
29
|
* retriever,
|
|
30
30
|
* rephrasePrompt,
|
|
@@ -41,7 +41,7 @@ export type CreateHistoryAwareRetrieverParams = {
|
|
|
41
41
|
* const rephrasePrompt = await pull("langchain-ai/chat-langchain-rephrase");
|
|
42
42
|
* const llm = new ChatOpenAI({});
|
|
43
43
|
* const retriever = ...
|
|
44
|
-
* const
|
|
44
|
+
* const chain = await createHistoryAwareRetriever({
|
|
45
45
|
* llm,
|
|
46
46
|
* retriever,
|
|
47
47
|
* rephrasePrompt,
|
|
@@ -21,7 +21,7 @@ import { StringOutputParser } from "@langchain/core/output_parsers";
|
|
|
21
21
|
* const rephrasePrompt = await pull("langchain-ai/chat-langchain-rephrase");
|
|
22
22
|
* const llm = new ChatOpenAI({});
|
|
23
23
|
* const retriever = ...
|
|
24
|
-
* const
|
|
24
|
+
* const chain = await createHistoryAwareRetriever({
|
|
25
25
|
* llm,
|
|
26
26
|
* retriever,
|
|
27
27
|
* rephrasePrompt,
|
|
@@ -2,4 +2,4 @@ export { createExtractionChain, createExtractionChainFromZod, } from "./extracti
|
|
|
2
2
|
export { type TaggingChainOptions, createTaggingChain, createTaggingChainFromZod, } from "./tagging.js";
|
|
3
3
|
export { type OpenAPIChainOptions, createOpenAPIChain } from "./openapi.js";
|
|
4
4
|
export { type StructuredOutputChainInput, createStructuredOutputChain, createStructuredOutputChainFromZod, } from "./structured_output.js";
|
|
5
|
-
export { createStructuredOutputRunnable, createOpenAIFnRunnable, } from "./base.js";
|
|
5
|
+
export { type CreateStructuredOutputRunnableConfig, createStructuredOutputRunnable, type CreateOpenAIFnRunnableConfig, createOpenAIFnRunnable, } from "./base.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SQL_SAP_HANA_PROMPT = exports.SQL_MSSQL_PROMPT = exports.SQL_MYSQL_PROMPT = exports.SQL_SQLITE_PROMPT = exports.SQL_POSTGRES_PROMPT = exports.DEFAULT_SQL_DATABASE_PROMPT = void 0;
|
|
3
|
+
exports.SQL_ORACLE_PROMPT = exports.SQL_SAP_HANA_PROMPT = exports.SQL_MSSQL_PROMPT = exports.SQL_MYSQL_PROMPT = exports.SQL_SQLITE_PROMPT = exports.SQL_POSTGRES_PROMPT = exports.DEFAULT_SQL_DATABASE_PROMPT = void 0;
|
|
4
4
|
/* eslint-disable spaced-comment */
|
|
5
5
|
const prompts_1 = require("@langchain/core/prompts");
|
|
6
6
|
exports.DEFAULT_SQL_DATABASE_PROMPT = new prompts_1.PromptTemplate({
|
|
@@ -120,3 +120,22 @@ Only use the following tables:
|
|
|
120
120
|
Question: {input}`,
|
|
121
121
|
inputVariables: ["dialect", "table_info", "input", "top_k"],
|
|
122
122
|
});
|
|
123
|
+
exports.SQL_ORACLE_PROMPT = new prompts_1.PromptTemplate({
|
|
124
|
+
template: `You are a ORACLE expert. Given an input question, first create a syntactically correct ORACLE query to run, then look at the results of the query and return the answer to the input question.
|
|
125
|
+
Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the ROWNUM clause as per ORACLE. You can order the results to return the most informative data in the database.
|
|
126
|
+
Never query for all columns from a table. You must query only the columns that are needed to answer the question.
|
|
127
|
+
Pay attention to use only the column names you can see in the tables below. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table.
|
|
128
|
+
|
|
129
|
+
Use the following format:
|
|
130
|
+
|
|
131
|
+
Question: "Question here"
|
|
132
|
+
SQLQuery: "SQL Query to run"
|
|
133
|
+
SQLResult: "Result of the SQLQuery"
|
|
134
|
+
Answer: "Final answer here"
|
|
135
|
+
|
|
136
|
+
Only use the following tables:
|
|
137
|
+
{table_info}
|
|
138
|
+
|
|
139
|
+
Question: {input}`,
|
|
140
|
+
inputVariables: ["dialect", "table_info", "input", "top_k"],
|
|
141
|
+
});
|
|
@@ -117,3 +117,22 @@ Only use the following tables:
|
|
|
117
117
|
Question: {input}`,
|
|
118
118
|
inputVariables: ["dialect", "table_info", "input", "top_k"],
|
|
119
119
|
});
|
|
120
|
+
export const SQL_ORACLE_PROMPT = /*#__PURE__*/ new PromptTemplate({
|
|
121
|
+
template: `You are a ORACLE expert. Given an input question, first create a syntactically correct ORACLE query to run, then look at the results of the query and return the answer to the input question.
|
|
122
|
+
Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the ROWNUM clause as per ORACLE. You can order the results to return the most informative data in the database.
|
|
123
|
+
Never query for all columns from a table. You must query only the columns that are needed to answer the question.
|
|
124
|
+
Pay attention to use only the column names you can see in the tables below. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table.
|
|
125
|
+
|
|
126
|
+
Use the following format:
|
|
127
|
+
|
|
128
|
+
Question: "Question here"
|
|
129
|
+
SQLQuery: "SQL Query to run"
|
|
130
|
+
SQLResult: "Result of the SQLQuery"
|
|
131
|
+
Answer: "Final answer here"
|
|
132
|
+
|
|
133
|
+
Only use the following tables:
|
|
134
|
+
{table_info}
|
|
135
|
+
|
|
136
|
+
Question: {input}`,
|
|
137
|
+
inputVariables: ["dialect", "table_info", "input", "top_k"],
|
|
138
|
+
});
|
|
@@ -17,5 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
const entrypoint_deprecation_js_1 = require("../util/entrypoint_deprecation.cjs");
|
|
18
18
|
/* #__PURE__ */ (0, entrypoint_deprecation_js_1.logVersion010MigrationWarning)({
|
|
19
19
|
oldEntrypointName: "chat_models/cloudflare_workersai",
|
|
20
|
+
newEntrypointName: "",
|
|
21
|
+
newPackageName: "@langchain/cloudflare",
|
|
20
22
|
});
|
|
21
23
|
__exportStar(require("@langchain/community/chat_models/cloudflare_workersai"), exports);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { logVersion010MigrationWarning } from "../util/entrypoint_deprecation.js";
|
|
2
2
|
/* #__PURE__ */ logVersion010MigrationWarning({
|
|
3
3
|
oldEntrypointName: "chat_models/cloudflare_workersai",
|
|
4
|
+
newEntrypointName: "",
|
|
5
|
+
newPackageName: "@langchain/cloudflare",
|
|
4
6
|
});
|
|
5
7
|
export * from "@langchain/community/chat_models/cloudflare_workersai";
|
|
@@ -17,5 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
const entrypoint_deprecation_js_1 = require("../util/entrypoint_deprecation.cjs");
|
|
18
18
|
/* #__PURE__ */ (0, entrypoint_deprecation_js_1.logVersion010MigrationWarning)({
|
|
19
19
|
oldEntrypointName: "embeddings/cloudflare_workersai",
|
|
20
|
+
newEntrypointName: "",
|
|
21
|
+
newPackageName: "@langchain/cloudflare",
|
|
20
22
|
});
|
|
21
23
|
__exportStar(require("@langchain/community/embeddings/cloudflare_workersai"), exports);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { logVersion010MigrationWarning } from "../util/entrypoint_deprecation.js";
|
|
2
2
|
/* #__PURE__ */ logVersion010MigrationWarning({
|
|
3
3
|
oldEntrypointName: "embeddings/cloudflare_workersai",
|
|
4
|
+
newEntrypointName: "",
|
|
5
|
+
newPackageName: "@langchain/cloudflare",
|
|
4
6
|
});
|
|
5
7
|
export * from "@langchain/community/embeddings/cloudflare_workersai";
|
|
@@ -6,7 +6,7 @@ import { ChatGeneration, Generation } from "@langchain/core/outputs";
|
|
|
6
6
|
import { BasePromptTemplate } from "@langchain/core/prompts";
|
|
7
7
|
import { Callbacks, BaseCallbackConfig } from "@langchain/core/callbacks/manager";
|
|
8
8
|
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
9
|
-
import { AgentTrajectoryEvaluator, EvalOutputType, LLMEvalChainInput, LLMTrajectoryEvaluatorArgs } from "../base.js";
|
|
9
|
+
import { AgentTrajectoryEvaluator, EvalOutputType, LLMEvalChainInput, LLMTrajectoryEvaluatorArgs, type ExtractLLMCallOptions } from "../base.js";
|
|
10
10
|
/**
|
|
11
11
|
* A parser for the output of the TrajectoryEvalChain.
|
|
12
12
|
*/
|
|
@@ -51,5 +51,5 @@ export declare class TrajectoryEvalChain extends AgentTrajectoryEvaluator {
|
|
|
51
51
|
*/
|
|
52
52
|
getAgentTrajectory(steps: AgentStep[]): string;
|
|
53
53
|
formatReference(reference?: string): string;
|
|
54
|
-
_evaluateAgentTrajectory(args: LLMTrajectoryEvaluatorArgs, callOptions: this["llm"]
|
|
54
|
+
_evaluateAgentTrajectory(args: LLMTrajectoryEvaluatorArgs, callOptions: ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
55
55
|
}
|
|
@@ -8,6 +8,7 @@ import { BaseChain, LLMChain, LLMChainInput } from "../chains/index.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export interface LLMEvalChainInput<T extends EvalOutputType = EvalOutputType, L extends BaseLanguageModelInterface = BaseLanguageModelInterface> extends LLMChainInput<T, L> {
|
|
10
10
|
}
|
|
11
|
+
export type ExtractLLMCallOptions<LanguageModelInterface> = LanguageModelInterface extends BaseLanguageModelInterface<any, infer CallOptions> ? CallOptions : never;
|
|
11
12
|
/**
|
|
12
13
|
* Compare two sets for equality
|
|
13
14
|
*
|
|
@@ -113,7 +114,7 @@ export declare abstract class LLMStringEvaluator<T extends EvalOutputType = Eval
|
|
|
113
114
|
* @param callOptions
|
|
114
115
|
* @param config
|
|
115
116
|
*/
|
|
116
|
-
abstract _evaluateStrings(args: StringEvaluatorArgs, callOptions?: this["llm"]
|
|
117
|
+
abstract _evaluateStrings(args: StringEvaluatorArgs, callOptions?: ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
117
118
|
/**
|
|
118
119
|
* Evaluate Chain or LLM output, based on optional input and label.
|
|
119
120
|
* @returns The evaluation results containing the score or value. It is recommended that the dictionary contain the following keys:
|
|
@@ -124,7 +125,7 @@ export declare abstract class LLMStringEvaluator<T extends EvalOutputType = Eval
|
|
|
124
125
|
* @param callOptions
|
|
125
126
|
* @param config
|
|
126
127
|
*/
|
|
127
|
-
evaluateStrings(args: StringEvaluatorArgs, callOptions?: this["llm"]
|
|
128
|
+
evaluateStrings(args: StringEvaluatorArgs, callOptions?: ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
128
129
|
}
|
|
129
130
|
/**
|
|
130
131
|
* Grade, tag, or otherwise evaluate predictions relative to their inputs
|
|
@@ -194,7 +195,7 @@ export declare abstract class LLMPairwiseStringEvaluator extends LLMEvalChain {
|
|
|
194
195
|
* @param config
|
|
195
196
|
* @return A dictionary containing the preference, scores, and/or other information.
|
|
196
197
|
*/
|
|
197
|
-
abstract _evaluateStringPairs(args: LLMPairwiseStringEvaluatorArgs, callOptions?: this["llm"]
|
|
198
|
+
abstract _evaluateStringPairs(args: LLMPairwiseStringEvaluatorArgs, callOptions?: ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
198
199
|
/**
|
|
199
200
|
* Evaluate the output string pairs.
|
|
200
201
|
* @param args
|
|
@@ -202,7 +203,7 @@ export declare abstract class LLMPairwiseStringEvaluator extends LLMEvalChain {
|
|
|
202
203
|
* @param config
|
|
203
204
|
* @return A dictionary containing the preference, scores, and/or other information.
|
|
204
205
|
*/
|
|
205
|
-
evaluateStringPairs(args: LLMPairwiseStringEvaluatorArgs, callOptions?: this["llm"]
|
|
206
|
+
evaluateStringPairs(args: LLMPairwiseStringEvaluatorArgs, callOptions?: ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
206
207
|
}
|
|
207
208
|
/**
|
|
208
209
|
* Interface for evaluating agent trajectories.
|
|
@@ -220,7 +221,7 @@ export declare abstract class AgentTrajectoryEvaluator extends LLMEvalChain {
|
|
|
220
221
|
* @param callOptions
|
|
221
222
|
* @param config
|
|
222
223
|
*/
|
|
223
|
-
abstract _evaluateAgentTrajectory(args: LLMTrajectoryEvaluatorArgs, callOptions?: this["llm"]
|
|
224
|
+
abstract _evaluateAgentTrajectory(args: LLMTrajectoryEvaluatorArgs, callOptions?: ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
224
225
|
/**
|
|
225
226
|
* Evaluate a trajectory.
|
|
226
227
|
* @return The evaluation result.
|
|
@@ -228,5 +229,5 @@ export declare abstract class AgentTrajectoryEvaluator extends LLMEvalChain {
|
|
|
228
229
|
* @param callOptions
|
|
229
230
|
* @param config
|
|
230
231
|
*/
|
|
231
|
-
evaluateAgentTrajectory(args: LLMTrajectoryEvaluatorArgs, callOptions?: this["llm"]
|
|
232
|
+
evaluateAgentTrajectory(args: LLMTrajectoryEvaluatorArgs, callOptions?: ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
232
233
|
}
|
|
@@ -4,7 +4,7 @@ import { ChainValues } from "@langchain/core/utils/types";
|
|
|
4
4
|
import { ChatGeneration, Generation } from "@langchain/core/outputs";
|
|
5
5
|
import { BasePromptTemplate } from "@langchain/core/prompts";
|
|
6
6
|
import { Callbacks, BaseCallbackConfig } from "@langchain/core/callbacks/manager";
|
|
7
|
-
import { EvalOutputType, LLMEvalChainInput, LLMPairwiseStringEvaluator, LLMPairwiseStringEvaluatorArgs } from "../base.js";
|
|
7
|
+
import { EvalOutputType, LLMEvalChainInput, LLMPairwiseStringEvaluator, LLMPairwiseStringEvaluatorArgs, type ExtractLLMCallOptions } from "../base.js";
|
|
8
8
|
import { CriteriaLike } from "../criteria/criteria.js";
|
|
9
9
|
/**
|
|
10
10
|
* A parser for the output of the PairwiseStringEvalChain.
|
|
@@ -36,7 +36,7 @@ export declare class PairwiseStringEvalChain extends LLMPairwiseStringEvaluator
|
|
|
36
36
|
*/
|
|
37
37
|
static fromLLM(llm: BaseLanguageModelInterface, criteria?: CriteriaLike, chainOptions?: Partial<Omit<LLMEvalChainInput, "llm">>): Promise<PairwiseStringEvalChain>;
|
|
38
38
|
_prepareOutput(result: ChainValues): any;
|
|
39
|
-
_evaluateStringPairs(args: LLMPairwiseStringEvaluatorArgs, callOptions: this["llm"]
|
|
39
|
+
_evaluateStringPairs(args: LLMPairwiseStringEvaluatorArgs, callOptions: ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* A chain for comparing two outputs, such as the outputs
|
|
@@ -4,7 +4,7 @@ import { ChainValues } from "@langchain/core/utils/types";
|
|
|
4
4
|
import { ChatGeneration, Generation } from "@langchain/core/outputs";
|
|
5
5
|
import { BasePromptTemplate } from "@langchain/core/prompts";
|
|
6
6
|
import { Callbacks, BaseCallbackConfig } from "@langchain/core/callbacks/manager";
|
|
7
|
-
import { EvalOutputType, LLMEvalChainInput, LLMStringEvaluator, StringEvaluatorArgs } from "../base.js";
|
|
7
|
+
import { EvalOutputType, LLMEvalChainInput, LLMStringEvaluator, StringEvaluatorArgs, type ExtractLLMCallOptions } from "../base.js";
|
|
8
8
|
import { ConstitutionalPrinciple } from "../../chains/constitutional_ai/constitutional_principle.js";
|
|
9
9
|
/**
|
|
10
10
|
* A Criteria to evaluate.
|
|
@@ -61,7 +61,7 @@ export declare class CriteriaEvalChain extends LLMStringEvaluator {
|
|
|
61
61
|
* @param result
|
|
62
62
|
*/
|
|
63
63
|
_prepareOutput(result: ChainValues): any;
|
|
64
|
-
_evaluateStrings(args: StringEvaluatorArgs, callOptions: this["llm"]
|
|
64
|
+
_evaluateStrings(args: StringEvaluatorArgs, callOptions: ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* Criteria evaluation chain that requires references.
|
|
@@ -5,7 +5,7 @@ const fast_xml_parser_1 = require("fast-xml-parser");
|
|
|
5
5
|
const messages_1 = require("@langchain/core/messages");
|
|
6
6
|
const chat_models_1 = require("@langchain/core/language_models/chat_models");
|
|
7
7
|
const prompts_1 = require("@langchain/core/prompts");
|
|
8
|
-
const
|
|
8
|
+
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
9
9
|
const anthropic_js_1 = require("../../chat_models/anthropic.cjs");
|
|
10
10
|
const TOOL_SYSTEM_PROMPT =
|
|
11
11
|
/* #__PURE__ */
|
|
@@ -71,7 +71,7 @@ class AnthropicFunctions extends chat_models_1.BaseChatModel {
|
|
|
71
71
|
let functionCall;
|
|
72
72
|
if (options.tools) {
|
|
73
73
|
// eslint-disable-next-line no-param-reassign
|
|
74
|
-
options.functions = (options.functions ?? []).concat(options.tools.map(
|
|
74
|
+
options.functions = (options.functions ?? []).concat(options.tools.map(function_calling_1.convertToOpenAIFunction));
|
|
75
75
|
}
|
|
76
76
|
if (options.functions !== undefined && options.functions.length > 0) {
|
|
77
77
|
const content = await TOOL_SYSTEM_PROMPT.format({
|
|
@@ -2,7 +2,7 @@ import { XMLParser } from "fast-xml-parser";
|
|
|
2
2
|
import { AIMessage, SystemMessage, } from "@langchain/core/messages";
|
|
3
3
|
import { BaseChatModel, } from "@langchain/core/language_models/chat_models";
|
|
4
4
|
import { PromptTemplate } from "@langchain/core/prompts";
|
|
5
|
-
import {
|
|
5
|
+
import { convertToOpenAIFunction } from "@langchain/core/utils/function_calling";
|
|
6
6
|
import { ChatAnthropic, DEFAULT_STOP_SEQUENCES, } from "../../chat_models/anthropic.js";
|
|
7
7
|
const TOOL_SYSTEM_PROMPT =
|
|
8
8
|
/* #__PURE__ */
|
|
@@ -68,7 +68,7 @@ export class AnthropicFunctions extends BaseChatModel {
|
|
|
68
68
|
let functionCall;
|
|
69
69
|
if (options.tools) {
|
|
70
70
|
// eslint-disable-next-line no-param-reassign
|
|
71
|
-
options.functions = (options.functions ?? []).concat(options.tools.map(
|
|
71
|
+
options.functions = (options.functions ?? []).concat(options.tools.map(convertToOpenAIFunction));
|
|
72
72
|
}
|
|
73
73
|
if (options.functions !== undefined && options.functions.length > 0) {
|
|
74
74
|
const content = await TOOL_SYSTEM_PROMPT.format({
|
|
@@ -49,6 +49,7 @@ export declare class OllamaFunctions extends BaseChatModel<ChatOllamaFunctionsCa
|
|
|
49
49
|
num_gpu: number | undefined;
|
|
50
50
|
num_gqa: number | undefined;
|
|
51
51
|
num_keep: number | undefined;
|
|
52
|
+
num_predict: number | undefined;
|
|
52
53
|
num_thread: number | undefined;
|
|
53
54
|
penalize_newline: boolean | undefined;
|
|
54
55
|
presence_penalty: number | undefined;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomFormatPromptTemplate = void 0;
|
|
4
|
+
const prompts_1 = require("@langchain/core/prompts");
|
|
5
|
+
class CustomFormatPromptTemplate extends prompts_1.PromptTemplate {
|
|
6
|
+
static lc_name() {
|
|
7
|
+
return "CustomPromptTemplate";
|
|
8
|
+
}
|
|
9
|
+
constructor(input) {
|
|
10
|
+
super(input);
|
|
11
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: false
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "templateValidator", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: void 0
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "renderer", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
Object.assign(this, input);
|
|
30
|
+
if (this.validateTemplate && this.templateValidator !== undefined) {
|
|
31
|
+
let totalInputVariables = this.inputVariables;
|
|
32
|
+
if (this.partialVariables) {
|
|
33
|
+
totalInputVariables = totalInputVariables.concat(Object.keys(this.partialVariables));
|
|
34
|
+
}
|
|
35
|
+
this.templateValidator(this.template, totalInputVariables);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Load prompt template from a template
|
|
40
|
+
*/
|
|
41
|
+
static fromTemplate(template, { customParser, ...rest }) {
|
|
42
|
+
const names = new Set();
|
|
43
|
+
const nodes = customParser(template);
|
|
44
|
+
for (const node of nodes) {
|
|
45
|
+
if (node.type === "variable") {
|
|
46
|
+
names.add(node.name);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
50
|
+
return new this({
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
|
+
inputVariables: [...names],
|
|
53
|
+
template,
|
|
54
|
+
customParser,
|
|
55
|
+
...rest,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Formats the prompt template with the provided values.
|
|
60
|
+
* @param values The values to be used to format the prompt template.
|
|
61
|
+
* @returns A promise that resolves to a string which is the formatted prompt.
|
|
62
|
+
*/
|
|
63
|
+
async format(values) {
|
|
64
|
+
const allValues = await this.mergePartialAndUserVariables(values);
|
|
65
|
+
return this.renderer(this.template, allValues);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.CustomFormatPromptTemplate = CustomFormatPromptTemplate;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { InputValues } from "@langchain/core/utils/types";
|
|
2
|
+
import { type ParsedFStringNode, PromptTemplate, type PromptTemplateInput, TypedPromptInputValues } from "@langchain/core/prompts";
|
|
3
|
+
export type CustomFormatPromptTemplateInput<RunInput extends InputValues> = Omit<PromptTemplateInput<RunInput, string>, "templateFormat"> & {
|
|
4
|
+
customParser: (template: string) => ParsedFStringNode[];
|
|
5
|
+
templateValidator?: (template: string, inputVariables: string[]) => boolean;
|
|
6
|
+
renderer: (template: string, values: InputValues) => string;
|
|
7
|
+
};
|
|
8
|
+
export declare class CustomFormatPromptTemplate<RunInput extends InputValues = any, PartialVariableName extends string = any> extends PromptTemplate<RunInput, PartialVariableName> {
|
|
9
|
+
static lc_name(): string;
|
|
10
|
+
lc_serializable: boolean;
|
|
11
|
+
templateValidator?: (template: string, inputVariables: string[]) => boolean;
|
|
12
|
+
renderer: (template: string, values: InputValues) => string;
|
|
13
|
+
constructor(input: CustomFormatPromptTemplateInput<RunInput>);
|
|
14
|
+
/**
|
|
15
|
+
* Load prompt template from a template
|
|
16
|
+
*/
|
|
17
|
+
static fromTemplate<RunInput extends InputValues = Record<string, any>>(template: string, { customParser, ...rest }: Omit<CustomFormatPromptTemplateInput<RunInput>, "template" | "inputVariables">): CustomFormatPromptTemplate<RunInput extends Symbol ? never : RunInput, any>;
|
|
18
|
+
/**
|
|
19
|
+
* Formats the prompt template with the provided values.
|
|
20
|
+
* @param values The values to be used to format the prompt template.
|
|
21
|
+
* @returns A promise that resolves to a string which is the formatted prompt.
|
|
22
|
+
*/
|
|
23
|
+
format(values: TypedPromptInputValues<RunInput>): Promise<string>;
|
|
24
|
+
}
|