langchain 0.0.182 → 0.0.183
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.
|
@@ -88,7 +88,25 @@ class ChatGooglePaLM extends base_js_1.BaseChatModel {
|
|
|
88
88
|
if (this.topK && this.topK < 0) {
|
|
89
89
|
throw new Error("`topK` must be a positive integer");
|
|
90
90
|
}
|
|
91
|
-
this.examples =
|
|
91
|
+
this.examples =
|
|
92
|
+
fields?.examples?.map((example) => {
|
|
93
|
+
if (((0, index_js_1.isBaseMessage)(example.input) &&
|
|
94
|
+
typeof example.input.content !== "string") ||
|
|
95
|
+
((0, index_js_1.isBaseMessage)(example.output) &&
|
|
96
|
+
typeof example.output.content !== "string")) {
|
|
97
|
+
throw new Error("GooglePaLM example messages may only have string content.");
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
input: {
|
|
101
|
+
...example.input,
|
|
102
|
+
content: example.input?.content,
|
|
103
|
+
},
|
|
104
|
+
output: {
|
|
105
|
+
...example.output,
|
|
106
|
+
content: example.output?.content,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}) ?? this.examples;
|
|
92
110
|
this.apiKey =
|
|
93
111
|
fields?.apiKey ?? (0, env_js_1.getEnvironmentVariable)("GOOGLE_PALM_API_KEY");
|
|
94
112
|
if (!this.apiKey) {
|
|
@@ -2,6 +2,10 @@ import type { protos } from "@google-ai/generativelanguage";
|
|
|
2
2
|
import { CallbackManagerForLLMRun } from "../callbacks/manager.js";
|
|
3
3
|
import { BaseMessage, ChatResult } from "../schema/index.js";
|
|
4
4
|
import { BaseChatModel, BaseChatModelParams } from "./base.js";
|
|
5
|
+
export type BaseMessageExamplePair = {
|
|
6
|
+
input: BaseMessage;
|
|
7
|
+
output: BaseMessage;
|
|
8
|
+
};
|
|
5
9
|
/**
|
|
6
10
|
* An interface defining the input to the ChatGooglePaLM class.
|
|
7
11
|
*/
|
|
@@ -47,7 +51,7 @@ export interface GooglePaLMChatInput extends BaseChatModelParams {
|
|
|
47
51
|
* Note: The default value varies by model
|
|
48
52
|
*/
|
|
49
53
|
topK?: number;
|
|
50
|
-
examples?: protos.google.ai.generativelanguage.v1beta2.IExample[];
|
|
54
|
+
examples?: protos.google.ai.generativelanguage.v1beta2.IExample[] | BaseMessageExamplePair[];
|
|
51
55
|
/**
|
|
52
56
|
* Google Palm API key to use
|
|
53
57
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DiscussServiceClient } from "@google-ai/generativelanguage";
|
|
2
2
|
import { GoogleAuth } from "google-auth-library";
|
|
3
|
-
import { AIMessage, ChatMessage, } from "../schema/index.js";
|
|
3
|
+
import { AIMessage, ChatMessage, isBaseMessage, } from "../schema/index.js";
|
|
4
4
|
import { getEnvironmentVariable } from "../util/env.js";
|
|
5
5
|
import { BaseChatModel } from "./base.js";
|
|
6
6
|
function getMessageAuthor(message) {
|
|
@@ -85,7 +85,25 @@ export class ChatGooglePaLM extends BaseChatModel {
|
|
|
85
85
|
if (this.topK && this.topK < 0) {
|
|
86
86
|
throw new Error("`topK` must be a positive integer");
|
|
87
87
|
}
|
|
88
|
-
this.examples =
|
|
88
|
+
this.examples =
|
|
89
|
+
fields?.examples?.map((example) => {
|
|
90
|
+
if ((isBaseMessage(example.input) &&
|
|
91
|
+
typeof example.input.content !== "string") ||
|
|
92
|
+
(isBaseMessage(example.output) &&
|
|
93
|
+
typeof example.output.content !== "string")) {
|
|
94
|
+
throw new Error("GooglePaLM example messages may only have string content.");
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
input: {
|
|
98
|
+
...example.input,
|
|
99
|
+
content: example.input?.content,
|
|
100
|
+
},
|
|
101
|
+
output: {
|
|
102
|
+
...example.output,
|
|
103
|
+
content: example.output?.content,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}) ?? this.examples;
|
|
89
107
|
this.apiKey =
|
|
90
108
|
fields?.apiKey ?? getEnvironmentVariable("GOOGLE_PALM_API_KEY");
|
|
91
109
|
if (!this.apiKey) {
|