@mariozechner/pi-ai 0.5.10
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/README.md +231 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/models.d.ts +72 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.generated.d.ts +2890 -0
- package/dist/models.generated.d.ts.map +1 -0
- package/dist/models.generated.js +2889 -0
- package/dist/models.generated.js.map +1 -0
- package/dist/models.js +71 -0
- package/dist/models.js.map +1 -0
- package/dist/providers/anthropic.d.ts +23 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +312 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/google.d.ts +20 -0
- package/dist/providers/google.d.ts.map +1 -0
- package/dist/providers/google.js +337 -0
- package/dist/providers/google.js.map +1 -0
- package/dist/providers/openai-completions.d.ts +21 -0
- package/dist/providers/openai-completions.d.ts.map +1 -0
- package/dist/providers/openai-completions.js +304 -0
- package/dist/providers/openai-completions.js.map +1 -0
- package/dist/providers/openai-responses.d.ts +16 -0
- package/dist/providers/openai-responses.d.ts.map +1 -0
- package/dist/providers/openai-responses.js +261 -0
- package/dist/providers/openai-responses.js.map +1 -0
- package/dist/types.d.ts +119 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { FunctionCallingConfigMode, GoogleGenAI, } from "@google/genai";
|
|
2
|
+
import { calculateCost } from "../models.js";
|
|
3
|
+
export class GoogleLLM {
|
|
4
|
+
client;
|
|
5
|
+
model;
|
|
6
|
+
constructor(model, apiKey) {
|
|
7
|
+
if (!apiKey) {
|
|
8
|
+
if (!process.env.GEMINI_API_KEY) {
|
|
9
|
+
throw new Error("Gemini API key is required. Set GEMINI_API_KEY environment variable or pass it as an argument.");
|
|
10
|
+
}
|
|
11
|
+
apiKey = process.env.GEMINI_API_KEY;
|
|
12
|
+
}
|
|
13
|
+
this.client = new GoogleGenAI({ apiKey });
|
|
14
|
+
this.model = model;
|
|
15
|
+
}
|
|
16
|
+
getModel() {
|
|
17
|
+
return this.model;
|
|
18
|
+
}
|
|
19
|
+
async complete(context, options) {
|
|
20
|
+
try {
|
|
21
|
+
const contents = this.convertMessages(context.messages);
|
|
22
|
+
// Build generation config
|
|
23
|
+
const generationConfig = {};
|
|
24
|
+
if (options?.temperature !== undefined) {
|
|
25
|
+
generationConfig.temperature = options.temperature;
|
|
26
|
+
}
|
|
27
|
+
if (options?.maxTokens !== undefined) {
|
|
28
|
+
generationConfig.maxOutputTokens = options.maxTokens;
|
|
29
|
+
}
|
|
30
|
+
// Build the config object
|
|
31
|
+
const config = {
|
|
32
|
+
...(Object.keys(generationConfig).length > 0 && generationConfig),
|
|
33
|
+
...(context.systemPrompt && { systemInstruction: context.systemPrompt }),
|
|
34
|
+
...(context.tools && { tools: this.convertTools(context.tools) }),
|
|
35
|
+
};
|
|
36
|
+
// Add tool config if needed
|
|
37
|
+
if (context.tools && options?.toolChoice) {
|
|
38
|
+
config.toolConfig = {
|
|
39
|
+
functionCallingConfig: {
|
|
40
|
+
mode: this.mapToolChoice(options.toolChoice),
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// Add thinking config if enabled and model supports it
|
|
45
|
+
if (options?.thinking?.enabled && this.model.reasoning) {
|
|
46
|
+
config.thinkingConfig = {
|
|
47
|
+
includeThoughts: true,
|
|
48
|
+
...(options.thinking.budgetTokens !== undefined && { thinkingBudget: options.thinking.budgetTokens }),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// Build the request parameters
|
|
52
|
+
const params = {
|
|
53
|
+
model: this.model.id,
|
|
54
|
+
contents,
|
|
55
|
+
config,
|
|
56
|
+
};
|
|
57
|
+
const stream = await this.client.models.generateContentStream(params);
|
|
58
|
+
let content = "";
|
|
59
|
+
let thinking = "";
|
|
60
|
+
let thoughtSignature;
|
|
61
|
+
const toolCalls = [];
|
|
62
|
+
let usage = {
|
|
63
|
+
input: 0,
|
|
64
|
+
output: 0,
|
|
65
|
+
cacheRead: 0,
|
|
66
|
+
cacheWrite: 0,
|
|
67
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
68
|
+
};
|
|
69
|
+
let stopReason = "stop";
|
|
70
|
+
let inTextBlock = false;
|
|
71
|
+
let inThinkingBlock = false;
|
|
72
|
+
// Process the stream
|
|
73
|
+
for await (const chunk of stream) {
|
|
74
|
+
// Extract parts from the chunk
|
|
75
|
+
const candidate = chunk.candidates?.[0];
|
|
76
|
+
if (candidate?.content?.parts) {
|
|
77
|
+
for (const part of candidate.content.parts) {
|
|
78
|
+
// Cast to any to access thinking properties not yet in SDK types
|
|
79
|
+
const partWithThinking = part;
|
|
80
|
+
if (partWithThinking.text !== undefined) {
|
|
81
|
+
// Check if it's thinking content using the thought boolean flag
|
|
82
|
+
if (partWithThinking.thought === true) {
|
|
83
|
+
if (inTextBlock) {
|
|
84
|
+
options?.onText?.("", true);
|
|
85
|
+
inTextBlock = false;
|
|
86
|
+
}
|
|
87
|
+
thinking += partWithThinking.text;
|
|
88
|
+
options?.onThinking?.(partWithThinking.text, false);
|
|
89
|
+
inThinkingBlock = true;
|
|
90
|
+
// Capture thought signature if present
|
|
91
|
+
if (partWithThinking.thoughtSignature) {
|
|
92
|
+
thoughtSignature = partWithThinking.thoughtSignature;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
if (inThinkingBlock) {
|
|
97
|
+
options?.onThinking?.("", true);
|
|
98
|
+
inThinkingBlock = false;
|
|
99
|
+
}
|
|
100
|
+
content += partWithThinking.text;
|
|
101
|
+
options?.onText?.(partWithThinking.text, false);
|
|
102
|
+
inTextBlock = true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// Handle function calls
|
|
106
|
+
if (part.functionCall) {
|
|
107
|
+
if (inTextBlock) {
|
|
108
|
+
options?.onText?.("", true);
|
|
109
|
+
inTextBlock = false;
|
|
110
|
+
}
|
|
111
|
+
if (inThinkingBlock) {
|
|
112
|
+
options?.onThinking?.("", true);
|
|
113
|
+
inThinkingBlock = false;
|
|
114
|
+
}
|
|
115
|
+
// Gemini doesn't provide tool call IDs, so we need to generate them
|
|
116
|
+
// Use the function name as part of the ID for better debugging
|
|
117
|
+
const toolCallId = `${part.functionCall.name}_${Date.now()}`;
|
|
118
|
+
toolCalls.push({
|
|
119
|
+
id: toolCallId,
|
|
120
|
+
name: part.functionCall.name || "",
|
|
121
|
+
arguments: part.functionCall.args,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Map finish reason
|
|
127
|
+
if (candidate?.finishReason) {
|
|
128
|
+
stopReason = this.mapStopReason(candidate.finishReason);
|
|
129
|
+
if (toolCalls.length > 0) {
|
|
130
|
+
stopReason = "toolUse";
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// Capture usage metadata if available
|
|
134
|
+
if (chunk.usageMetadata) {
|
|
135
|
+
usage = {
|
|
136
|
+
input: chunk.usageMetadata.promptTokenCount || 0,
|
|
137
|
+
output: (chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),
|
|
138
|
+
cacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,
|
|
139
|
+
cacheWrite: 0,
|
|
140
|
+
cost: {
|
|
141
|
+
input: 0,
|
|
142
|
+
output: 0,
|
|
143
|
+
cacheRead: 0,
|
|
144
|
+
cacheWrite: 0,
|
|
145
|
+
total: 0,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// Signal end of blocks
|
|
151
|
+
if (inTextBlock) {
|
|
152
|
+
options?.onText?.("", true);
|
|
153
|
+
}
|
|
154
|
+
if (inThinkingBlock) {
|
|
155
|
+
options?.onThinking?.("", true);
|
|
156
|
+
}
|
|
157
|
+
// Generate a thinking signature if we have thinking content but no signature from API
|
|
158
|
+
// This is needed for proper multi-turn conversations with thinking
|
|
159
|
+
if (thinking && !thoughtSignature) {
|
|
160
|
+
// Create a base64-encoded signature as Gemini expects
|
|
161
|
+
// In production, Gemini API should provide this
|
|
162
|
+
const encoder = new TextEncoder();
|
|
163
|
+
const data = encoder.encode(thinking);
|
|
164
|
+
// Create a simple hash-like signature and encode to base64
|
|
165
|
+
const signature = `gemini_thinking_${data.length}_${Date.now()}`;
|
|
166
|
+
thoughtSignature = Buffer.from(signature).toString("base64");
|
|
167
|
+
}
|
|
168
|
+
// Calculate cost
|
|
169
|
+
calculateCost(this.model, usage);
|
|
170
|
+
// Usage metadata is in the last chunk
|
|
171
|
+
// Already captured during streaming
|
|
172
|
+
return {
|
|
173
|
+
role: "assistant",
|
|
174
|
+
content: content || undefined,
|
|
175
|
+
thinking: thinking || undefined,
|
|
176
|
+
thinkingSignature: thoughtSignature,
|
|
177
|
+
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
178
|
+
provider: this.model.provider,
|
|
179
|
+
model: this.model.id,
|
|
180
|
+
usage,
|
|
181
|
+
stopReason,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
return {
|
|
186
|
+
role: "assistant",
|
|
187
|
+
provider: this.model.provider,
|
|
188
|
+
model: this.model.id,
|
|
189
|
+
usage: {
|
|
190
|
+
input: 0,
|
|
191
|
+
output: 0,
|
|
192
|
+
cacheRead: 0,
|
|
193
|
+
cacheWrite: 0,
|
|
194
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
195
|
+
},
|
|
196
|
+
stopReason: "error",
|
|
197
|
+
error: error instanceof Error ? error.message : String(error),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
convertMessages(messages) {
|
|
202
|
+
const contents = [];
|
|
203
|
+
for (const msg of messages) {
|
|
204
|
+
if (msg.role === "user") {
|
|
205
|
+
// Handle both string and array content
|
|
206
|
+
if (typeof msg.content === "string") {
|
|
207
|
+
contents.push({
|
|
208
|
+
role: "user",
|
|
209
|
+
parts: [{ text: msg.content }],
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
// Convert array content to Google format
|
|
214
|
+
const parts = msg.content.map((item) => {
|
|
215
|
+
if (item.type === "text") {
|
|
216
|
+
return { text: item.text };
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
// Image content - Google uses inlineData
|
|
220
|
+
return {
|
|
221
|
+
inlineData: {
|
|
222
|
+
mimeType: item.mimeType,
|
|
223
|
+
data: item.data,
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
contents.push({
|
|
229
|
+
role: "user",
|
|
230
|
+
parts,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
else if (msg.role === "assistant") {
|
|
235
|
+
const parts = [];
|
|
236
|
+
// Add thinking if present
|
|
237
|
+
// Note: We include thinkingSignature in our response for multi-turn context,
|
|
238
|
+
// but don't send it back to Gemini API as it may cause errors
|
|
239
|
+
if (msg.thinking) {
|
|
240
|
+
parts.push({
|
|
241
|
+
text: msg.thinking,
|
|
242
|
+
thought: true,
|
|
243
|
+
// Don't include thoughtSignature when sending back to API
|
|
244
|
+
// thoughtSignature: msg.thinkingSignature,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
if (msg.content) {
|
|
248
|
+
parts.push({ text: msg.content });
|
|
249
|
+
}
|
|
250
|
+
if (msg.toolCalls) {
|
|
251
|
+
for (const toolCall of msg.toolCalls) {
|
|
252
|
+
parts.push({
|
|
253
|
+
functionCall: {
|
|
254
|
+
name: toolCall.name,
|
|
255
|
+
args: toolCall.arguments,
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (parts.length > 0) {
|
|
261
|
+
contents.push({
|
|
262
|
+
role: "model",
|
|
263
|
+
parts,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
else if (msg.role === "toolResult") {
|
|
268
|
+
// Tool results are sent as function responses
|
|
269
|
+
// Extract function name from the tool call ID (format: "functionName_timestamp")
|
|
270
|
+
const functionName = msg.toolCallId.substring(0, msg.toolCallId.lastIndexOf("_"));
|
|
271
|
+
contents.push({
|
|
272
|
+
role: "user",
|
|
273
|
+
parts: [
|
|
274
|
+
{
|
|
275
|
+
functionResponse: {
|
|
276
|
+
name: functionName,
|
|
277
|
+
response: {
|
|
278
|
+
result: msg.content,
|
|
279
|
+
isError: msg.isError || false,
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return contents;
|
|
288
|
+
}
|
|
289
|
+
convertTools(tools) {
|
|
290
|
+
return [
|
|
291
|
+
{
|
|
292
|
+
functionDeclarations: tools.map((tool) => ({
|
|
293
|
+
name: tool.name,
|
|
294
|
+
description: tool.description,
|
|
295
|
+
parameters: tool.parameters,
|
|
296
|
+
})),
|
|
297
|
+
},
|
|
298
|
+
];
|
|
299
|
+
}
|
|
300
|
+
mapToolChoice(choice) {
|
|
301
|
+
switch (choice) {
|
|
302
|
+
case "auto":
|
|
303
|
+
return FunctionCallingConfigMode.AUTO;
|
|
304
|
+
case "none":
|
|
305
|
+
return FunctionCallingConfigMode.NONE;
|
|
306
|
+
case "any":
|
|
307
|
+
return FunctionCallingConfigMode.ANY;
|
|
308
|
+
default:
|
|
309
|
+
return FunctionCallingConfigMode.AUTO;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
mapStopReason(reason) {
|
|
313
|
+
switch (reason) {
|
|
314
|
+
case "STOP":
|
|
315
|
+
return "stop";
|
|
316
|
+
case "MAX_TOKENS":
|
|
317
|
+
return "length";
|
|
318
|
+
case "BLOCKLIST":
|
|
319
|
+
case "PROHIBITED_CONTENT":
|
|
320
|
+
case "SPII":
|
|
321
|
+
case "SAFETY":
|
|
322
|
+
case "IMAGE_SAFETY":
|
|
323
|
+
return "safety";
|
|
324
|
+
case "RECITATION":
|
|
325
|
+
return "safety";
|
|
326
|
+
case "FINISH_REASON_UNSPECIFIED":
|
|
327
|
+
case "OTHER":
|
|
328
|
+
case "LANGUAGE":
|
|
329
|
+
case "MALFORMED_FUNCTION_CALL":
|
|
330
|
+
case "UNEXPECTED_TOOL_CALL":
|
|
331
|
+
return "error";
|
|
332
|
+
default:
|
|
333
|
+
return "stop";
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
//# sourceMappingURL=google.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google.js","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,yBAAyB,EAGzB,WAAW,GAEX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAsB7C,MAAM,OAAO,SAAS;IACb,MAAM,CAAc;IACpB,KAAK,CAAQ;IAErB,YAAY,KAAY,EAAE,MAAe;QACxC,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;gBACjC,MAAM,IAAI,KAAK,CACd,gGAAgG,CAChG,CAAC;YACH,CAAC;YACD,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;QACrC,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;IAED,QAAQ;QACP,OAAO,IA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QAAQ,CAAC;YACjB,KAAK,WAAW,CAAC;YACjB,KAAK,oBAAoB,CAAC;YAC1B,KAAK,MAAM,CAAC;YACZ,KAAK,QAAQ,CAAC;YACd,KAAK,cAAc;gBAClB,OAAO,QAAQ,CAAC;YACjB,KAAK,YAAY;gBAChB,OAAO,QAAQ,CAAC;YACjB,KAAK,2BAA2B,CAAC;YACjC,KAAK,OAAO,CAAC;YACb,KAAK,UAAU,CAAC;YAChB,KAAK,yBAAyB,CAAC;YAC/B,KAAK,sBAAsB;gBAC1B,OAAO,OAAO,CAAC;YAChB;gBACC,OAAO,MAAM,CAAC;QAChB,CAAC;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AssistantMessage, Context, LLM, LLMOptions, Model } from "../types.js";
|
|
2
|
+
export interface OpenAICompletionsLLMOptions extends LLMOptions {
|
|
3
|
+
toolChoice?: "auto" | "none" | "required" | {
|
|
4
|
+
type: "function";
|
|
5
|
+
function: {
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
reasoningEffort?: "low" | "medium" | "high";
|
|
10
|
+
}
|
|
11
|
+
export declare class OpenAICompletionsLLM implements LLM<OpenAICompletionsLLMOptions> {
|
|
12
|
+
private client;
|
|
13
|
+
private modelInfo;
|
|
14
|
+
constructor(model: Model, apiKey?: string);
|
|
15
|
+
getModel(): Model;
|
|
16
|
+
complete(request: Context, options?: OpenAICompletionsLLMOptions): Promise<AssistantMessage>;
|
|
17
|
+
private convertMessages;
|
|
18
|
+
private convertTools;
|
|
19
|
+
private mapStopReason;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=openai-completions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-completions.d.ts","sourceRoot":"","sources":["../../src/providers/openai-completions.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACX,gBAAgB,EAChB,OAAO,EACP,GAAG,EACH,UAAU,EAEV,KAAK,EAKL,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,2BAA4B,SAAQ,UAAU;IAC9D,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,QAAQ,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IAC7F,eAAe,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;CAC5C;AAED,qBAAa,oBAAqB,YAAW,GAAG,CAAC,2BAA2B,CAAC;IAC5E,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAQ;gBAEb,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM;IAazC,QAAQ,IAAI,KAAK;IAIX,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA+MlG,OAAO,CAAC,eAAe;IAiFvB,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,aAAa;CAerB"}
|