langchain 0.0.81 → 0.0.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chat_models/googlevertexai.cjs +1 -0
- package/chat_models/googlevertexai.d.ts +1 -0
- package/chat_models/googlevertexai.js +1 -0
- package/dist/base_language/index.cjs +7 -1
- package/dist/base_language/index.d.ts +1 -0
- package/dist/base_language/index.js +5 -0
- package/dist/chains/api/api_chain.cjs +108 -0
- package/dist/chains/api/api_chain.d.ts +38 -0
- package/dist/chains/api/api_chain.js +104 -0
- package/dist/chains/api/prompts.cjs +29 -0
- package/dist/chains/api/prompts.d.ts +5 -0
- package/dist/chains/api/prompts.js +26 -0
- package/dist/chains/base.cjs +4 -0
- package/dist/chains/base.js +4 -0
- package/dist/chains/index.cjs +3 -1
- package/dist/chains/index.d.ts +2 -1
- package/dist/chains/index.js +1 -0
- package/dist/chains/serde.d.ts +7 -1
- package/dist/chat_models/anthropic.cjs +12 -2
- package/dist/chat_models/anthropic.d.ts +2 -0
- package/dist/chat_models/anthropic.js +12 -2
- package/dist/chat_models/googlevertexai.cjs +184 -0
- package/dist/chat_models/googlevertexai.d.ts +74 -0
- package/dist/chat_models/googlevertexai.js +179 -0
- package/dist/document_loaders/web/gitbook.cjs +6 -6
- package/dist/document_loaders/web/gitbook.js +6 -6
- package/dist/embeddings/googlevertexai.cjs +54 -0
- package/dist/embeddings/googlevertexai.d.ts +25 -0
- package/dist/embeddings/googlevertexai.js +50 -0
- package/dist/llms/cohere.cjs +5 -4
- package/dist/llms/cohere.js +5 -4
- package/dist/stores/message/upstash_redis.cjs +66 -0
- package/dist/stores/message/upstash_redis.d.ts +17 -0
- package/dist/stores/message/upstash_redis.js +62 -0
- package/dist/tools/google_custom_search.cjs +64 -0
- package/dist/tools/google_custom_search.d.ts +13 -0
- package/dist/tools/google_custom_search.js +60 -0
- package/dist/tools/index.cjs +3 -1
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.js +1 -0
- package/dist/util/googlevertexai-connection.d.ts +1 -1
- package/dist/vectorstores/faiss.cjs +2 -1
- package/dist/vectorstores/faiss.js +2 -1
- package/dist/vectorstores/qdrant.cjs +119 -0
- package/dist/vectorstores/qdrant.d.ts +24 -0
- package/dist/vectorstores/qdrant.js +115 -0
- package/embeddings/googlevertexai.cjs +1 -0
- package/embeddings/googlevertexai.d.ts +1 -0
- package/embeddings/googlevertexai.js +1 -0
- package/package.json +43 -1
- package/stores/message/upstash_redis.cjs +1 -0
- package/stores/message/upstash_redis.d.ts +1 -0
- package/stores/message/upstash_redis.js +1 -0
- package/vectorstores/qdrant.cjs +1 -0
- package/vectorstores/qdrant.d.ts +1 -0
- package/vectorstores/qdrant.js +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/chat_models/googlevertexai.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/chat_models/googlevertexai.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/chat_models/googlevertexai.js'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseLanguageModel = exports.BaseLangChain = void 0;
|
|
3
|
+
exports.calculateMaxTokens = exports.BaseLanguageModel = exports.BaseLangChain = void 0;
|
|
4
4
|
const async_caller_js_1 = require("../util/async_caller.cjs");
|
|
5
5
|
const count_tokens_js_1 = require("./count_tokens.cjs");
|
|
6
6
|
const tiktoken_js_1 = require("../util/tiktoken.cjs");
|
|
@@ -116,3 +116,9 @@ class BaseLanguageModel extends BaseLangChain {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
exports.BaseLanguageModel = BaseLanguageModel;
|
|
119
|
+
/*
|
|
120
|
+
* Calculate max tokens for given model and prompt.
|
|
121
|
+
* That is the model size - number of tokens in prompt.
|
|
122
|
+
*/
|
|
123
|
+
var count_tokens_js_2 = require("./count_tokens.cjs");
|
|
124
|
+
Object.defineProperty(exports, "calculateMaxTokens", { enumerable: true, get: function () { return count_tokens_js_2.calculateMaxTokens; } });
|
|
@@ -111,3 +111,8 @@ export class BaseLanguageModel extends BaseLangChain {
|
|
|
111
111
|
return new Cls(rest);
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
+
/*
|
|
115
|
+
* Calculate max tokens for given model and prompt.
|
|
116
|
+
* That is the model size - number of tokens in prompt.
|
|
117
|
+
*/
|
|
118
|
+
export { calculateMaxTokens } from "./count_tokens.js";
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.APIChain = void 0;
|
|
4
|
+
const base_js_1 = require("../base.cjs");
|
|
5
|
+
const llm_chain_js_1 = require("../llm_chain.cjs");
|
|
6
|
+
const prompts_js_1 = require("./prompts.cjs");
|
|
7
|
+
class APIChain extends base_js_1.BaseChain {
|
|
8
|
+
get inputKeys() {
|
|
9
|
+
return [this.inputKey];
|
|
10
|
+
}
|
|
11
|
+
get outputKeys() {
|
|
12
|
+
return [this.outputKey];
|
|
13
|
+
}
|
|
14
|
+
constructor(fields) {
|
|
15
|
+
super(fields);
|
|
16
|
+
Object.defineProperty(this, "apiAnswerChain", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: void 0
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(this, "apiRequestChain", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: void 0
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(this, "apiDocs", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: void 0
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(this, "headers", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: {}
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(this, "inputKey", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: "question"
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(this, "outputKey", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: "output"
|
|
51
|
+
});
|
|
52
|
+
this.apiRequestChain = fields.apiRequestChain;
|
|
53
|
+
this.apiAnswerChain = fields.apiAnswerChain;
|
|
54
|
+
this.apiDocs = fields.apiDocs;
|
|
55
|
+
this.inputKey = fields.inputKey ?? this.inputKey;
|
|
56
|
+
this.outputKey = fields.outputKey ?? this.outputKey;
|
|
57
|
+
this.headers = fields.headers ?? this.headers;
|
|
58
|
+
}
|
|
59
|
+
/** @ignore */
|
|
60
|
+
async _call(values, runManager) {
|
|
61
|
+
const question = values[this.inputKey];
|
|
62
|
+
const api_url = await this.apiRequestChain.predict({ question, api_docs: this.apiDocs }, runManager?.getChild());
|
|
63
|
+
const res = await fetch(api_url, { headers: this.headers });
|
|
64
|
+
const api_response = await res.text();
|
|
65
|
+
const answer = await this.apiAnswerChain.predict({ question, api_docs: this.apiDocs, api_url, api_response }, runManager?.getChild());
|
|
66
|
+
return { [this.outputKey]: answer };
|
|
67
|
+
}
|
|
68
|
+
_chainType() {
|
|
69
|
+
return "api_chain";
|
|
70
|
+
}
|
|
71
|
+
static async deserialize(data) {
|
|
72
|
+
const { api_request_chain, api_answer_chain, api_docs } = data;
|
|
73
|
+
if (!api_request_chain) {
|
|
74
|
+
throw new Error("LLMChain must have api_request_chain");
|
|
75
|
+
}
|
|
76
|
+
if (!api_answer_chain) {
|
|
77
|
+
throw new Error("LLMChain must have api_answer_chain");
|
|
78
|
+
}
|
|
79
|
+
if (!api_docs) {
|
|
80
|
+
throw new Error("LLMChain must have api_docs");
|
|
81
|
+
}
|
|
82
|
+
return new APIChain({
|
|
83
|
+
apiAnswerChain: await llm_chain_js_1.LLMChain.deserialize(api_answer_chain),
|
|
84
|
+
apiRequestChain: await llm_chain_js_1.LLMChain.deserialize(api_request_chain),
|
|
85
|
+
apiDocs: api_docs,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
serialize() {
|
|
89
|
+
return {
|
|
90
|
+
_type: this._chainType(),
|
|
91
|
+
api_answer_chain: this.apiAnswerChain.serialize(),
|
|
92
|
+
api_request_chain: this.apiRequestChain.serialize(),
|
|
93
|
+
api_docs: this.apiDocs,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
static fromLLMAndAPIDocs(llm, apiDocs, options = {}) {
|
|
97
|
+
const { apiUrlPrompt = prompts_js_1.API_URL_PROMPT_TEMPLATE, apiResponsePrompt = prompts_js_1.API_RESPONSE_PROMPT_TEMPLATE, } = options;
|
|
98
|
+
const apiRequestChain = new llm_chain_js_1.LLMChain({ prompt: apiUrlPrompt, llm });
|
|
99
|
+
const apiAnswerChain = new llm_chain_js_1.LLMChain({ prompt: apiResponsePrompt, llm });
|
|
100
|
+
return new this({
|
|
101
|
+
apiAnswerChain,
|
|
102
|
+
apiRequestChain,
|
|
103
|
+
apiDocs,
|
|
104
|
+
...options,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.APIChain = APIChain;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BaseChain, ChainInputs } from "../base.js";
|
|
2
|
+
import { SerializedAPIChain } from "../serde.js";
|
|
3
|
+
import { LLMChain } from "../llm_chain.js";
|
|
4
|
+
import { BaseLanguageModel } from "../../base_language/index.js";
|
|
5
|
+
import { CallbackManagerForChainRun } from "../../callbacks/manager.js";
|
|
6
|
+
import { ChainValues } from "../../schema/index.js";
|
|
7
|
+
import { BasePromptTemplate } from "../../index.js";
|
|
8
|
+
export interface APIChainInput extends Omit<ChainInputs, "memory"> {
|
|
9
|
+
apiAnswerChain: LLMChain;
|
|
10
|
+
apiRequestChain: LLMChain;
|
|
11
|
+
apiDocs: string;
|
|
12
|
+
inputKey?: string;
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
/** Key to use for output, defaults to `output` */
|
|
15
|
+
outputKey?: string;
|
|
16
|
+
}
|
|
17
|
+
export type APIChainOptions = {
|
|
18
|
+
headers?: Record<string, string>;
|
|
19
|
+
apiUrlPrompt?: BasePromptTemplate;
|
|
20
|
+
apiResponsePrompt?: BasePromptTemplate;
|
|
21
|
+
};
|
|
22
|
+
export declare class APIChain extends BaseChain implements APIChainInput {
|
|
23
|
+
apiAnswerChain: LLMChain;
|
|
24
|
+
apiRequestChain: LLMChain;
|
|
25
|
+
apiDocs: string;
|
|
26
|
+
headers: {};
|
|
27
|
+
inputKey: string;
|
|
28
|
+
outputKey: string;
|
|
29
|
+
get inputKeys(): string[];
|
|
30
|
+
get outputKeys(): string[];
|
|
31
|
+
constructor(fields: APIChainInput);
|
|
32
|
+
/** @ignore */
|
|
33
|
+
_call(values: ChainValues, runManager?: CallbackManagerForChainRun): Promise<ChainValues>;
|
|
34
|
+
_chainType(): "api_chain";
|
|
35
|
+
static deserialize(data: SerializedAPIChain): Promise<APIChain>;
|
|
36
|
+
serialize(): SerializedAPIChain;
|
|
37
|
+
static fromLLMAndAPIDocs(llm: BaseLanguageModel, apiDocs: string, options?: APIChainOptions & Omit<APIChainInput, "apiAnswerChain" | "apiRequestChain" | "apiDocs">): APIChain;
|
|
38
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { BaseChain } from "../base.js";
|
|
2
|
+
import { LLMChain } from "../llm_chain.js";
|
|
3
|
+
import { API_URL_PROMPT_TEMPLATE, API_RESPONSE_PROMPT_TEMPLATE, } from "./prompts.js";
|
|
4
|
+
export class APIChain extends BaseChain {
|
|
5
|
+
get inputKeys() {
|
|
6
|
+
return [this.inputKey];
|
|
7
|
+
}
|
|
8
|
+
get outputKeys() {
|
|
9
|
+
return [this.outputKey];
|
|
10
|
+
}
|
|
11
|
+
constructor(fields) {
|
|
12
|
+
super(fields);
|
|
13
|
+
Object.defineProperty(this, "apiAnswerChain", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: void 0
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(this, "apiRequestChain", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: void 0
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(this, "apiDocs", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: void 0
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(this, "headers", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
value: {}
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(this, "inputKey", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: "question"
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(this, "outputKey", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true,
|
|
46
|
+
writable: true,
|
|
47
|
+
value: "output"
|
|
48
|
+
});
|
|
49
|
+
this.apiRequestChain = fields.apiRequestChain;
|
|
50
|
+
this.apiAnswerChain = fields.apiAnswerChain;
|
|
51
|
+
this.apiDocs = fields.apiDocs;
|
|
52
|
+
this.inputKey = fields.inputKey ?? this.inputKey;
|
|
53
|
+
this.outputKey = fields.outputKey ?? this.outputKey;
|
|
54
|
+
this.headers = fields.headers ?? this.headers;
|
|
55
|
+
}
|
|
56
|
+
/** @ignore */
|
|
57
|
+
async _call(values, runManager) {
|
|
58
|
+
const question = values[this.inputKey];
|
|
59
|
+
const api_url = await this.apiRequestChain.predict({ question, api_docs: this.apiDocs }, runManager?.getChild());
|
|
60
|
+
const res = await fetch(api_url, { headers: this.headers });
|
|
61
|
+
const api_response = await res.text();
|
|
62
|
+
const answer = await this.apiAnswerChain.predict({ question, api_docs: this.apiDocs, api_url, api_response }, runManager?.getChild());
|
|
63
|
+
return { [this.outputKey]: answer };
|
|
64
|
+
}
|
|
65
|
+
_chainType() {
|
|
66
|
+
return "api_chain";
|
|
67
|
+
}
|
|
68
|
+
static async deserialize(data) {
|
|
69
|
+
const { api_request_chain, api_answer_chain, api_docs } = data;
|
|
70
|
+
if (!api_request_chain) {
|
|
71
|
+
throw new Error("LLMChain must have api_request_chain");
|
|
72
|
+
}
|
|
73
|
+
if (!api_answer_chain) {
|
|
74
|
+
throw new Error("LLMChain must have api_answer_chain");
|
|
75
|
+
}
|
|
76
|
+
if (!api_docs) {
|
|
77
|
+
throw new Error("LLMChain must have api_docs");
|
|
78
|
+
}
|
|
79
|
+
return new APIChain({
|
|
80
|
+
apiAnswerChain: await LLMChain.deserialize(api_answer_chain),
|
|
81
|
+
apiRequestChain: await LLMChain.deserialize(api_request_chain),
|
|
82
|
+
apiDocs: api_docs,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
serialize() {
|
|
86
|
+
return {
|
|
87
|
+
_type: this._chainType(),
|
|
88
|
+
api_answer_chain: this.apiAnswerChain.serialize(),
|
|
89
|
+
api_request_chain: this.apiRequestChain.serialize(),
|
|
90
|
+
api_docs: this.apiDocs,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
static fromLLMAndAPIDocs(llm, apiDocs, options = {}) {
|
|
94
|
+
const { apiUrlPrompt = API_URL_PROMPT_TEMPLATE, apiResponsePrompt = API_RESPONSE_PROMPT_TEMPLATE, } = options;
|
|
95
|
+
const apiRequestChain = new LLMChain({ prompt: apiUrlPrompt, llm });
|
|
96
|
+
const apiAnswerChain = new LLMChain({ prompt: apiResponsePrompt, llm });
|
|
97
|
+
return new this({
|
|
98
|
+
apiAnswerChain,
|
|
99
|
+
apiRequestChain,
|
|
100
|
+
apiDocs,
|
|
101
|
+
...options,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.API_RESPONSE_PROMPT_TEMPLATE = exports.API_RESPONSE_RAW_PROMPT_TEMPLATE = exports.API_URL_PROMPT_TEMPLATE = exports.API_URL_RAW_PROMPT_TEMPLATE = void 0;
|
|
4
|
+
/* eslint-disable spaced-comment */
|
|
5
|
+
const prompt_js_1 = require("../../prompts/prompt.cjs");
|
|
6
|
+
exports.API_URL_RAW_PROMPT_TEMPLATE = `You are given the below API Documentation:
|
|
7
|
+
{api_docs}
|
|
8
|
+
Using this documentation, generate the full API url to call for answering the user question.
|
|
9
|
+
You should build the API url in order to get a response that is as short as possible, while still getting the necessary information to answer the question. Pay attention to deliberately exclude any unnecessary pieces of data in the API call.
|
|
10
|
+
|
|
11
|
+
Question:{question}
|
|
12
|
+
API url:`;
|
|
13
|
+
exports.API_URL_PROMPT_TEMPLATE = new prompt_js_1.PromptTemplate({
|
|
14
|
+
inputVariables: ["api_docs", "question"],
|
|
15
|
+
template: exports.API_URL_RAW_PROMPT_TEMPLATE,
|
|
16
|
+
});
|
|
17
|
+
exports.API_RESPONSE_RAW_PROMPT_TEMPLATE = `${exports.API_URL_RAW_PROMPT_TEMPLATE} {api_url}
|
|
18
|
+
|
|
19
|
+
Here is the response from the API:
|
|
20
|
+
|
|
21
|
+
{api_response}
|
|
22
|
+
|
|
23
|
+
Summarize this response to answer the original question.
|
|
24
|
+
|
|
25
|
+
Summary:`;
|
|
26
|
+
exports.API_RESPONSE_PROMPT_TEMPLATE = new prompt_js_1.PromptTemplate({
|
|
27
|
+
inputVariables: ["api_docs", "question", "api_url", "api_response"],
|
|
28
|
+
template: exports.API_RESPONSE_RAW_PROMPT_TEMPLATE,
|
|
29
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PromptTemplate } from "../../prompts/prompt.js";
|
|
2
|
+
export declare const API_URL_RAW_PROMPT_TEMPLATE = "You are given the below API Documentation:\n{api_docs}\nUsing this documentation, generate the full API url to call for answering the user question.\nYou should build the API url in order to get a response that is as short as possible, while still getting the necessary information to answer the question. Pay attention to deliberately exclude any unnecessary pieces of data in the API call.\n\nQuestion:{question}\nAPI url:";
|
|
3
|
+
export declare const API_URL_PROMPT_TEMPLATE: PromptTemplate;
|
|
4
|
+
export declare const API_RESPONSE_RAW_PROMPT_TEMPLATE: string;
|
|
5
|
+
export declare const API_RESPONSE_PROMPT_TEMPLATE: PromptTemplate;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* eslint-disable spaced-comment */
|
|
2
|
+
import { PromptTemplate } from "../../prompts/prompt.js";
|
|
3
|
+
export const API_URL_RAW_PROMPT_TEMPLATE = `You are given the below API Documentation:
|
|
4
|
+
{api_docs}
|
|
5
|
+
Using this documentation, generate the full API url to call for answering the user question.
|
|
6
|
+
You should build the API url in order to get a response that is as short as possible, while still getting the necessary information to answer the question. Pay attention to deliberately exclude any unnecessary pieces of data in the API call.
|
|
7
|
+
|
|
8
|
+
Question:{question}
|
|
9
|
+
API url:`;
|
|
10
|
+
export const API_URL_PROMPT_TEMPLATE = /* #__PURE__ */ new PromptTemplate({
|
|
11
|
+
inputVariables: ["api_docs", "question"],
|
|
12
|
+
template: API_URL_RAW_PROMPT_TEMPLATE,
|
|
13
|
+
});
|
|
14
|
+
export const API_RESPONSE_RAW_PROMPT_TEMPLATE = `${API_URL_RAW_PROMPT_TEMPLATE} {api_url}
|
|
15
|
+
|
|
16
|
+
Here is the response from the API:
|
|
17
|
+
|
|
18
|
+
{api_response}
|
|
19
|
+
|
|
20
|
+
Summarize this response to answer the original question.
|
|
21
|
+
|
|
22
|
+
Summary:`;
|
|
23
|
+
export const API_RESPONSE_PROMPT_TEMPLATE = /* #__PURE__ */ new PromptTemplate({
|
|
24
|
+
inputVariables: ["api_docs", "question", "api_url", "api_response"],
|
|
25
|
+
template: API_RESPONSE_RAW_PROMPT_TEMPLATE,
|
|
26
|
+
});
|
package/dist/chains/base.cjs
CHANGED
|
@@ -121,6 +121,10 @@ class BaseChain extends index_js_2.BaseLangChain {
|
|
|
121
121
|
const { VectorDBQAChain } = await import("./vector_db_qa.js");
|
|
122
122
|
return VectorDBQAChain.deserialize(data, values);
|
|
123
123
|
}
|
|
124
|
+
case "api_chain": {
|
|
125
|
+
const { APIChain } = await import("./api/api_chain.js");
|
|
126
|
+
return APIChain.deserialize(data);
|
|
127
|
+
}
|
|
124
128
|
default:
|
|
125
129
|
throw new Error(`Invalid prompt type in config: ${data._type}`);
|
|
126
130
|
}
|
package/dist/chains/base.js
CHANGED
|
@@ -118,6 +118,10 @@ export class BaseChain extends BaseLangChain {
|
|
|
118
118
|
const { VectorDBQAChain } = await import("./vector_db_qa.js");
|
|
119
119
|
return VectorDBQAChain.deserialize(data, values);
|
|
120
120
|
}
|
|
121
|
+
case "api_chain": {
|
|
122
|
+
const { APIChain } = await import("./api/api_chain.js");
|
|
123
|
+
return APIChain.deserialize(data);
|
|
124
|
+
}
|
|
121
125
|
default:
|
|
122
126
|
throw new Error(`Invalid prompt type in config: ${data._type}`);
|
|
123
127
|
}
|
package/dist/chains/index.cjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MultiRetrievalQAChain = exports.MultiPromptChain = exports.LLMRouterChain = exports.RouterChain = exports.MultiRouteChain = exports.OpenAIModerationChain = exports.PRINCIPLES = exports.ConstitutionalPrinciple = exports.ConstitutionalChain = exports.RetrievalQAChain = exports.ConversationalRetrievalQAChain = exports.SqlDatabaseChain = exports.loadSummarizationChain = exports.loadQARefineChain = exports.loadQAMapReduceChain = exports.loadQAStuffChain = exports.loadQAChain = exports.VectorDBQAChain = exports.AnalyzeDocumentChain = exports.ChatVectorDBQAChain = exports.RefineDocumentsChain = exports.MapReduceDocumentsChain = exports.StuffDocumentsChain = exports.SimpleSequentialChain = exports.SequentialChain = exports.ConversationChain = exports.LLMChain = exports.BaseChain = void 0;
|
|
3
|
+
exports.MultiRetrievalQAChain = exports.MultiPromptChain = exports.LLMRouterChain = exports.RouterChain = exports.MultiRouteChain = exports.OpenAIModerationChain = exports.PRINCIPLES = exports.ConstitutionalPrinciple = exports.ConstitutionalChain = exports.RetrievalQAChain = exports.ConversationalRetrievalQAChain = exports.SqlDatabaseChain = exports.loadSummarizationChain = exports.loadQARefineChain = exports.loadQAMapReduceChain = exports.loadQAStuffChain = exports.loadQAChain = exports.VectorDBQAChain = exports.AnalyzeDocumentChain = exports.ChatVectorDBQAChain = exports.RefineDocumentsChain = exports.MapReduceDocumentsChain = exports.StuffDocumentsChain = exports.SimpleSequentialChain = exports.SequentialChain = exports.ConversationChain = exports.APIChain = exports.LLMChain = exports.BaseChain = void 0;
|
|
4
4
|
var base_js_1 = require("./base.cjs");
|
|
5
5
|
Object.defineProperty(exports, "BaseChain", { enumerable: true, get: function () { return base_js_1.BaseChain; } });
|
|
6
6
|
var llm_chain_js_1 = require("./llm_chain.cjs");
|
|
7
7
|
Object.defineProperty(exports, "LLMChain", { enumerable: true, get: function () { return llm_chain_js_1.LLMChain; } });
|
|
8
|
+
var api_chain_js_1 = require("./api/api_chain.cjs");
|
|
9
|
+
Object.defineProperty(exports, "APIChain", { enumerable: true, get: function () { return api_chain_js_1.APIChain; } });
|
|
8
10
|
var conversation_js_1 = require("./conversation.cjs");
|
|
9
11
|
Object.defineProperty(exports, "ConversationChain", { enumerable: true, get: function () { return conversation_js_1.ConversationChain; } });
|
|
10
12
|
var sequential_chain_js_1 = require("./sequential_chain.cjs");
|
package/dist/chains/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { BaseChain, ChainInputs } from "./base.js";
|
|
2
2
|
export { LLMChain, LLMChainInput } from "./llm_chain.js";
|
|
3
|
+
export { APIChain, APIChainInput, APIChainOptions } from "./api/api_chain.js";
|
|
3
4
|
export { ConversationChain } from "./conversation.js";
|
|
4
5
|
export { SequentialChain, SequentialChainInput, SimpleSequentialChain, SimpleSequentialChainInput, } from "./sequential_chain.js";
|
|
5
6
|
export { StuffDocumentsChain, StuffDocumentsChainInput, MapReduceDocumentsChain, MapReduceDocumentsChainInput, RefineDocumentsChain, RefineDocumentsChainInput, } from "./combine_docs_chain.js";
|
|
@@ -13,7 +14,7 @@ export { ConversationalRetrievalQAChain, ConversationalRetrievalQAChainInput, }
|
|
|
13
14
|
export { RetrievalQAChain, RetrievalQAChainInput } from "./retrieval_qa.js";
|
|
14
15
|
export { ConstitutionalChainInput, ConstitutionalChain, } from "./constitutional_ai/constitutional_chain.js";
|
|
15
16
|
export { ConstitutionalPrinciple, PRINCIPLES, } from "./constitutional_ai/constitutional_principle.js";
|
|
16
|
-
export { SerializedLLMChain, SerializedSequentialChain, SerializedSimpleSequentialChain, SerializedSqlDatabaseChain, SerializedAnalyzeDocumentChain, SerializedBaseChain, SerializedChatVectorDBQAChain, SerializedMapReduceDocumentsChain, SerializedStuffDocumentsChain, SerializedVectorDBQAChain, SerializedRefineDocumentsChain, } from "./serde.js";
|
|
17
|
+
export { SerializedLLMChain, SerializedSequentialChain, SerializedSimpleSequentialChain, SerializedSqlDatabaseChain, SerializedAnalyzeDocumentChain, SerializedAPIChain, SerializedBaseChain, SerializedChatVectorDBQAChain, SerializedMapReduceDocumentsChain, SerializedStuffDocumentsChain, SerializedVectorDBQAChain, SerializedRefineDocumentsChain, } from "./serde.js";
|
|
17
18
|
export { OpenAIModerationChain } from "./openai_moderation.js";
|
|
18
19
|
export { MultiRouteChain, MultiRouteChainInput, RouterChain, } from "./router/multi_route.js";
|
|
19
20
|
export { LLMRouterChain, LLMRouterChainInput, RouterOutputSchema, } from "./router/llm_router.js";
|
package/dist/chains/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { BaseChain } from "./base.js";
|
|
2
2
|
export { LLMChain } from "./llm_chain.js";
|
|
3
|
+
export { APIChain } from "./api/api_chain.js";
|
|
3
4
|
export { ConversationChain } from "./conversation.js";
|
|
4
5
|
export { SequentialChain, SimpleSequentialChain, } from "./sequential_chain.js";
|
|
5
6
|
export { StuffDocumentsChain, MapReduceDocumentsChain, RefineDocumentsChain, } from "./combine_docs_chain.js";
|
package/dist/chains/serde.d.ts
CHANGED
|
@@ -26,6 +26,12 @@ export type SerializedVectorDBQAChain = {
|
|
|
26
26
|
k: number;
|
|
27
27
|
combine_documents_chain: SerializedBaseChain;
|
|
28
28
|
};
|
|
29
|
+
export type SerializedAPIChain = {
|
|
30
|
+
_type: "api_chain";
|
|
31
|
+
api_request_chain: SerializedLLMChain;
|
|
32
|
+
api_answer_chain: SerializedLLMChain;
|
|
33
|
+
api_docs: string;
|
|
34
|
+
};
|
|
29
35
|
export type SerializedStuffDocumentsChain = {
|
|
30
36
|
_type: "stuff_documents_chain";
|
|
31
37
|
llm_chain?: SerializedLLMChain;
|
|
@@ -63,4 +69,4 @@ export type SerializedConstitutionalChain = {
|
|
|
63
69
|
revisionChain?: SerializedBaseChain;
|
|
64
70
|
ConstitutionalPrinciple?: SerializedConstitutionalPrinciple[];
|
|
65
71
|
};
|
|
66
|
-
export type SerializedBaseChain = SerializedLLMChain | SerializedSequentialChain | SerializedSimpleSequentialChain | SerializedVectorDBQAChain | SerializedStuffDocumentsChain | SerializedSqlDatabaseChain | SerializedChatVectorDBQAChain | SerializedMapReduceDocumentsChain | SerializedAnalyzeDocumentChain | SerializedRefineDocumentsChain | SerializedConstitutionalChain;
|
|
72
|
+
export type SerializedBaseChain = SerializedLLMChain | SerializedSequentialChain | SerializedSimpleSequentialChain | SerializedVectorDBQAChain | SerializedAPIChain | SerializedStuffDocumentsChain | SerializedSqlDatabaseChain | SerializedChatVectorDBQAChain | SerializedMapReduceDocumentsChain | SerializedAnalyzeDocumentChain | SerializedRefineDocumentsChain | SerializedConstitutionalChain;
|
|
@@ -42,6 +42,12 @@ class ChatAnthropic extends base_js_1.BaseChatModel {
|
|
|
42
42
|
writable: true,
|
|
43
43
|
value: void 0
|
|
44
44
|
});
|
|
45
|
+
Object.defineProperty(this, "apiUrl", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true,
|
|
49
|
+
value: void 0
|
|
50
|
+
});
|
|
45
51
|
Object.defineProperty(this, "temperature", {
|
|
46
52
|
enumerable: true,
|
|
47
53
|
configurable: true,
|
|
@@ -113,6 +119,8 @@ class ChatAnthropic extends base_js_1.BaseChatModel {
|
|
|
113
119
|
if (!this.apiKey) {
|
|
114
120
|
throw new Error("Anthropic API key not found");
|
|
115
121
|
}
|
|
122
|
+
// Support overriding the default API URL (i.e., https://api.anthropic.com)
|
|
123
|
+
this.apiUrl = fields?.anthropicApiUrl;
|
|
116
124
|
this.modelName = fields?.modelName ?? this.modelName;
|
|
117
125
|
this.invocationKwargs = fields?.invocationKwargs ?? {};
|
|
118
126
|
this.temperature = fields?.temperature ?? this.temperature;
|
|
@@ -193,7 +201,8 @@ class ChatAnthropic extends base_js_1.BaseChatModel {
|
|
|
193
201
|
let makeCompletionRequest;
|
|
194
202
|
if (request.stream) {
|
|
195
203
|
if (!this.streamingClient) {
|
|
196
|
-
this.
|
|
204
|
+
const options = this.apiUrl ? { apiUrl: this.apiUrl } : undefined;
|
|
205
|
+
this.streamingClient = new sdk_1.Client(this.apiKey, options);
|
|
197
206
|
}
|
|
198
207
|
makeCompletionRequest = async () => {
|
|
199
208
|
let currentCompletion = "";
|
|
@@ -226,7 +235,8 @@ class ChatAnthropic extends base_js_1.BaseChatModel {
|
|
|
226
235
|
}
|
|
227
236
|
else {
|
|
228
237
|
if (!this.batchClient) {
|
|
229
|
-
this.
|
|
238
|
+
const options = this.apiUrl ? { apiUrl: this.apiUrl } : undefined;
|
|
239
|
+
this.batchClient = new sdk_1.Client(this.apiKey, options);
|
|
230
240
|
}
|
|
231
241
|
makeCompletionRequest = async () => this.batchClient
|
|
232
242
|
.complete(request, {
|
|
@@ -64,6 +64,7 @@ export declare class ChatAnthropic extends BaseChatModel implements AnthropicInp
|
|
|
64
64
|
CallOptions: BaseLanguageModelCallOptions;
|
|
65
65
|
get callKeys(): string[];
|
|
66
66
|
apiKey?: string;
|
|
67
|
+
apiUrl?: string;
|
|
67
68
|
temperature: number;
|
|
68
69
|
topK: number;
|
|
69
70
|
topP: number;
|
|
@@ -76,6 +77,7 @@ export declare class ChatAnthropic extends BaseChatModel implements AnthropicInp
|
|
|
76
77
|
private streamingClient;
|
|
77
78
|
constructor(fields?: Partial<AnthropicInput> & BaseChatModelParams & {
|
|
78
79
|
anthropicApiKey?: string;
|
|
80
|
+
anthropicApiUrl?: string;
|
|
79
81
|
});
|
|
80
82
|
/**
|
|
81
83
|
* Get the parameters used to invoke the model
|
|
@@ -39,6 +39,12 @@ export class ChatAnthropic extends BaseChatModel {
|
|
|
39
39
|
writable: true,
|
|
40
40
|
value: void 0
|
|
41
41
|
});
|
|
42
|
+
Object.defineProperty(this, "apiUrl", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
writable: true,
|
|
46
|
+
value: void 0
|
|
47
|
+
});
|
|
42
48
|
Object.defineProperty(this, "temperature", {
|
|
43
49
|
enumerable: true,
|
|
44
50
|
configurable: true,
|
|
@@ -110,6 +116,8 @@ export class ChatAnthropic extends BaseChatModel {
|
|
|
110
116
|
if (!this.apiKey) {
|
|
111
117
|
throw new Error("Anthropic API key not found");
|
|
112
118
|
}
|
|
119
|
+
// Support overriding the default API URL (i.e., https://api.anthropic.com)
|
|
120
|
+
this.apiUrl = fields?.anthropicApiUrl;
|
|
113
121
|
this.modelName = fields?.modelName ?? this.modelName;
|
|
114
122
|
this.invocationKwargs = fields?.invocationKwargs ?? {};
|
|
115
123
|
this.temperature = fields?.temperature ?? this.temperature;
|
|
@@ -190,7 +198,8 @@ export class ChatAnthropic extends BaseChatModel {
|
|
|
190
198
|
let makeCompletionRequest;
|
|
191
199
|
if (request.stream) {
|
|
192
200
|
if (!this.streamingClient) {
|
|
193
|
-
this.
|
|
201
|
+
const options = this.apiUrl ? { apiUrl: this.apiUrl } : undefined;
|
|
202
|
+
this.streamingClient = new AnthropicApi(this.apiKey, options);
|
|
194
203
|
}
|
|
195
204
|
makeCompletionRequest = async () => {
|
|
196
205
|
let currentCompletion = "";
|
|
@@ -223,7 +232,8 @@ export class ChatAnthropic extends BaseChatModel {
|
|
|
223
232
|
}
|
|
224
233
|
else {
|
|
225
234
|
if (!this.batchClient) {
|
|
226
|
-
this.
|
|
235
|
+
const options = this.apiUrl ? { apiUrl: this.apiUrl } : undefined;
|
|
236
|
+
this.batchClient = new AnthropicApi(this.apiKey, options);
|
|
227
237
|
}
|
|
228
238
|
makeCompletionRequest = async () => this.batchClient
|
|
229
239
|
.complete(request, {
|