-
Notifications
You must be signed in to change notification settings - Fork 337
/
types.ts
115 lines (96 loc) · 3.29 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
import {
GenerativeModel as GoogleGenerativeModel,
type EnhancedGenerateContentResponse,
type Content as GeminiMessageContent,
type FileDataPart as GoogleFileDataPart,
type InlineDataPart as GoogleInlineFileDataPart,
type ModelParams as GoogleModelParams,
type Part as GooglePart,
type GenerateContentStreamResult as GoogleStreamGenerateContentResult,
} from "@google/generative-ai";
import {
GenerativeModel as VertexGenerativeModel,
GenerativeModelPreview as VertexGenerativeModelPreview,
type GenerateContentResponse,
type FileDataPart as VertexFileDataPart,
type VertexInit,
type InlineDataPart as VertexInlineFileDataPart,
type ModelParams as VertexModelParams,
type Part as VertexPart,
type StreamGenerateContentResult as VertexStreamGenerateContentResult,
} from "@google-cloud/vertexai";
import type {
ChatResponse,
ChatResponseChunk,
CompletionResponse,
LLMChatParamsNonStreaming,
LLMChatParamsStreaming,
ToolCallLLMMessageOptions,
} from "../types.js";
export enum GEMINI_BACKENDS {
GOOGLE = "google",
VERTEX = "vertex",
}
export type GoogleGeminiSessionOptions = {
apiKey?: string;
};
export type VertexGeminiSessionOptions = {
preview?: boolean;
} & VertexInit;
export type GeminiSessionOptions =
| (GoogleGeminiSessionOptions & { backend: GEMINI_BACKENDS.GOOGLE })
| (VertexGeminiSessionOptions & { backend: GEMINI_BACKENDS.VERTEX });
export enum GEMINI_MODEL {
GEMINI_PRO = "gemini-pro",
GEMINI_PRO_VISION = "gemini-pro-vision",
GEMINI_PRO_LATEST = "gemini-1.5-pro-latest",
GEMINI_PRO_1_5_PRO_PREVIEW = "gemini-1.5-pro-preview-0514",
GEMINI_PRO_1_5_FLASH_PREVIEW = "gemini-1.5-flash-preview-0514",
GEMINI_PRO_1_5 = "gemini-1.5-pro-001",
GEMINI_PRO_1_5_FLASH = "gemini-1.5-flash-001",
}
export interface GeminiModelInfo {
contextWindow: number;
}
export type Part = GooglePart | VertexPart;
export type FileDataPart = GoogleFileDataPart | VertexFileDataPart;
export type InlineDataPart =
| GoogleInlineFileDataPart
| VertexInlineFileDataPart;
export type ModelParams = GoogleModelParams | VertexModelParams;
export type GenerativeModel =
| VertexGenerativeModelPreview
| VertexGenerativeModel
| GoogleGenerativeModel;
export type ChatContext = { message: Part[]; history: GeminiMessageContent[] };
export type GeminiMessageRole = "user" | "model";
export type GeminiAdditionalChatOptions = {};
export type GeminiChatParamsStreaming = LLMChatParamsStreaming<
GeminiAdditionalChatOptions,
ToolCallLLMMessageOptions
>;
export type GeminiChatStreamResponse = AsyncIterable<
ChatResponseChunk<ToolCallLLMMessageOptions>
>;
export type GeminiChatParamsNonStreaming = LLMChatParamsNonStreaming<
GeminiAdditionalChatOptions,
ToolCallLLMMessageOptions
>;
export type GeminiChatNonStreamResponse =
ChatResponse<ToolCallLLMMessageOptions>;
export interface IGeminiSession {
getGenerativeModel(metadata: ModelParams): GenerativeModel;
getResponseText(
response: EnhancedGenerateContentResponse | GenerateContentResponse,
): string;
getCompletionStream(
result:
| GoogleStreamGenerateContentResult
| VertexStreamGenerateContentResult,
): AsyncIterable<CompletionResponse>;
getChatStream(
result:
| GoogleStreamGenerateContentResult
| VertexStreamGenerateContentResult,
): GeminiChatStreamResponse;
}