@langchain/google-common 0.2.18 → 1.0.1
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/CHANGELOG.md +23 -0
- package/LICENSE +6 -6
- package/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/auth.cjs +82 -116
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.cts +46 -0
- package/dist/auth.d.cts.map +1 -0
- package/dist/auth.d.ts +41 -36
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +80 -110
- package/dist/auth.js.map +1 -0
- package/dist/chat_models.cjs +264 -466
- package/dist/chat_models.cjs.map +1 -0
- package/dist/chat_models.d.cts +109 -0
- package/dist/chat_models.d.cts.map +1 -0
- package/dist/chat_models.d.ts +98 -73
- package/dist/chat_models.d.ts.map +1 -0
- package/dist/chat_models.js +258 -457
- package/dist/chat_models.js.map +1 -0
- package/dist/connection.cjs +321 -466
- package/dist/connection.cjs.map +1 -0
- package/dist/connection.d.cts +109 -0
- package/dist/connection.d.cts.map +1 -0
- package/dist/connection.d.ts +98 -91
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +317 -459
- package/dist/connection.js.map +1 -0
- package/dist/embeddings.cjs +135 -186
- package/dist/embeddings.cjs.map +1 -0
- package/dist/embeddings.d.cts +44 -0
- package/dist/embeddings.d.cts.map +1 -0
- package/dist/embeddings.d.ts +38 -32
- package/dist/embeddings.d.ts.map +1 -0
- package/dist/embeddings.js +133 -181
- package/dist/embeddings.js.map +1 -0
- package/dist/experimental/media.cjs +380 -482
- package/dist/experimental/media.cjs.map +1 -0
- package/dist/experimental/media.d.cts +198 -0
- package/dist/experimental/media.d.cts.map +1 -0
- package/dist/experimental/media.d.ts +190 -202
- package/dist/experimental/media.d.ts.map +1 -0
- package/dist/experimental/media.js +369 -468
- package/dist/experimental/media.js.map +1 -0
- package/dist/experimental/utils/media_core.cjs +403 -517
- package/dist/experimental/utils/media_core.cjs.map +1 -0
- package/dist/experimental/utils/media_core.d.cts +215 -0
- package/dist/experimental/utils/media_core.d.cts.map +1 -0
- package/dist/experimental/utils/media_core.d.ts +171 -165
- package/dist/experimental/utils/media_core.d.ts.map +1 -0
- package/dist/experimental/utils/media_core.js +395 -506
- package/dist/experimental/utils/media_core.js.map +1 -0
- package/dist/index.cjs +58 -27
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -11
- package/dist/index.js +13 -11
- package/dist/llms.cjs +157 -244
- package/dist/llms.cjs.map +1 -0
- package/dist/llms.d.cts +72 -0
- package/dist/llms.d.cts.map +1 -0
- package/dist/llms.d.ts +64 -54
- package/dist/llms.d.ts.map +1 -0
- package/dist/llms.js +154 -238
- package/dist/llms.js.map +1 -0
- package/dist/output_parsers.cjs +148 -173
- package/dist/output_parsers.cjs.map +1 -0
- package/dist/output_parsers.d.cts +53 -0
- package/dist/output_parsers.d.cts.map +1 -0
- package/dist/output_parsers.d.ts +46 -42
- package/dist/output_parsers.d.ts.map +1 -0
- package/dist/output_parsers.js +146 -168
- package/dist/output_parsers.js.map +1 -0
- package/dist/profiles.cjs +219 -0
- package/dist/profiles.cjs.map +1 -0
- package/dist/profiles.js +218 -0
- package/dist/profiles.js.map +1 -0
- package/dist/types-anthropic.d.cts +229 -0
- package/dist/types-anthropic.d.cts.map +1 -0
- package/dist/types-anthropic.d.ts +221 -215
- package/dist/types-anthropic.d.ts.map +1 -0
- package/dist/types.cjs +51 -62
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +748 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +669 -656
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +46 -45
- package/dist/types.js.map +1 -0
- package/dist/utils/anthropic.cjs +598 -821
- package/dist/utils/anthropic.cjs.map +1 -0
- package/dist/utils/anthropic.js +597 -818
- package/dist/utils/anthropic.js.map +1 -0
- package/dist/utils/common.cjs +130 -211
- package/dist/utils/common.cjs.map +1 -0
- package/dist/utils/common.d.cts +13 -0
- package/dist/utils/common.d.cts.map +1 -0
- package/dist/utils/common.d.ts +12 -7
- package/dist/utils/common.d.ts.map +1 -0
- package/dist/utils/common.js +128 -207
- package/dist/utils/common.js.map +1 -0
- package/dist/utils/failed_handler.cjs +28 -30
- package/dist/utils/failed_handler.cjs.map +1 -0
- package/dist/utils/failed_handler.d.cts +9 -0
- package/dist/utils/failed_handler.d.cts.map +1 -0
- package/dist/utils/failed_handler.d.ts +8 -2
- package/dist/utils/failed_handler.d.ts.map +1 -0
- package/dist/utils/failed_handler.js +28 -28
- package/dist/utils/failed_handler.js.map +1 -0
- package/dist/utils/gemini.cjs +1020 -1488
- package/dist/utils/gemini.cjs.map +1 -0
- package/dist/utils/gemini.d.cts +51 -0
- package/dist/utils/gemini.d.cts.map +1 -0
- package/dist/utils/gemini.d.ts +51 -48
- package/dist/utils/gemini.d.ts.map +1 -0
- package/dist/utils/gemini.js +1015 -1479
- package/dist/utils/gemini.js.map +1 -0
- package/dist/utils/index.cjs +38 -23
- package/dist/utils/index.d.cts +8 -0
- package/dist/utils/index.d.ts +8 -7
- package/dist/utils/index.js +8 -7
- package/dist/utils/palm.d.cts +11 -0
- package/dist/utils/palm.d.cts.map +1 -0
- package/dist/utils/palm.d.ts +9 -4
- package/dist/utils/palm.d.ts.map +1 -0
- package/dist/utils/safety.cjs +13 -22
- package/dist/utils/safety.cjs.map +1 -0
- package/dist/utils/safety.d.cts +12 -0
- package/dist/utils/safety.d.cts.map +1 -0
- package/dist/utils/safety.d.ts +10 -4
- package/dist/utils/safety.d.ts.map +1 -0
- package/dist/utils/safety.js +13 -19
- package/dist/utils/safety.js.map +1 -0
- package/dist/utils/stream.cjs +296 -475
- package/dist/utils/stream.cjs.map +1 -0
- package/dist/utils/stream.d.cts +165 -0
- package/dist/utils/stream.d.cts.map +1 -0
- package/dist/utils/stream.d.ts +156 -131
- package/dist/utils/stream.d.ts.map +1 -0
- package/dist/utils/stream.js +293 -469
- package/dist/utils/stream.js.map +1 -0
- package/dist/utils/zod_to_gemini_parameters.cjs +43 -81
- package/dist/utils/zod_to_gemini_parameters.cjs.map +1 -0
- package/dist/utils/zod_to_gemini_parameters.d.cts +22 -0
- package/dist/utils/zod_to_gemini_parameters.d.cts.map +1 -0
- package/dist/utils/zod_to_gemini_parameters.d.ts +21 -6
- package/dist/utils/zod_to_gemini_parameters.d.ts.map +1 -0
- package/dist/utils/zod_to_gemini_parameters.js +40 -76
- package/dist/utils/zod_to_gemini_parameters.js.map +1 -0
- package/package.json +72 -85
- package/dist/types-anthropic.cjs +0 -2
- package/dist/types-anthropic.js +0 -1
- package/dist/utils/anthropic.d.ts +0 -4
- package/dist/utils/palm.cjs +0 -2
- package/dist/utils/palm.js +0 -1
- package/experimental/media.cjs +0 -1
- package/experimental/media.d.cts +0 -1
- package/experimental/media.d.ts +0 -1
- package/experimental/media.js +0 -1
- package/experimental/utils/media_core.cjs +0 -1
- package/experimental/utils/media_core.d.cts +0 -1
- package/experimental/utils/media_core.d.ts +0 -1
- package/experimental/utils/media_core.js +0 -1
- package/index.cjs +0 -1
- package/index.d.cts +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/types.cjs +0 -1
- package/types.d.cts +0 -1
- package/types.d.ts +0 -1
- package/types.js +0 -1
- package/utils.cjs +0 -1
- package/utils.d.cts +0 -1
- package/utils.d.ts +0 -1
- package/utils.js +0 -1
package/dist/output_parsers.cjs
CHANGED
|
@@ -1,175 +1,150 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const __langchain_core_output_parsers = require_rolldown_runtime.__toESM(require("@langchain/core/output_parsers"));
|
|
3
|
+
|
|
4
|
+
//#region src/output_parsers.ts
|
|
5
|
+
var BaseGoogleSearchOutputParser = class extends __langchain_core_output_parsers.BaseLLMOutputParser {
|
|
6
|
+
lc_namespace = ["google_common", "output_parsers"];
|
|
7
|
+
generationToGroundingInfo(generation) {
|
|
8
|
+
if ("message" in generation) {
|
|
9
|
+
const responseMetadata = generation?.message?.response_metadata;
|
|
10
|
+
const metadata = responseMetadata?.groundingMetadata;
|
|
11
|
+
const supports = responseMetadata?.groundingSupport ?? metadata?.groundingSupports ?? [];
|
|
12
|
+
if (metadata) return {
|
|
13
|
+
metadata,
|
|
14
|
+
supports
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return void 0;
|
|
18
|
+
}
|
|
19
|
+
generationsToGroundingInfo(generations) {
|
|
20
|
+
for (const generation of generations) {
|
|
21
|
+
const info = this.generationToGroundingInfo(generation);
|
|
22
|
+
if (info !== void 0) return info;
|
|
23
|
+
}
|
|
24
|
+
return void 0;
|
|
25
|
+
}
|
|
26
|
+
generationToString(generation) {
|
|
27
|
+
if ("message" in generation) {
|
|
28
|
+
const content = generation?.message?.content;
|
|
29
|
+
if (typeof content === "string") return content;
|
|
30
|
+
else return content.map((c) => {
|
|
31
|
+
if (c?.type === "text") return c?.text ?? "";
|
|
32
|
+
else return "";
|
|
33
|
+
}).reduce((previousValue, currentValue) => `${previousValue}${currentValue}`);
|
|
34
|
+
}
|
|
35
|
+
return generation.text;
|
|
36
|
+
}
|
|
37
|
+
generationsToString(generations) {
|
|
38
|
+
return generations.map((generation) => this.generationToString(generation)).reduce((previousValue, currentValue) => `${previousValue}${currentValue}`);
|
|
39
|
+
}
|
|
40
|
+
annotateSegment(text, grounding, support, index) {
|
|
41
|
+
const start = support.segment.startIndex ?? 0;
|
|
42
|
+
const end = support.segment.endIndex;
|
|
43
|
+
const textBefore = text.substring(0, start);
|
|
44
|
+
const textSegment = text.substring(start, end);
|
|
45
|
+
const textAfter = text.substring(end);
|
|
46
|
+
const textPrefix = this.segmentPrefix(grounding, support, index) ?? "";
|
|
47
|
+
const textSuffix = this.segmentSuffix(grounding, support, index) ?? "";
|
|
48
|
+
return `${textBefore}${textPrefix}${textSegment}${textSuffix}${textAfter}`;
|
|
49
|
+
}
|
|
50
|
+
annotateTextSegments(text, grounding) {
|
|
51
|
+
let ret = text;
|
|
52
|
+
for (let co = grounding.supports.length - 1; co >= 0; co -= 1) {
|
|
53
|
+
const support = grounding.supports[co];
|
|
54
|
+
ret = this.annotateSegment(ret, grounding, support, co);
|
|
55
|
+
}
|
|
56
|
+
return ret;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Google requires us to
|
|
60
|
+
* "Display the Search Suggestion exactly as provided without any modifications"
|
|
61
|
+
* So this will typically be called from the textSuffix() method to get
|
|
62
|
+
* a string that renders HTML.
|
|
63
|
+
* See https://ai.google.dev/gemini-api/docs/grounding/search-suggestions
|
|
64
|
+
* @param grounding
|
|
65
|
+
*/
|
|
66
|
+
searchSuggestion(grounding) {
|
|
67
|
+
return grounding?.metadata?.searchEntryPoint?.renderedContent ?? "";
|
|
68
|
+
}
|
|
69
|
+
annotateText(text, grounding) {
|
|
70
|
+
const prefix = this.textPrefix(text, grounding) ?? "";
|
|
71
|
+
const suffix = this.textSuffix(text, grounding) ?? "";
|
|
72
|
+
const body = this.annotateTextSegments(text, grounding);
|
|
73
|
+
return `${prefix}${body}${suffix}`;
|
|
74
|
+
}
|
|
75
|
+
async parseResult(generations, _callbacks) {
|
|
76
|
+
const text = this.generationsToString(generations);
|
|
77
|
+
const grounding = this.generationsToGroundingInfo(generations);
|
|
78
|
+
if (!grounding) return text;
|
|
79
|
+
return this.annotateText(text, grounding);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var SimpleGoogleSearchOutputParser = class extends BaseGoogleSearchOutputParser {
|
|
83
|
+
segmentPrefix(_grounding, _support, _index) {
|
|
84
|
+
return void 0;
|
|
85
|
+
}
|
|
86
|
+
segmentSuffix(_grounding, support, _index) {
|
|
87
|
+
const indices = support.groundingChunkIndices.map((i) => i + 1);
|
|
88
|
+
return ` [${indices.join(", ")}]`;
|
|
89
|
+
}
|
|
90
|
+
textPrefix(_text, _grounding) {
|
|
91
|
+
return "Google Says:\n";
|
|
92
|
+
}
|
|
93
|
+
chunkToString(chunk, index) {
|
|
94
|
+
const info = chunk.retrievedContext ?? chunk.web;
|
|
95
|
+
return `${index + 1}. ${info.title} - ${info.uri}`;
|
|
96
|
+
}
|
|
97
|
+
textSuffix(_text, grounding) {
|
|
98
|
+
let ret = "\n";
|
|
99
|
+
const chunks = grounding?.metadata?.groundingChunks ?? [];
|
|
100
|
+
chunks.forEach((chunk, index) => {
|
|
101
|
+
ret = `${ret}${this.chunkToString(chunk, index)}\n`;
|
|
102
|
+
});
|
|
103
|
+
return ret;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var MarkdownGoogleSearchOutputParser = class extends BaseGoogleSearchOutputParser {
|
|
107
|
+
segmentPrefix(_grounding, _support, _index) {
|
|
108
|
+
return void 0;
|
|
109
|
+
}
|
|
110
|
+
chunkLink(grounding, index) {
|
|
111
|
+
const chunk = grounding.metadata.groundingChunks[index];
|
|
112
|
+
const url = chunk.retrievedContext?.uri ?? chunk.web?.uri;
|
|
113
|
+
const num = index + 1;
|
|
114
|
+
return `[[${num}](${url})]`;
|
|
115
|
+
}
|
|
116
|
+
segmentSuffix(grounding, support, _index) {
|
|
117
|
+
let ret = "";
|
|
118
|
+
support.groundingChunkIndices.forEach((chunkIndex) => {
|
|
119
|
+
const link = this.chunkLink(grounding, chunkIndex);
|
|
120
|
+
ret = `${ret}${link}`;
|
|
121
|
+
});
|
|
122
|
+
return ret;
|
|
123
|
+
}
|
|
124
|
+
textPrefix(_text, _grounding) {
|
|
125
|
+
return void 0;
|
|
126
|
+
}
|
|
127
|
+
chunkSuffixLink(chunk, index) {
|
|
128
|
+
const num = index + 1;
|
|
129
|
+
const info = chunk.retrievedContext ?? chunk.web;
|
|
130
|
+
const url = info.uri;
|
|
131
|
+
const site = info.title;
|
|
132
|
+
return `${num}. [${site}](${url})`;
|
|
133
|
+
}
|
|
134
|
+
textSuffix(_text, grounding) {
|
|
135
|
+
let ret = "\n**Search Sources**\n";
|
|
136
|
+
const chunks = grounding.metadata.groundingChunks;
|
|
137
|
+
chunks.forEach((chunk, index) => {
|
|
138
|
+
ret = `${ret}${this.chunkSuffixLink(chunk, index)}\n`;
|
|
139
|
+
});
|
|
140
|
+
const search = this.searchSuggestion(grounding);
|
|
141
|
+
ret = `${ret}\n${search}`;
|
|
142
|
+
return ret;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
//#endregion
|
|
110
147
|
exports.BaseGoogleSearchOutputParser = BaseGoogleSearchOutputParser;
|
|
111
|
-
class SimpleGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {
|
|
112
|
-
segmentPrefix(_grounding, _support, _index) {
|
|
113
|
-
return undefined;
|
|
114
|
-
}
|
|
115
|
-
segmentSuffix(_grounding, support, _index) {
|
|
116
|
-
const indices = support.groundingChunkIndices.map((i) => i + 1);
|
|
117
|
-
return ` [${indices.join(", ")}]`;
|
|
118
|
-
}
|
|
119
|
-
textPrefix(_text, _grounding) {
|
|
120
|
-
return "Google Says:\n";
|
|
121
|
-
}
|
|
122
|
-
chunkToString(chunk, index) {
|
|
123
|
-
const info = chunk.retrievedContext ?? chunk.web;
|
|
124
|
-
return `${index + 1}. ${info.title} - ${info.uri}`;
|
|
125
|
-
}
|
|
126
|
-
textSuffix(_text, grounding) {
|
|
127
|
-
let ret = "\n";
|
|
128
|
-
const chunks = grounding?.metadata?.groundingChunks ?? [];
|
|
129
|
-
chunks.forEach((chunk, index) => {
|
|
130
|
-
ret = `${ret}${this.chunkToString(chunk, index)}\n`;
|
|
131
|
-
});
|
|
132
|
-
return ret;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
exports.SimpleGoogleSearchOutputParser = SimpleGoogleSearchOutputParser;
|
|
136
|
-
class MarkdownGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {
|
|
137
|
-
segmentPrefix(_grounding, _support, _index) {
|
|
138
|
-
return undefined;
|
|
139
|
-
}
|
|
140
|
-
chunkLink(grounding, index) {
|
|
141
|
-
const chunk = grounding.metadata.groundingChunks[index];
|
|
142
|
-
const url = chunk.retrievedContext?.uri ?? chunk.web?.uri;
|
|
143
|
-
const num = index + 1;
|
|
144
|
-
return `[[${num}](${url})]`;
|
|
145
|
-
}
|
|
146
|
-
segmentSuffix(grounding, support, _index) {
|
|
147
|
-
let ret = "";
|
|
148
|
-
support.groundingChunkIndices.forEach((chunkIndex) => {
|
|
149
|
-
const link = this.chunkLink(grounding, chunkIndex);
|
|
150
|
-
ret = `${ret}${link}`;
|
|
151
|
-
});
|
|
152
|
-
return ret;
|
|
153
|
-
}
|
|
154
|
-
textPrefix(_text, _grounding) {
|
|
155
|
-
return undefined;
|
|
156
|
-
}
|
|
157
|
-
chunkSuffixLink(chunk, index) {
|
|
158
|
-
const num = index + 1;
|
|
159
|
-
const info = chunk.retrievedContext ?? chunk.web;
|
|
160
|
-
const url = info.uri;
|
|
161
|
-
const site = info.title;
|
|
162
|
-
return `${num}. [${site}](${url})`;
|
|
163
|
-
}
|
|
164
|
-
textSuffix(_text, grounding) {
|
|
165
|
-
let ret = "\n**Search Sources**\n";
|
|
166
|
-
const chunks = grounding.metadata.groundingChunks;
|
|
167
|
-
chunks.forEach((chunk, index) => {
|
|
168
|
-
ret = `${ret}${this.chunkSuffixLink(chunk, index)}\n`;
|
|
169
|
-
});
|
|
170
|
-
const search = this.searchSuggestion(grounding);
|
|
171
|
-
ret = `${ret}\n${search}`;
|
|
172
|
-
return ret;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
148
|
exports.MarkdownGoogleSearchOutputParser = MarkdownGoogleSearchOutputParser;
|
|
149
|
+
exports.SimpleGoogleSearchOutputParser = SimpleGoogleSearchOutputParser;
|
|
150
|
+
//# sourceMappingURL=output_parsers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output_parsers.cjs","names":["BaseLLMOutputParser","generation: Generation | ChatGeneration","generations: Generations","content: MessageContent","text: string","grounding: GroundingInfo","support: GeminiGroundingSupport","index: number","_callbacks?: Callbacks","_grounding: GroundingInfo","_support: GeminiGroundingSupport","_index: number","indices: number[]","_text: string","chunk: GeminiGroundingChunk","chunks: GeminiGroundingChunk[]"],"sources":["../src/output_parsers.ts"],"sourcesContent":["import { BaseLLMOutputParser } from \"@langchain/core/output_parsers\";\nimport { Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { ChatGeneration, Generation } from \"@langchain/core/outputs\";\nimport { MessageContent } from \"@langchain/core/messages\";\nimport {\n GeminiGroundingChunk,\n GeminiGroundingMetadata,\n GeminiGroundingSupport,\n} from \"./types.js\";\n\ntype Generations = Generation[] | ChatGeneration[];\n\ntype GroundingInfo = {\n metadata: GeminiGroundingMetadata;\n supports: GeminiGroundingSupport[];\n};\n\nexport abstract class BaseGoogleSearchOutputParser extends BaseLLMOutputParser<string> {\n lc_namespace: string[] = [\"google_common\", \"output_parsers\"];\n\n protected generationToGroundingInfo(\n generation: Generation | ChatGeneration\n ): GroundingInfo | undefined {\n if (\"message\" in generation) {\n const responseMetadata = generation?.message?.response_metadata;\n const metadata = responseMetadata?.groundingMetadata;\n const supports =\n responseMetadata?.groundingSupport ?? metadata?.groundingSupports ?? [];\n if (metadata) {\n return {\n metadata,\n supports,\n };\n }\n }\n return undefined;\n }\n\n protected generationsToGroundingInfo(\n generations: Generations\n ): GroundingInfo | undefined {\n for (const generation of generations) {\n const info = this.generationToGroundingInfo(generation);\n if (info !== undefined) {\n return info;\n }\n }\n return undefined;\n }\n\n protected generationToString(\n generation: Generation | ChatGeneration\n ): string {\n if (\"message\" in generation) {\n const content: MessageContent = generation?.message?.content;\n if (typeof content === \"string\") {\n return content;\n } else {\n return content\n .map((c) => {\n if (c?.type === \"text\") {\n return c?.text ?? \"\";\n } else {\n return \"\";\n }\n })\n .reduce(\n (previousValue, currentValue) => `${previousValue}${currentValue}`\n );\n }\n }\n return generation.text;\n }\n\n protected generationsToString(generations: Generations): string {\n return generations\n .map((generation) => this.generationToString(generation))\n .reduce(\n (previousValue, currentValue) => `${previousValue}${currentValue}`\n );\n }\n\n protected abstract segmentPrefix(\n grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n index: number\n ): string | undefined;\n\n protected abstract segmentSuffix(\n grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n index: number\n ): string | undefined;\n\n protected annotateSegment(\n text: string,\n grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n index: number\n ): string {\n const start = support.segment.startIndex ?? 0;\n const end = support.segment.endIndex;\n\n const textBefore = text.substring(0, start);\n const textSegment = text.substring(start, end);\n const textAfter = text.substring(end);\n\n const textPrefix = this.segmentPrefix(grounding, support, index) ?? \"\";\n const textSuffix = this.segmentSuffix(grounding, support, index) ?? \"\";\n\n return `${textBefore}${textPrefix}${textSegment}${textSuffix}${textAfter}`;\n }\n\n protected annotateTextSegments(\n text: string,\n grounding: GroundingInfo\n ): string {\n // Go through each support info in reverse, since the segment info\n // is sorted, and we won't need to adjust string indexes this way.\n let ret = text;\n for (let co = grounding.supports.length - 1; co >= 0; co -= 1) {\n const support = grounding.supports[co];\n ret = this.annotateSegment(ret, grounding, support, co);\n }\n return ret;\n }\n\n protected abstract textPrefix(\n text: string,\n grounding: GroundingInfo\n ): string | undefined;\n\n protected abstract textSuffix(\n text: string,\n grounding: GroundingInfo\n ): string | undefined;\n\n /**\n * Google requires us to\n * \"Display the Search Suggestion exactly as provided without any modifications\"\n * So this will typically be called from the textSuffix() method to get\n * a string that renders HTML.\n * See https://ai.google.dev/gemini-api/docs/grounding/search-suggestions\n * @param grounding\n */\n protected searchSuggestion(grounding: GroundingInfo): string {\n return grounding?.metadata?.searchEntryPoint?.renderedContent ?? \"\";\n }\n\n protected annotateText(text: string, grounding: GroundingInfo): string {\n const prefix = this.textPrefix(text, grounding) ?? \"\";\n const suffix = this.textSuffix(text, grounding) ?? \"\";\n const body = this.annotateTextSegments(text, grounding);\n return `${prefix}${body}${suffix}`;\n }\n\n async parseResult(\n generations: Generations,\n _callbacks?: Callbacks\n ): Promise<string> {\n const text = this.generationsToString(generations);\n\n const grounding = this.generationsToGroundingInfo(generations);\n if (!grounding) {\n return text;\n }\n\n return this.annotateText(text, grounding);\n }\n}\n\nexport class SimpleGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {\n protected segmentPrefix(\n _grounding: GroundingInfo,\n _support: GeminiGroundingSupport,\n _index: number\n ): string | undefined {\n return undefined;\n }\n\n protected segmentSuffix(\n _grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n _index: number\n ): string | undefined {\n const indices: number[] = support.groundingChunkIndices.map((i) => i + 1);\n return ` [${indices.join(\", \")}]`;\n }\n\n protected textPrefix(_text: string, _grounding: GroundingInfo): string {\n return \"Google Says:\\n\";\n }\n\n protected chunkToString(chunk: GeminiGroundingChunk, index: number): string {\n const info = chunk.retrievedContext ?? chunk.web;\n return `${index + 1}. ${info.title} - ${info.uri}`;\n }\n\n protected textSuffix(_text: string, grounding: GroundingInfo): string {\n let ret = \"\\n\";\n const chunks: GeminiGroundingChunk[] =\n grounding?.metadata?.groundingChunks ?? [];\n chunks.forEach((chunk, index) => {\n ret = `${ret}${this.chunkToString(chunk, index)}\\n`;\n });\n return ret;\n }\n}\n\nexport class MarkdownGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {\n protected segmentPrefix(\n _grounding: GroundingInfo,\n _support: GeminiGroundingSupport,\n _index: number\n ): string | undefined {\n return undefined;\n }\n\n protected chunkLink(grounding: GroundingInfo, index: number): string {\n const chunk = grounding.metadata.groundingChunks[index];\n const url = chunk.retrievedContext?.uri ?? chunk.web?.uri;\n const num = index + 1;\n return `[[${num}](${url})]`;\n }\n\n protected segmentSuffix(\n grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n _index: number\n ): string | undefined {\n let ret = \"\";\n support.groundingChunkIndices.forEach((chunkIndex) => {\n const link = this.chunkLink(grounding, chunkIndex);\n ret = `${ret}${link}`;\n });\n return ret;\n }\n\n protected textPrefix(\n _text: string,\n _grounding: GroundingInfo\n ): string | undefined {\n return undefined;\n }\n\n protected chunkSuffixLink(\n chunk: GeminiGroundingChunk,\n index: number\n ): string {\n const num = index + 1;\n const info = chunk.retrievedContext ?? chunk.web;\n const url = info.uri;\n const site = info.title;\n return `${num}. [${site}](${url})`;\n }\n\n protected textSuffix(\n _text: string,\n grounding: GroundingInfo\n ): string | undefined {\n let ret = \"\\n**Search Sources**\\n\";\n const chunks: GeminiGroundingChunk[] = grounding.metadata.groundingChunks;\n chunks.forEach((chunk, index) => {\n ret = `${ret}${this.chunkSuffixLink(chunk, index)}\\n`;\n });\n\n const search = this.searchSuggestion(grounding);\n ret = `${ret}\\n${search}`;\n\n return ret;\n }\n}\n"],"mappings":";;;;AAiBA,IAAsB,+BAAtB,cAA2DA,oDAA4B;CACrF,eAAyB,CAAC,iBAAiB,gBAAiB;CAE5D,AAAU,0BACRC,YAC2B;AAC3B,MAAI,aAAa,YAAY;GAC3B,MAAM,mBAAmB,YAAY,SAAS;GAC9C,MAAM,WAAW,kBAAkB;GACnC,MAAM,WACJ,kBAAkB,oBAAoB,UAAU,qBAAqB,CAAE;AACzE,OAAI,SACF,QAAO;IACL;IACA;GACD;EAEJ;AACD,SAAO;CACR;CAED,AAAU,2BACRC,aAC2B;AAC3B,OAAK,MAAM,cAAc,aAAa;GACpC,MAAM,OAAO,KAAK,0BAA0B,WAAW;AACvD,OAAI,SAAS,OACX,QAAO;EAEV;AACD,SAAO;CACR;CAED,AAAU,mBACRD,YACQ;AACR,MAAI,aAAa,YAAY;GAC3B,MAAME,UAA0B,YAAY,SAAS;AACrD,OAAI,OAAO,YAAY,SACrB,QAAO;OAEP,QAAO,QACJ,IAAI,CAAC,MAAM;AACV,QAAI,GAAG,SAAS,OACd,QAAO,GAAG,QAAQ;QAElB,QAAO;GAEV,EAAC,CACD,OACC,CAAC,eAAe,iBAAiB,GAAG,gBAAgB,cAAc,CACnE;EAEN;AACD,SAAO,WAAW;CACnB;CAED,AAA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;CACR;CAED,AAAU,WACRE,OACAJ,YACoB;AACpB,SAAO;CACR;CAED,AAAU,gBACRK,OACAP,OACQ;EACR,MAAM,MAAM,QAAQ;EACpB,MAAM,OAAO,MAAM,oBAAoB,MAAM;EAC7C,MAAM,MAAM,KAAK;EACjB,MAAM,OAAO,KAAK;AAClB,SAAO,GAAG,IAAI,GAAG,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;CACnC;CAED,AAAU,WACRM,OACAR,WACoB;EACpB,IAAI,MAAM;EACV,MAAMU,SAAiC,UAAU,SAAS;EAC1D,OAAO,QAAQ,CAAC,OAAO,UAAU;GAC/B,MAAM,GAAG,MAAM,KAAK,gBAAgB,OAAO,MAAM,CAAC,EAAE,CAAC;EACtD,EAAC;EAEF,MAAM,SAAS,KAAK,iBAAiB,UAAU;EAC/C,MAAM,GAAG,IAAI,EAAE,EAAE,QAAQ;AAEzB,SAAO;CACR;AACF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { GeminiGroundingChunk, GeminiGroundingMetadata, GeminiGroundingSupport } from "./types.cjs";
|
|
2
|
+
import { ChatGeneration, Generation } from "@langchain/core/outputs";
|
|
3
|
+
import { Callbacks } from "@langchain/core/callbacks/manager";
|
|
4
|
+
import { BaseLLMOutputParser } from "@langchain/core/output_parsers";
|
|
5
|
+
|
|
6
|
+
//#region src/output_parsers.d.ts
|
|
7
|
+
type Generations = Generation[] | ChatGeneration[];
|
|
8
|
+
type GroundingInfo = {
|
|
9
|
+
metadata: GeminiGroundingMetadata;
|
|
10
|
+
supports: GeminiGroundingSupport[];
|
|
11
|
+
};
|
|
12
|
+
declare abstract class BaseGoogleSearchOutputParser extends BaseLLMOutputParser<string> {
|
|
13
|
+
lc_namespace: string[];
|
|
14
|
+
protected generationToGroundingInfo(generation: Generation | ChatGeneration): GroundingInfo | undefined;
|
|
15
|
+
protected generationsToGroundingInfo(generations: Generations): GroundingInfo | undefined;
|
|
16
|
+
protected generationToString(generation: Generation | ChatGeneration): string;
|
|
17
|
+
protected generationsToString(generations: Generations): string;
|
|
18
|
+
protected abstract segmentPrefix(grounding: GroundingInfo, support: GeminiGroundingSupport, index: number): string | undefined;
|
|
19
|
+
protected abstract segmentSuffix(grounding: GroundingInfo, support: GeminiGroundingSupport, index: number): string | undefined;
|
|
20
|
+
protected annotateSegment(text: string, grounding: GroundingInfo, support: GeminiGroundingSupport, index: number): string;
|
|
21
|
+
protected annotateTextSegments(text: string, grounding: GroundingInfo): string;
|
|
22
|
+
protected abstract textPrefix(text: string, grounding: GroundingInfo): string | undefined;
|
|
23
|
+
protected abstract textSuffix(text: string, grounding: GroundingInfo): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Google requires us to
|
|
26
|
+
* "Display the Search Suggestion exactly as provided without any modifications"
|
|
27
|
+
* So this will typically be called from the textSuffix() method to get
|
|
28
|
+
* a string that renders HTML.
|
|
29
|
+
* See https://ai.google.dev/gemini-api/docs/grounding/search-suggestions
|
|
30
|
+
* @param grounding
|
|
31
|
+
*/
|
|
32
|
+
protected searchSuggestion(grounding: GroundingInfo): string;
|
|
33
|
+
protected annotateText(text: string, grounding: GroundingInfo): string;
|
|
34
|
+
parseResult(generations: Generations, _callbacks?: Callbacks): Promise<string>;
|
|
35
|
+
}
|
|
36
|
+
declare class SimpleGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {
|
|
37
|
+
protected segmentPrefix(_grounding: GroundingInfo, _support: GeminiGroundingSupport, _index: number): string | undefined;
|
|
38
|
+
protected segmentSuffix(_grounding: GroundingInfo, support: GeminiGroundingSupport, _index: number): string | undefined;
|
|
39
|
+
protected textPrefix(_text: string, _grounding: GroundingInfo): string;
|
|
40
|
+
protected chunkToString(chunk: GeminiGroundingChunk, index: number): string;
|
|
41
|
+
protected textSuffix(_text: string, grounding: GroundingInfo): string;
|
|
42
|
+
}
|
|
43
|
+
declare class MarkdownGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {
|
|
44
|
+
protected segmentPrefix(_grounding: GroundingInfo, _support: GeminiGroundingSupport, _index: number): string | undefined;
|
|
45
|
+
protected chunkLink(grounding: GroundingInfo, index: number): string;
|
|
46
|
+
protected segmentSuffix(grounding: GroundingInfo, support: GeminiGroundingSupport, _index: number): string | undefined;
|
|
47
|
+
protected textPrefix(_text: string, _grounding: GroundingInfo): string | undefined;
|
|
48
|
+
protected chunkSuffixLink(chunk: GeminiGroundingChunk, index: number): string;
|
|
49
|
+
protected textSuffix(_text: string, grounding: GroundingInfo): string | undefined;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { BaseGoogleSearchOutputParser, MarkdownGoogleSearchOutputParser, SimpleGoogleSearchOutputParser };
|
|
53
|
+
//# sourceMappingURL=output_parsers.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output_parsers.d.cts","names":["BaseLLMOutputParser","Callbacks","ChatGeneration","Generation","GeminiGroundingChunk","GeminiGroundingMetadata","GeminiGroundingSupport","Generations","GroundingInfo","BaseGoogleSearchOutputParser","Promise","SimpleGoogleSearchOutputParser","MarkdownGoogleSearchOutputParser"],"sources":["../src/output_parsers.d.ts"],"sourcesContent":["import { BaseLLMOutputParser } from \"@langchain/core/output_parsers\";\nimport { Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { ChatGeneration, Generation } from \"@langchain/core/outputs\";\nimport { GeminiGroundingChunk, GeminiGroundingMetadata, GeminiGroundingSupport } from \"./types.js\";\ntype Generations = Generation[] | ChatGeneration[];\ntype GroundingInfo = {\n metadata: GeminiGroundingMetadata;\n supports: GeminiGroundingSupport[];\n};\nexport declare abstract class BaseGoogleSearchOutputParser extends BaseLLMOutputParser<string> {\n lc_namespace: string[];\n protected generationToGroundingInfo(generation: Generation | ChatGeneration): GroundingInfo | undefined;\n protected generationsToGroundingInfo(generations: Generations): GroundingInfo | undefined;\n protected generationToString(generation: Generation | ChatGeneration): string;\n protected generationsToString(generations: Generations): string;\n protected abstract segmentPrefix(grounding: GroundingInfo, support: GeminiGroundingSupport, index: number): string | undefined;\n protected abstract segmentSuffix(grounding: GroundingInfo, support: GeminiGroundingSupport, index: number): string | undefined;\n protected annotateSegment(text: string, grounding: GroundingInfo, support: GeminiGroundingSupport, index: number): string;\n protected annotateTextSegments(text: string, grounding: GroundingInfo): string;\n protected abstract textPrefix(text: string, grounding: GroundingInfo): string | undefined;\n protected abstract textSuffix(text: string, grounding: GroundingInfo): string | undefined;\n /**\n * Google requires us to\n * \"Display the Search Suggestion exactly as provided without any modifications\"\n * So this will typically be called from the textSuffix() method to get\n * a string that renders HTML.\n * See https://ai.google.dev/gemini-api/docs/grounding/search-suggestions\n * @param grounding\n */\n protected searchSuggestion(grounding: GroundingInfo): string;\n protected annotateText(text: string, grounding: GroundingInfo): string;\n parseResult(generations: Generations, _callbacks?: Callbacks): Promise<string>;\n}\nexport declare class SimpleGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {\n protected segmentPrefix(_grounding: GroundingInfo, _support: GeminiGroundingSupport, _index: number): string | undefined;\n protected segmentSuffix(_grounding: GroundingInfo, support: GeminiGroundingSupport, _index: number): string | undefined;\n protected textPrefix(_text: string, _grounding: GroundingInfo): string;\n protected chunkToString(chunk: GeminiGroundingChunk, index: number): string;\n protected textSuffix(_text: string, grounding: GroundingInfo): string;\n}\nexport declare class MarkdownGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {\n protected segmentPrefix(_grounding: GroundingInfo, _support: GeminiGroundingSupport, _index: number): string | undefined;\n protected chunkLink(grounding: GroundingInfo, index: number): string;\n protected segmentSuffix(grounding: GroundingInfo, support: GeminiGroundingSupport, _index: number): string | undefined;\n protected textPrefix(_text: string, _grounding: GroundingInfo): string | undefined;\n protected chunkSuffixLink(chunk: GeminiGroundingChunk, index: number): string;\n protected textSuffix(_text: string, grounding: GroundingInfo): string | undefined;\n}\nexport {};\n"],"mappings":";;;;;;KAIKO,WAAAA,GAAcJ,eAAeD;KAC7BM,aAAAA;EADAD,QAAAA,EAESF,u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,CAAA,SAAA,EAUZA,aAVY,EAAA,OAAA,EAUYF,sBAVZ,EAAA,MAAA,EAAA,MAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAA,UACXE,UAAAA,CAAAA,KAAAA,EAAAA,MAAAA,EAAAA,UAAAA,EAUYA,aAVZA,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EAAa,UAAYF,eAAAA,CAAAA,KAAAA,EAW5BF,oBAX4BE,EAAAA,KAAAA,EAAAA,MAAAA,CAAAA,EAAAA,MAAAA;EAAsB,UAC/CE,UAAAA,CAAAA,KAAAA,EAAAA,MAAAA,EAAAA,SAAAA,EAWWA,aAXXA,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA"}
|
package/dist/output_parsers.d.ts
CHANGED
|
@@ -1,49 +1,53 @@
|
|
|
1
|
-
import { BaseLLMOutputParser } from "@langchain/core/output_parsers";
|
|
2
|
-
import { Callbacks } from "@langchain/core/callbacks/manager";
|
|
3
|
-
import { ChatGeneration, Generation } from "@langchain/core/outputs";
|
|
4
1
|
import { GeminiGroundingChunk, GeminiGroundingMetadata, GeminiGroundingSupport } from "./types.js";
|
|
2
|
+
import { ChatGeneration, Generation } from "@langchain/core/outputs";
|
|
3
|
+
import { Callbacks } from "@langchain/core/callbacks/manager";
|
|
4
|
+
import { BaseLLMOutputParser } from "@langchain/core/output_parsers";
|
|
5
|
+
|
|
6
|
+
//#region src/output_parsers.d.ts
|
|
5
7
|
type Generations = Generation[] | ChatGeneration[];
|
|
6
8
|
type GroundingInfo = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
metadata: GeminiGroundingMetadata;
|
|
10
|
+
supports: GeminiGroundingSupport[];
|
|
9
11
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
12
|
+
declare abstract class BaseGoogleSearchOutputParser extends BaseLLMOutputParser<string> {
|
|
13
|
+
lc_namespace: string[];
|
|
14
|
+
protected generationToGroundingInfo(generation: Generation | ChatGeneration): GroundingInfo | undefined;
|
|
15
|
+
protected generationsToGroundingInfo(generations: Generations): GroundingInfo | undefined;
|
|
16
|
+
protected generationToString(generation: Generation | ChatGeneration): string;
|
|
17
|
+
protected generationsToString(generations: Generations): string;
|
|
18
|
+
protected abstract segmentPrefix(grounding: GroundingInfo, support: GeminiGroundingSupport, index: number): string | undefined;
|
|
19
|
+
protected abstract segmentSuffix(grounding: GroundingInfo, support: GeminiGroundingSupport, index: number): string | undefined;
|
|
20
|
+
protected annotateSegment(text: string, grounding: GroundingInfo, support: GeminiGroundingSupport, index: number): string;
|
|
21
|
+
protected annotateTextSegments(text: string, grounding: GroundingInfo): string;
|
|
22
|
+
protected abstract textPrefix(text: string, grounding: GroundingInfo): string | undefined;
|
|
23
|
+
protected abstract textSuffix(text: string, grounding: GroundingInfo): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Google requires us to
|
|
26
|
+
* "Display the Search Suggestion exactly as provided without any modifications"
|
|
27
|
+
* So this will typically be called from the textSuffix() method to get
|
|
28
|
+
* a string that renders HTML.
|
|
29
|
+
* See https://ai.google.dev/gemini-api/docs/grounding/search-suggestions
|
|
30
|
+
* @param grounding
|
|
31
|
+
*/
|
|
32
|
+
protected searchSuggestion(grounding: GroundingInfo): string;
|
|
33
|
+
protected annotateText(text: string, grounding: GroundingInfo): string;
|
|
34
|
+
parseResult(generations: Generations, _callbacks?: Callbacks): Promise<string>;
|
|
33
35
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
declare class SimpleGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {
|
|
37
|
+
protected segmentPrefix(_grounding: GroundingInfo, _support: GeminiGroundingSupport, _index: number): string | undefined;
|
|
38
|
+
protected segmentSuffix(_grounding: GroundingInfo, support: GeminiGroundingSupport, _index: number): string | undefined;
|
|
39
|
+
protected textPrefix(_text: string, _grounding: GroundingInfo): string;
|
|
40
|
+
protected chunkToString(chunk: GeminiGroundingChunk, index: number): string;
|
|
41
|
+
protected textSuffix(_text: string, grounding: GroundingInfo): string;
|
|
40
42
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
declare class MarkdownGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {
|
|
44
|
+
protected segmentPrefix(_grounding: GroundingInfo, _support: GeminiGroundingSupport, _index: number): string | undefined;
|
|
45
|
+
protected chunkLink(grounding: GroundingInfo, index: number): string;
|
|
46
|
+
protected segmentSuffix(grounding: GroundingInfo, support: GeminiGroundingSupport, _index: number): string | undefined;
|
|
47
|
+
protected textPrefix(_text: string, _grounding: GroundingInfo): string | undefined;
|
|
48
|
+
protected chunkSuffixLink(chunk: GeminiGroundingChunk, index: number): string;
|
|
49
|
+
protected textSuffix(_text: string, grounding: GroundingInfo): string | undefined;
|
|
48
50
|
}
|
|
49
|
-
|
|
51
|
+
//#endregion
|
|
52
|
+
export { BaseGoogleSearchOutputParser, MarkdownGoogleSearchOutputParser, SimpleGoogleSearchOutputParser };
|
|
53
|
+
//# sourceMappingURL=output_parsers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output_parsers.d.ts","names":["BaseLLMOutputParser","Callbacks","ChatGeneration","Generation","GeminiGroundingChunk","GeminiGroundingMetadata","GeminiGroundingSupport","Generations","GroundingInfo","BaseGoogleSearchOutputParser","Promise","SimpleGoogleSearchOutputParser","MarkdownGoogleSearchOutputParser"],"sources":["../src/output_parsers.d.ts"],"sourcesContent":["import { BaseLLMOutputParser } from \"@langchain/core/output_parsers\";\nimport { Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { ChatGeneration, Generation } from \"@langchain/core/outputs\";\nimport { GeminiGroundingChunk, GeminiGroundingMetadata, GeminiGroundingSupport } from \"./types.js\";\ntype Generations = Generation[] | ChatGeneration[];\ntype GroundingInfo = {\n metadata: GeminiGroundingMetadata;\n supports: GeminiGroundingSupport[];\n};\nexport declare abstract class BaseGoogleSearchOutputParser extends BaseLLMOutputParser<string> {\n lc_namespace: string[];\n protected generationToGroundingInfo(generation: Generation | ChatGeneration): GroundingInfo | undefined;\n protected generationsToGroundingInfo(generations: Generations): GroundingInfo | undefined;\n protected generationToString(generation: Generation | ChatGeneration): string;\n protected generationsToString(generations: Generations): string;\n protected abstract segmentPrefix(grounding: GroundingInfo, support: GeminiGroundingSupport, index: number): string | undefined;\n protected abstract segmentSuffix(grounding: GroundingInfo, support: GeminiGroundingSupport, index: number): string | undefined;\n protected annotateSegment(text: string, grounding: GroundingInfo, support: GeminiGroundingSupport, index: number): string;\n protected annotateTextSegments(text: string, grounding: GroundingInfo): string;\n protected abstract textPrefix(text: string, grounding: GroundingInfo): string | undefined;\n protected abstract textSuffix(text: string, grounding: GroundingInfo): string | undefined;\n /**\n * Google requires us to\n * \"Display the Search Suggestion exactly as provided without any modifications\"\n * So this will typically be called from the textSuffix() method to get\n * a string that renders HTML.\n * See https://ai.google.dev/gemini-api/docs/grounding/search-suggestions\n * @param grounding\n */\n protected searchSuggestion(grounding: GroundingInfo): string;\n protected annotateText(text: string, grounding: GroundingInfo): string;\n parseResult(generations: Generations, _callbacks?: Callbacks): Promise<string>;\n}\nexport declare class SimpleGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {\n protected segmentPrefix(_grounding: GroundingInfo, _support: GeminiGroundingSupport, _index: number): string | undefined;\n protected segmentSuffix(_grounding: GroundingInfo, support: GeminiGroundingSupport, _index: number): string | undefined;\n protected textPrefix(_text: string, _grounding: GroundingInfo): string;\n protected chunkToString(chunk: GeminiGroundingChunk, index: number): string;\n protected textSuffix(_text: string, grounding: GroundingInfo): string;\n}\nexport declare class MarkdownGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {\n protected segmentPrefix(_grounding: GroundingInfo, _support: GeminiGroundingSupport, _index: number): string | undefined;\n protected chunkLink(grounding: GroundingInfo, index: number): string;\n protected segmentSuffix(grounding: GroundingInfo, support: GeminiGroundingSupport, _index: number): string | undefined;\n protected textPrefix(_text: string, _grounding: GroundingInfo): string | undefined;\n protected chunkSuffixLink(chunk: GeminiGroundingChunk, index: number): string;\n protected textSuffix(_text: string, grounding: GroundingInfo): string | undefined;\n}\nexport {};\n"],"mappings":";;;;;;KAIKO,WAAAA,GAAcJ,eAAeD;KAC7BM,aAAAA;EADAD,QAAAA,EAESF,uBAFE;EAAA,QAAA,EAGFC,sBAHE,EAAA;CAAA;AAAkBJ,uBAKJO,4BAAAA,SAAqCT,mBALjCE,CAAAA,MAAAA,CAAAA,CAAAA;EAAc,YAAA,EAAA,MAAA,EAAA;EAC3CM,UAAAA,yBAAa,CAAA,UAAA,EAMkCL,UANlC,GAM+CD,cAN/C,CAAA,EAMgEM,aANhE,GAAA,SAAA;EAAA,UAAA,0BAAA,CAAA,WAAA,EAOoCD,WAPpC,CAAA,EAOkDC,aAPlD,GAAA,SAAA;EAAA,UACJH,kBAAAA,CAAAA,UAAAA,EAO+BF,UAP/BE,GAO4CH,cAP5CG,CAAAA,EAAAA,MAAAA;EAAuB,UACvBC,mBAAAA,CAAAA,WAAAA,EAOiCC,WAPjCD,CAAAA,EAAAA,MAAAA;EAAsB,mBAAA,aAAA,CAAA,SAAA,EAQYE,aARZ,EAAA,OAAA,EAQoCF,sBARpC,EAAA,KAAA,EAAA,MAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAENG,mBAAAA,aAA4B,CAAA,SAAA,EAOVD,aAPU,EAAA,OAAA,EAOcF,sBAPd,EAAA,KAAA,EAAA,MAAA,CAAA,EAAA,MAAA,GAA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