-
Notifications
You must be signed in to change notification settings - Fork 2k
/
types.ts
199 lines (162 loc) Β· 4.63 KB
/
types.ts
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import type { BaseLLMParams } from "@langchain/core/language_models/llms";
import type { JsonStream } from "./utils/stream.js";
/**
* Parameters needed to setup the client connection.
* AuthOptions are something like GoogleAuthOptions (from google-auth-library)
* or WebGoogleAuthOptions.
*/
export interface GoogleClientParams<AuthOptions> {
authOptions?: AuthOptions;
/** Some APIs allow an API key instead */
apiKey?: string;
}
/**
* What platform is this running on?
* gai - Google AI Studio / MakerSuite / Generative AI platform
* gcp - Google Cloud Platform
*/
export type GooglePlatformType = "gai" | "gcp";
export interface GoogleConnectionParams<AuthOptions>
extends GoogleClientParams<AuthOptions> {
/** Hostname for the API call (if this is running on GCP) */
endpoint?: string;
/** Region where the LLM is stored (if this is running on GCP) */
location?: string;
/** The version of the API functions. Part of the path. */
apiVersion?: string;
/**
* What platform to run the service on.
* If not specified, the class should determine this from other
* means. Either way, the platform actually used will be in
* the "platform" getter.
*/
platformType?: GooglePlatformType;
}
export interface GoogleAISafetySetting {
category: string;
threshold: string;
}
export interface GoogleAIModelParams {
/** Model to use */
model?: string;
/** Sampling temperature to use */
temperature?: number;
/**
* Maximum number of tokens to generate in the completion.
*/
maxOutputTokens?: number;
/**
* Top-p changes how the model selects tokens for output.
*
* Tokens are selected from most probable to least until the sum
* of their probabilities equals the top-p value.
*
* For example, if tokens A, B, and C have a probability of
* .3, .2, and .1 and the top-p value is .5, then the model will
* select either A or B as the next token (using temperature).
*/
topP?: number;
/**
* Top-k changes how the model selects tokens for output.
*
* A top-k of 1 means the selected token is the most probable among
* all tokens in the modelβs vocabulary (also called greedy decoding),
* while a top-k of 3 means that the next token is selected from
* among the 3 most probable tokens (using temperature).
*/
topK?: number;
stopSequences?: string[];
safetySettings?: GoogleAISafetySetting[];
}
export interface GoogleAIBaseLLMInput<AuthOptions>
extends BaseLLMParams,
GoogleConnectionParams<AuthOptions>,
GoogleAIModelParams {}
export interface GoogleResponse {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data: any;
}
export interface GeminiPartText {
text: string;
}
export interface GeminiPartInlineData {
mimeType: string;
data: string;
}
// Vertex AI only
export interface GeminiPartFileData {
mimeType: string;
fileUri: string;
}
// AI Studio only?
export interface GeminiPartFunctionCall {
name: string;
args?: object;
}
// AI Studio Only?
export interface GeminiPartFunctionResponse {
name: string;
response: object;
}
export type GeminiPart =
| GeminiPartText
| GeminiPartInlineData
| GeminiPartFileData
| GeminiPartFunctionCall
| GeminiPartFunctionResponse;
export interface GeminiSafetySetting {
category: string;
threshold: string;
}
export interface GeminiSafetyRating {
category: string;
probability: string;
}
export type GeminiRole = "user" | "model";
// Vertex AI requires the role
export interface GeminiContent {
parts: GeminiPart[];
role: GeminiRole; // Vertex AI requires the role
}
export interface GeminiTool {
// TODO: Implement
}
export interface GeminiGenerationConfig {
stopSequences?: string[];
candidateCount?: number;
maxOutputTokens?: number;
temperature?: number;
topP?: number;
topK?: number;
}
export interface GeminiRequest {
contents?: GeminiContent[];
tools?: GeminiTool[];
safetySettings?: GeminiSafetySetting[];
generationConfig?: GeminiGenerationConfig;
}
interface GeminiResponseCandidate {
content: {
parts: GeminiPart[];
role: string;
};
finishReason: string;
index: number;
tokenCount?: number;
safetyRatings: GeminiSafetyRating[];
}
interface GeminiResponsePromptFeedback {
safetyRatings: GeminiSafetyRating[];
}
export interface GenerateContentResponseData {
candidates: GeminiResponseCandidate[];
promptFeedback: GeminiResponsePromptFeedback;
}
export type GoogleLLMModelFamily = null | "palm" | "gemini";
export type GoogleLLMResponseData =
| JsonStream
| GenerateContentResponseData
| GenerateContentResponseData[];
export interface GoogleLLMResponse extends GoogleResponse {
data: GoogleLLMResponseData;
}