@ibgib/web-gib 0.0.5 → 0.0.7
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/dist/witness/agent/gemini/agent-witness-gemini-v1.d.mts +2 -2
- package/dist/witness/agent/gemini/agent-witness-gemini-v1.d.mts.map +1 -1
- package/dist/witness/agent/gemini/agent-witness-gemini-v1.mjs +160 -87
- package/dist/witness/agent/gemini/agent-witness-gemini-v1.mjs.map +1 -1
- package/dist/witness/agent/gemini/gemini-helpers.d.mts +10 -3
- package/dist/witness/agent/gemini/gemini-helpers.d.mts.map +1 -1
- package/dist/witness/agent/gemini/gemini-helpers.mjs +9 -4
- package/dist/witness/agent/gemini/gemini-helpers.mjs.map +1 -1
- package/dist/witness/agent/gemini/gemini-types.d.mts +20 -12
- package/dist/witness/agent/gemini/gemini-types.d.mts.map +1 -1
- package/dist/witness/agent/gemini/gemini-types.mjs.map +1 -1
- package/package.json +2 -2
- package/src/witness/agent/gemini/agent-witness-gemini-v1.mts +188 -94
- package/src/witness/agent/gemini/gemini-helpers.mts +17 -6
- package/src/witness/agent/gemini/gemini-types.mts +38 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini-helpers.mjs","sourceRoot":"","sources":["../../../../src/witness/agent/gemini/gemini-helpers.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gemini-helpers.mjs","sourceRoot":"","sources":["../../../../src/witness/agent/gemini/gemini-helpers.mts"],"names":[],"mappings":"AAUA,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,iDAAiD,CAAC;AAE1F,OAAO,EAAE,SAAS,GAAG,MAAM,wDAAwD,CAAC;AAEpF,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGjE,OAAO,EAAE,iCAAiC,EAAE,UAAU,GAAG,MAAM,wBAAwB,CAAC;AA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,KAAK,EAAE,QAAQ;SAClB,CAAC;QACF,MAAM,oBAAoB,GAAyB;YAC/C,gBAAgB,EAAE;gBACd,IAAI,EAAE,MAAM;gBACZ,QAAQ,EAAE,eAAe,EAAE,+CAA+C;aACzD;SACO,CAAC;QAEjC,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,QAAQ,EAAE,oBAAoB,EAAE,CAAC;KAErE;IAAC,OAAO,KAAK,EAAE;QACZ,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,WAAW,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACxD,MAAM,KAAK,CAAC;KACf;YAAS;QACN,IAAI,OAAO,EAAE;YAAE,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;SAAE;KACnD;AACL,CAAC"}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
import { Content } from "@google/
|
|
2
|
-
import type { FunctionCallingMode } from "@google/generative-ai";
|
|
1
|
+
import { Content, FunctionCallingConfigMode } from "@google/genai";
|
|
3
2
|
import { PromptInfo } from "../agent-types.mjs";
|
|
4
3
|
import { TextSource } from "../agent-constants.mjs";
|
|
4
|
+
import { type Part } from '@google/genai';
|
|
5
|
+
/** Utility type to make a specific key required, without using 'never' for others. */
|
|
6
|
+
type AssertRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
7
|
+
/** Represents a Part where the 'text' property is guaranteed to be a string. */
|
|
8
|
+
export type TextPart = AssertRequired<Part, 'text'>;
|
|
9
|
+
/** Represents a Part where the 'functionCall' property is guaranteed to be present. */
|
|
10
|
+
export type FunctionCallPart = AssertRequired<Part, 'functionCall'>;
|
|
11
|
+
/** Represents a Part where the 'functionResponse' property is guaranteed to be present. */
|
|
12
|
+
export type FunctionResponsePart = AssertRequired<Part, 'functionResponse'>;
|
|
13
|
+
import { type GenerateContentResponse } from '@google/genai';
|
|
14
|
+
export type EnhancedGenerateContentResponse = GenerateContentResponse;
|
|
5
15
|
export interface PromptInfoEntryGemini {
|
|
6
16
|
/**
|
|
7
17
|
* The source of the text, in terms of our code definition.
|
|
@@ -31,23 +41,19 @@ export interface PromptInfoGemini extends PromptInfo {
|
|
|
31
41
|
* recent.
|
|
32
42
|
*
|
|
33
43
|
* NOTE: We will be using this for the gemini api's "chat" function.
|
|
34
|
-
*
|
|
35
|
-
* @see {@link StartChatParams.history}
|
|
36
44
|
*/
|
|
37
45
|
chatPromptHistoryParts: PromptInfoEntryGemini[];
|
|
38
46
|
/**
|
|
39
47
|
* The most recent chat message
|
|
40
|
-
*
|
|
41
|
-
* @see {@link ChatSession.sendMessage}
|
|
42
48
|
*/
|
|
43
49
|
chatPromptCurrent: PromptInfoEntryGemini;
|
|
44
50
|
/**
|
|
45
51
|
* if truthy, this will override the default function calling mode when
|
|
46
52
|
* prompting the LLM.
|
|
47
53
|
*
|
|
48
|
-
* if falsy, will use the default (
|
|
54
|
+
* if falsy, will use the default (FunctionCallingConfigMode.ANY)
|
|
49
55
|
*
|
|
50
|
-
* @see {@link
|
|
56
|
+
* @see {@link FunctionCallingConfigMode}
|
|
51
57
|
*
|
|
52
58
|
* ## notes
|
|
53
59
|
*
|
|
@@ -56,7 +62,7 @@ export interface PromptInfoGemini extends PromptInfo {
|
|
|
56
62
|
* to just ask the model a "normal" chat llm question (for translating some
|
|
57
63
|
* text).
|
|
58
64
|
*/
|
|
59
|
-
overrideFunctionCallingMode?:
|
|
65
|
+
overrideFunctionCallingMode?: FunctionCallingConfigMode;
|
|
60
66
|
}
|
|
61
67
|
/**
|
|
62
68
|
* Gemini returns either function calls or raw text atow (01/2025)
|
|
@@ -72,11 +78,13 @@ export type PromptAPIResult_Gemini = {
|
|
|
72
78
|
};
|
|
73
79
|
/**
|
|
74
80
|
* This is a "kluge" IMO because it wraps the response part to be able to handle
|
|
75
|
-
* all responses of functions. This is a limitation of the Gemini API which
|
|
76
|
-
* object as the response part's value. So if a function returns
|
|
77
|
-
* it throws an error. So this is a wrapper.
|
|
81
|
+
* all responses of functions. This is a limitation of the Gemini API which
|
|
82
|
+
* requires an object as the response part's value. So if a function returns
|
|
83
|
+
* "undefined" or an array, it throws an error. So this is a wrapper.
|
|
78
84
|
*/
|
|
79
85
|
export interface FunctionResponsePart_ResponseWrapper {
|
|
80
86
|
value: any | undefined;
|
|
87
|
+
[key: string]: any;
|
|
81
88
|
}
|
|
89
|
+
export {};
|
|
82
90
|
//# sourceMappingURL=gemini-types.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini-types.d.mts","sourceRoot":"","sources":["../../../../src/witness/agent/gemini/gemini-types.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"gemini-types.d.mts","sourceRoot":"","sources":["../../../../src/witness/agent/gemini/gemini-types.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,yBAAyB,EAAgB,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,UAAU,EAAG,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAOpD,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,sFAAsF;AACtF,KAAK,cAAc,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAIrE,gFAAgF;AAChF,MAAM,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAEpD,uFAAuF;AACvF,MAAM,MAAM,gBAAgB,GAAG,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;AAEpE,2FAA2F;AAC3F,MAAM,MAAM,oBAAoB,GAAG,cAAc,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;AAM5E,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAC7D,MAAM,MAAM,+BAA+B,GAAG,uBAAuB,CAAC;AAItE,MAAM,WAAW,qBAAqB;IAClC;;;;;;;;OAQG;IACH,GAAG,EAAE,UAAU,CAAC;IAKhB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;CACpB;AACD;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAChD;;OAEG;IACH,mBAAmB,EAAE,qBAAqB,EAAE,CAAC;IAC7C;;;;;OAKG;IACH,sBAAsB,EAAE,qBAAqB,EAAE,CAAC;IAChD;;MAEE;IACF,iBAAiB,EAAE,qBAAqB,CAAC;IACzC;;;;;;;;;;;;;;OAcG;IACH,2BAA2B,CAAC,EAAE,yBAAyB,CAAC;CAC3D;AAED;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAC5B;IACE;;;OAGG;IACH,aAAa,EAAE,MAAM,EAAE,CAAA;CAC1B,GACC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvB;;;;;GAKG;AACH,MAAM,WAAW,oCAAoC;IACjD,KAAK,EAAE,GAAG,GAAG,SAAS,CAAC;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini-types.mjs","sourceRoot":"","sources":["../../../../src/witness/agent/gemini/gemini-types.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gemini-types.mjs","sourceRoot":"","sources":["../../../../src/witness/agent/gemini/gemini-types.mts"],"names":[],"mappings":"AAqDC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ibgib/web-gib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Framework for creating agentic ibGib web apps. Contains plumbing for ibgib components, agentic framework (currently only Gemini implemented), web-based IndexedDB storage substrate, and more.",
|
|
5
5
|
"funding": {
|
|
6
6
|
"type": "individual",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"author": "William Raiford",
|
|
43
43
|
"license": "ISC",
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@google/
|
|
45
|
+
"@google/genai": "^1.33.0",
|
|
46
46
|
"@ibgib/core-gib": "^0.1.4",
|
|
47
47
|
"@ibgib/encrypt-gib": "^0.2.33",
|
|
48
48
|
"@ibgib/helper-gib": "^0.0.32",
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module agent-witness-gemini-v1.mts
|
|
3
|
+
*
|
|
4
|
+
* ## MIGRATING TO @google/genai NOTES
|
|
5
|
+
*
|
|
6
|
+
* * Different Part types (TextPart, FunctionCallPart) are apparently "unified" in the new structure as just Part
|
|
7
|
+
*/
|
|
8
|
+
import { FunctionCallPart, FunctionResponsePart, } from './gemini-types.mjs';
|
|
1
9
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from '@google/
|
|
10
|
+
Part, GenerateContentResponse, Content, GoogleGenAI, SendMessageParameters,
|
|
11
|
+
CreateChatParameters, FunctionCallingConfigMode, FunctionCall,
|
|
12
|
+
} from '@google/genai';
|
|
5
13
|
|
|
6
14
|
import { clone, delay, extractErrorMsg, getTimestampInTicks, pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
7
15
|
import { Ib, IbGibAddr, TransformResult } from '@ibgib/ts-gib/dist/types.mjs';
|
|
@@ -11,8 +19,8 @@ import { ROOT_ADDR } from '@ibgib/ts-gib/dist/V1/constants.mjs';
|
|
|
11
19
|
import { getGibInfo } from '@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs';
|
|
12
20
|
import { CommentIbGib_V1 } from '@ibgib/core-gib/dist/common/comment/comment-types.mjs';
|
|
13
21
|
import { createCommentIbGib, parseCommentIb } from '@ibgib/core-gib/dist/common/comment/comment-helper.mjs';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
22
|
+
import { execInSpaceWithLocking } from '@ibgib/core-gib/dist/witness/space/space-helper.mjs';
|
|
23
|
+
import { appendToTimeline, Rel8nInfo } from '@ibgib/core-gib/dist/timeline/timeline-api.mjs';
|
|
16
24
|
|
|
17
25
|
import { GLOBAL_LOG_A_LOT } from '../../../constants.mjs';
|
|
18
26
|
import { getAllFunctionInfos, getDeprecatedFunctionInfoNames } from '../../../api/api-index.mjs';
|
|
@@ -35,15 +43,13 @@ import { agentIbGibDtoToWitness } from './gemini-agent-factory.mjs';
|
|
|
35
43
|
import { getAgentsSvc } from '../agents-service-v1.mjs';
|
|
36
44
|
import { GEMINI_BACKUP_MODEL_STR, GEMINI_ERROR_DETAILS_TYPE_RETRY_INFO, GEMINI_ERROR_DETAILS_TYPE_RETRY_INFO_RETRY_DELAY_KEY, GEMINI_ERROR_STATUS_MODEL_OVERLOADED, GEMINI_ERROR_STATUS_RATE_QUOTA_EXCEEDED, GEMINI_MAX_TRY_COUNT } from './gemini-constants.mjs';
|
|
37
45
|
import { AGENT_REL8N_NAME, TextSource } from '../agent-constants.mjs';
|
|
38
|
-
// import { appendToTimeline, getLockScope, mut8Timeline, Rel8nInfo } from '../../../api/timeline/timeline-api.mjs';
|
|
39
|
-
import { execInSpaceWithLocking } from '@ibgib/core-gib/dist/witness/space/space-helper.mjs';
|
|
40
|
-
import { appendToTimeline, Rel8nInfo } from '@ibgib/core-gib/dist/timeline/timeline-api.mjs';
|
|
41
46
|
import { AgentWitness_V1 } from '../agent-one-file.mjs';
|
|
42
47
|
|
|
43
48
|
const logalot = GLOBAL_LOG_A_LOT;
|
|
44
49
|
|
|
45
50
|
export class AgentWitnessGemini_V1
|
|
46
|
-
extends AgentWitness_V1<
|
|
51
|
+
extends AgentWitness_V1<GoogleGenAI, PromptInfoGemini, PromptAPIResult_Gemini> {
|
|
52
|
+
// extends AgentWitness_V1<GoogleGenerativeAI, PromptInfoGemini, PromptAPIResult_Gemini> {
|
|
47
53
|
// witness(arg: IbGib_V1): Promise<IbGib_V1 | undefined> {
|
|
48
54
|
// throw new Error('Method not implemented.');
|
|
49
55
|
// }
|
|
@@ -268,7 +274,8 @@ export class AgentWitnessGemini_V1
|
|
|
268
274
|
text: getTextPartForCurrentContextTjpAddr({
|
|
269
275
|
currentContextTjpAddr
|
|
270
276
|
})
|
|
271
|
-
} satisfies
|
|
277
|
+
} satisfies Part // see genai migration note at top of this file
|
|
278
|
+
// } satisfies TextPart
|
|
272
279
|
],
|
|
273
280
|
}
|
|
274
281
|
})
|
|
@@ -344,7 +351,8 @@ export class AgentWitnessGemini_V1
|
|
|
344
351
|
text: 'no api key entered so no LLM chat happening. enter a gemini api key and donate/invest!',
|
|
345
352
|
}; /* <<<< returns early */
|
|
346
353
|
}
|
|
347
|
-
this._genAI ??= new
|
|
354
|
+
this._genAI ??= new GoogleGenAI({ apiKey });
|
|
355
|
+
// this._genAI ??= new GoogleGenerativeAI(apiKey);
|
|
348
356
|
|
|
349
357
|
const functionDeclarations = Array.from(this.availableFunctions.values()).map(
|
|
350
358
|
(x) => ({
|
|
@@ -391,7 +399,8 @@ export class AgentWitnessGemini_V1
|
|
|
391
399
|
// this.transientDecompressionPromptText = undefined;
|
|
392
400
|
// }
|
|
393
401
|
|
|
394
|
-
let result:
|
|
402
|
+
let result: GenerateContentResponse | undefined = undefined;
|
|
403
|
+
// let result: GenerateContentResult | undefined = undefined;
|
|
395
404
|
|
|
396
405
|
/**
|
|
397
406
|
* need to be able to call this function with retries with different
|
|
@@ -406,33 +415,75 @@ export class AgentWitnessGemini_V1
|
|
|
406
415
|
* @param modelStr to use
|
|
407
416
|
* @param isRetry if true, this indicates this is aleady a retry and should throw if fails
|
|
408
417
|
*/
|
|
418
|
+
// const fnGoModel = async (modelStr: string) => {
|
|
419
|
+
// if (!this._genAI) { throw new Error(`(UNEXPECTED) this._genAI falsy? (E: 503a0d9e3f729de7653ee3565b017b25)`); }
|
|
420
|
+
// const genModel = this._genAI.getGenerativeModel({
|
|
421
|
+
// model: modelStr,
|
|
422
|
+
// systemInstruction: systemPromptEntriesToSystemInstructionContent({ systemPromptEntries }),
|
|
423
|
+
// tools: [{ functionDeclarations }],
|
|
424
|
+
// toolConfig: {
|
|
425
|
+
// functionCallingConfig: {
|
|
426
|
+
// // mode: FunctionCallingMode.AUTO, // can be either text or function call, this is the default
|
|
427
|
+
// mode:
|
|
428
|
+
// info.overrideFunctionCallingMode ??
|
|
429
|
+
// FunctionCallingMode.ANY, // MANDATES a function call. If this is not used, the model gets confused, but maybe this will be fixed after we get better function response feedback in place.
|
|
430
|
+
// },
|
|
431
|
+
// },
|
|
432
|
+
// });
|
|
433
|
+
// /**
|
|
434
|
+
// * We start a "chat", _BUT ONLY TO USE THE HISTORY MECHANISM_.
|
|
435
|
+
// * Really we use this as a one-off, but we do not know how to mimic
|
|
436
|
+
// * the "history" so that the model understands to only respond to
|
|
437
|
+
// * the most recent prompt.
|
|
438
|
+
// */
|
|
439
|
+
// const chat = genModel.startChat({
|
|
440
|
+
// history: chatPromptHistoryParts.map(x => x.content),
|
|
441
|
+
// });
|
|
442
|
+
// result = await chat.sendMessage(chatPromptCurrent.content.parts);
|
|
443
|
+
// return result;
|
|
444
|
+
// }
|
|
445
|
+
// interface ChatConfigParams {
|
|
446
|
+
// model: string;
|
|
447
|
+
// history: Content[];
|
|
448
|
+
// config: GenerateContentConfig;
|
|
449
|
+
// }
|
|
450
|
+
|
|
409
451
|
const fnGoModel = async (modelStr: string) => {
|
|
410
|
-
if (!this._genAI) {
|
|
411
|
-
|
|
452
|
+
if (!this._genAI) {
|
|
453
|
+
throw new Error(`(UNEXPECTED) this._genAI falsy? (E: 503a0d9e3f729de7653ee3565b017b25)`);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const historyContents: Content[] = chatPromptHistoryParts.map(x => x.content);
|
|
457
|
+
|
|
458
|
+
const chatConfig: CreateChatParameters = {
|
|
412
459
|
model: modelStr,
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
info.overrideFunctionCallingMode ??
|
|
420
|
-
|
|
460
|
+
history: historyContents,
|
|
461
|
+
config: {
|
|
462
|
+
systemInstruction: systemPromptEntriesToSystemInstructionContent({ systemPromptEntries }),
|
|
463
|
+
tools: [{ functionDeclarations }],
|
|
464
|
+
toolConfig: {
|
|
465
|
+
functionCallingConfig: {
|
|
466
|
+
mode: info.overrideFunctionCallingMode ?? FunctionCallingConfigMode.ANY,
|
|
467
|
+
},
|
|
421
468
|
},
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
const chat = this._genAI.chats.create(chatConfig);
|
|
473
|
+
|
|
474
|
+
// The 'sendMessage' method requires a `message` property in its parameters object.
|
|
475
|
+
// The message content itself can be a string or Part[] (PartListUnion).
|
|
476
|
+
|
|
477
|
+
// Prepare the message parameters:
|
|
478
|
+
const messageParams: SendMessageParameters = {
|
|
479
|
+
message: chatPromptCurrent.content.parts as Part[], // Cast to Part[] to satisfy the type
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
// The result is typed as GenerateContentResponse
|
|
483
|
+
const result: GenerateContentResponse = await chat.sendMessage(messageParams);
|
|
484
|
+
|
|
434
485
|
return result;
|
|
435
|
-
}
|
|
486
|
+
};
|
|
436
487
|
|
|
437
488
|
let tryCount = 0;
|
|
438
489
|
let modelStr = model;
|
|
@@ -442,7 +493,11 @@ export class AgentWitnessGemini_V1
|
|
|
442
493
|
result = await fnGoModel(modelStr);
|
|
443
494
|
break;
|
|
444
495
|
} catch (error) {
|
|
445
|
-
|
|
496
|
+
const errorMessage = error.message;
|
|
497
|
+
const status = (error as any).status ?? '[STATUS?]';
|
|
498
|
+
|
|
499
|
+
// if (error.status && error.status === GEMINI_ERROR_STATUS_MODEL_OVERLOADED) {
|
|
500
|
+
if (errorMessage.includes(`${GEMINI_ERROR_STATUS_MODEL_OVERLOADED}`)) {
|
|
446
501
|
// model is overloaded, try using the backup
|
|
447
502
|
console.error(`${lc}[fnGoModel][${modelStr}] error trying to get result from model. will try using backup model (${GEMINI_BACKUP_MODEL_STR}) for this next call. error (${error.status}): ${extractErrorMsg(error)} (E: a5cd7d174183518058da57cc6d0d8a25)`);
|
|
448
503
|
modelStr = GEMINI_BACKUP_MODEL_STR;
|
|
@@ -455,12 +510,28 @@ export class AgentWitnessGemini_V1
|
|
|
455
510
|
if (!result) { throw new Error(`couldn't get result from model (E: ede013a53f875d99a96a2e257c7e7125)`); }
|
|
456
511
|
|
|
457
512
|
// const result = await genModel.generateContent(finalChatPrompt);
|
|
458
|
-
const enhancedResult = result.response as EnhancedGenerateContentResponse;
|
|
459
|
-
const functionCalls = enhancedResult.functionCalls();
|
|
513
|
+
// const enhancedResult = result.response as EnhancedGenerateContentResponse;
|
|
514
|
+
// const functionCalls = enhancedResult.functionCalls();
|
|
515
|
+
|
|
516
|
+
// The 'result' IS the GenerateContentResponse object directly.
|
|
517
|
+
const response: GenerateContentResponse = result;
|
|
518
|
+
|
|
519
|
+
// Function calls are no longer accessed via a method, but by manually scanning the 'candidates' structure.
|
|
520
|
+
|
|
521
|
+
// We need a way to extract the function calls from the parts array manually.
|
|
522
|
+
const functionCalls: FunctionCall[] = [];
|
|
523
|
+
const parts = response.candidates?.[0]?.content?.parts || [];
|
|
524
|
+
|
|
525
|
+
for (const part of parts) {
|
|
526
|
+
if (part.functionCall) {
|
|
527
|
+
functionCalls.push(part.functionCall);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
460
530
|
|
|
461
531
|
if (!functionCalls || functionCalls.length === 0) {
|
|
462
532
|
if (logalot) { console.warn(`${lc} no function calls in response, returning text. (W: 3a4b8c940983b9e28e3f04c01a09bb25)`); }
|
|
463
|
-
|
|
533
|
+
if (!response.text) { throw new Error(`response generated no function calls and no response.text (E: 6123b8cacfb834105ad3160cfc4ef825)`); }
|
|
534
|
+
return { text: response.text };
|
|
464
535
|
}
|
|
465
536
|
|
|
466
537
|
if (logalot) {
|
|
@@ -514,13 +585,14 @@ export class AgentWitnessGemini_V1
|
|
|
514
585
|
// part for the function response entry.
|
|
515
586
|
const functionInfoIbGibs: FunctionInfoIbGib_V1[] =
|
|
516
587
|
await this.getFunctionInfoIbGibs({ fcrCommentIbGib: commentIbGib });
|
|
588
|
+
// const functionCallParts: Part[] = [];
|
|
517
589
|
const functionCallParts: FunctionCallPart[] = [];
|
|
518
590
|
const functionResponseParts: FunctionResponsePart[] = [];
|
|
519
591
|
for (let functionInfoIbGib of functionInfoIbGibs) {
|
|
520
592
|
let { call, response } = getFunctionCallAndResponseParts({ functionInfoIbGib });
|
|
521
593
|
if (!call) { throw new Error(`(UNEXPECTED) call falsy? (E: 5c8f3bd6de3b300e1c105b9603bb7b25)`); }
|
|
522
594
|
if (!response) { throw new Error(`(UNEXPECTED) response falsy? (E: d0388c838975c93126c1a6d64f781d25)`); }
|
|
523
|
-
if (call.functionCall
|
|
595
|
+
if (call.functionCall!.name !== response.functionResponse.name) {
|
|
524
596
|
throw new Error(`(UNEXPECTED) functionCall.name !== functionResponse.name? (E: e49f0d60093354db2b6ad17fdf86d425)`);
|
|
525
597
|
}
|
|
526
598
|
functionCallParts.push(call);
|
|
@@ -560,7 +632,12 @@ export class AgentWitnessGemini_V1
|
|
|
560
632
|
// text: commentIbGib.data.text,
|
|
561
633
|
content: {
|
|
562
634
|
role: textSourceToGeminiRole(textSrc),
|
|
563
|
-
parts: [
|
|
635
|
+
parts: [
|
|
636
|
+
{
|
|
637
|
+
text: commentIbGib.data.text
|
|
638
|
+
} satisfies Part // see genai migration note at top of this file
|
|
639
|
+
// } satisfies TextPart
|
|
640
|
+
],
|
|
564
641
|
}
|
|
565
642
|
}];
|
|
566
643
|
}
|
|
@@ -593,8 +670,7 @@ export class AgentWitnessGemini_V1
|
|
|
593
670
|
console.error(`${lc} apiKey falsy. did you set this.fnGetAPIKey (E: genuuid)`);
|
|
594
671
|
return undefined; /* <<<< returns early */
|
|
595
672
|
}
|
|
596
|
-
this._genAI ??= new
|
|
597
|
-
|
|
673
|
+
this._genAI ??= new GoogleGenAI({ apiKey });
|
|
598
674
|
|
|
599
675
|
/**
|
|
600
676
|
* need to be able to call this function with retries with different
|
|
@@ -610,26 +686,31 @@ export class AgentWitnessGemini_V1
|
|
|
610
686
|
* @param isRetry if true, this indicates this is aleady a retry and should throw if fails
|
|
611
687
|
*/
|
|
612
688
|
const fnGoModel = async (modelStr: string) => {
|
|
613
|
-
if (!this._genAI) { throw new Error(`(UNEXPECTED) this._genAI falsy? (E:
|
|
614
|
-
const
|
|
689
|
+
if (!this._genAI) { throw new Error(`(UNEXPECTED) this._genAI falsy? (E: fbe235713d48f0d8e87cd0b88ec54825)`); }
|
|
690
|
+
const chatConfig: CreateChatParameters = {
|
|
615
691
|
model: modelStr,
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
// const chat = genModel.startChat({
|
|
625
|
-
// history: chatPromptHistoryParts.map(x => x.content),
|
|
626
|
-
// });
|
|
627
|
-
const result = await genModel.generateContent(text);
|
|
628
|
-
if (result.response) {
|
|
629
|
-
return result.response.text();
|
|
692
|
+
config: {
|
|
693
|
+
systemInstruction: systemInstructions,
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
const chat = this._genAI.chats.create(chatConfig);
|
|
697
|
+
const response = await chat.sendMessage({ message: text });
|
|
698
|
+
if (response.text) {
|
|
699
|
+
return response.text;
|
|
630
700
|
} else {
|
|
631
|
-
throw new Error(`
|
|
701
|
+
throw new Error(`response.text empty/falsy, potentially blocked by safety settings (E: a21a78c9471f27a42c07d1c859187825)`);
|
|
702
|
+
|
|
632
703
|
}
|
|
704
|
+
// const genModel = this._genAI.getGenerativeModel({
|
|
705
|
+
// model: modelStr,
|
|
706
|
+
// systemInstruction: systemInstructions,
|
|
707
|
+
// });
|
|
708
|
+
// const result = await genModel.generateContent(text);
|
|
709
|
+
// if (result.response) {
|
|
710
|
+
// return result.response.text();
|
|
711
|
+
// } else {
|
|
712
|
+
// throw new Error(`not implemented (E: bbf05fe00da23d5b16c223bd200eaa25)`);
|
|
713
|
+
// }
|
|
633
714
|
}
|
|
634
715
|
|
|
635
716
|
let result: string | undefined = undefined;
|
|
@@ -640,47 +721,60 @@ export class AgentWitnessGemini_V1
|
|
|
640
721
|
tryCount++;
|
|
641
722
|
retryDelayInSeconds++;
|
|
642
723
|
try {
|
|
643
|
-
|
|
724
|
+
debugger; // step through the new error mechanism and look for how to determine if the model is overloaded vs quota exceeded
|
|
725
|
+
// let x: ErrorDetails
|
|
644
726
|
result = await fnGoModel(modelStr);
|
|
645
727
|
break;
|
|
646
728
|
} catch (error) {
|
|
647
|
-
if (error
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
let errorDetails: ErrorDetails[] = error.errorDetails;
|
|
661
|
-
let retryInfo = errorDetails.find(x => x['@type'] === GEMINI_ERROR_DETAILS_TYPE_RETRY_INFO);
|
|
662
|
-
retryDelayInSeconds = 30;
|
|
663
|
-
if (retryInfo && retryInfo[GEMINI_ERROR_DETAILS_TYPE_RETRY_INFO_RETRY_DELAY_KEY]) {
|
|
664
|
-
// get more accurate wait time
|
|
665
|
-
let retryStr = retryInfo[GEMINI_ERROR_DETAILS_TYPE_RETRY_INFO_RETRY_DELAY_KEY]! as string;
|
|
666
|
-
// retryStr from testing is in seconds, e.g., "41s". IF it's longer than a minute, I don't know/care (too long)
|
|
667
|
-
if (retryStr.match(/^\d+s$/)) {
|
|
668
|
-
// valid retry str in seconds
|
|
669
|
-
retryDelayInSeconds = Number.parseInt(retryStr.substring(0, retryStr.length - 1));
|
|
670
|
-
if (Number.isNaN(retryDelayInSeconds)) {
|
|
671
|
-
retryDelayInSeconds = 30;
|
|
672
|
-
}
|
|
673
|
-
} else {
|
|
674
|
-
retryDelayInSeconds = 30;
|
|
675
|
-
console.error(`${lc}[fnGoModel][${modelStr}] error trying to get result from model: GEMINI_ERROR_STATUS_RATE_QUOTA_EXCEEDED ${GEMINI_ERROR_STATUS_RATE_QUOTA_EXCEEDED}. Could not find valid retryInfo (errorDetails with retry info with a ${GEMINI_ERROR_DETAILS_TYPE_RETRY_INFO_RETRY_DELAY_KEY} with an "s"). So we'll just try waiting ${retryDelayInSeconds} seconds: ${extractErrorMsg(error)} (E: 986d9883fc72bf156f1691183e27ee25)`);
|
|
676
|
-
}
|
|
729
|
+
if (error instanceof Error) {
|
|
730
|
+
const errorMessage = error.message;
|
|
731
|
+
const status = (error as any).status ?? '[STATUS?]';
|
|
732
|
+
|
|
733
|
+
// if (error.status && error.status === GEMINI_ERROR_STATUS_MODEL_OVERLOADED) // see migration notes at top of file
|
|
734
|
+
if (errorMessage.includes(`${GEMINI_ERROR_STATUS_MODEL_OVERLOADED}`)) {
|
|
735
|
+
if (modelStr === GEMINI_BACKUP_MODEL_STR) {
|
|
736
|
+
// already is the backup model, so we just fail
|
|
737
|
+
console.error(`${lc}[fnGoModel][${modelStr}] error trying to get result from model: GEMINI_ERROR_STATUS_MODEL_OVERLOADED ${GEMINI_ERROR_STATUS_MODEL_OVERLOADED}. we are already using the backup model, so SOL here. will try again... error (${status}): ${extractErrorMsg(error)} (E: 9bb63cb520b8bd3bb85d2ca20715c825)`);
|
|
738
|
+
} else {
|
|
739
|
+
// model is overloaded, try using the backup
|
|
740
|
+
console.error(`${lc}[fnGoModel][${modelStr}] error trying to get result from model: GEMINI_ERROR_STATUS_MODEL_OVERLOADED ${GEMINI_ERROR_STATUS_MODEL_OVERLOADED}. will try using backup model (${GEMINI_BACKUP_MODEL_STR}) for this next call. error (${status}): ${extractErrorMsg(error)} (E: b07a041bb97ea95b03cd6f9856f01525)`);
|
|
741
|
+
modelStr = GEMINI_BACKUP_MODEL_STR;
|
|
677
742
|
}
|
|
743
|
+
// else if (error.status && error.status === GEMINI_ERROR_STATUS_RATE_QUOTA_EXCEEDED)
|
|
744
|
+
} else if (errorMessage.includes(`${GEMINI_ERROR_STATUS_RATE_QUOTA_EXCEEDED}`)) {
|
|
745
|
+
// quota exceeded, either try backup or wait for retry
|
|
746
|
+
debugger; // examine the error to see if we can manually parse out any information about retry
|
|
747
|
+
throw new Error('examine the error to see if we can manually parse out any information about retry (E: ea2c2e2ef1deadf968cd0558cdfd5a25)');
|
|
748
|
+
|
|
749
|
+
// if (modelStr === GEMINI_BACKUP_MODEL_STR) {
|
|
750
|
+
// // nothing else to try, wait retry amount if possible
|
|
751
|
+
// let errorDetails: ErrorDetails[] = error.errorDetails;
|
|
752
|
+
// let retryInfo = errorDetails.find(x => x['@type'] === GEMINI_ERROR_DETAILS_TYPE_RETRY_INFO);
|
|
753
|
+
// retryDelayInSeconds = 30;
|
|
754
|
+
// if (retryInfo && retryInfo[GEMINI_ERROR_DETAILS_TYPE_RETRY_INFO_RETRY_DELAY_KEY]) {
|
|
755
|
+
// // get more accurate wait time
|
|
756
|
+
// let retryStr = retryInfo[GEMINI_ERROR_DETAILS_TYPE_RETRY_INFO_RETRY_DELAY_KEY]! as string;
|
|
757
|
+
// // retryStr from testing is in seconds, e.g., "41s". IF it's longer than a minute, I don't know/care (too long)
|
|
758
|
+
// if (retryStr.match(/^\d+s$/)) {
|
|
759
|
+
// // valid retry str in seconds
|
|
760
|
+
// retryDelayInSeconds = Number.parseInt(retryStr.substring(0, retryStr.length - 1));
|
|
761
|
+
// if (Number.isNaN(retryDelayInSeconds)) {
|
|
762
|
+
// retryDelayInSeconds = 30;
|
|
763
|
+
// }
|
|
764
|
+
// } else {
|
|
765
|
+
// retryDelayInSeconds = 30;
|
|
766
|
+
// console.error(`${lc}[fnGoModel][${modelStr}] error trying to get result from model: GEMINI_ERROR_STATUS_RATE_QUOTA_EXCEEDED ${GEMINI_ERROR_STATUS_RATE_QUOTA_EXCEEDED}. Could not find valid retryInfo (errorDetails with retry info with a ${GEMINI_ERROR_DETAILS_TYPE_RETRY_INFO_RETRY_DELAY_KEY} with an "s"). So we'll just try waiting ${retryDelayInSeconds} seconds: ${extractErrorMsg(error)} (E: 986d9883fc72bf156f1691183e27ee25)`);
|
|
767
|
+
// }
|
|
768
|
+
// }
|
|
769
|
+
// } else {
|
|
770
|
+
// console.error(`${lc}[fnGoModel][${modelStr}] error trying to get result from model: GEMINI_ERROR_STATUS_RATE_QUOTA_EXCEEDED ${GEMINI_ERROR_STATUS_RATE_QUOTA_EXCEEDED}. will try using backup model (${GEMINI_BACKUP_MODEL_STR}) for this next call. error (${error.status}): ${extractErrorMsg(error)} (E: 637ed809c659f55738becab83fc01825)`);
|
|
771
|
+
// }
|
|
772
|
+
// modelStr = GEMINI_BACKUP_MODEL_STR;
|
|
678
773
|
} else {
|
|
679
|
-
console.error(`${lc}[fnGoModel][${modelStr}] error trying to get result from model
|
|
774
|
+
console.error(`${lc}[fnGoModel][${modelStr}] error trying to get result from model. error (${status}): ${extractErrorMsg(error)} (E: a67d595c8ed313d458369d4d0b3e7f25)`);
|
|
680
775
|
}
|
|
681
|
-
modelStr = GEMINI_BACKUP_MODEL_STR;
|
|
682
776
|
} else {
|
|
683
|
-
console.error(`${lc}[fnGoModel][${modelStr}] error
|
|
777
|
+
console.error(`${lc}[fnGoModel][${modelStr}] (UNEXPECTED) error is not instanceof Error? The expected error from the @google/genai lib is supposed to be an instance of Error according to Gemini migration AI. (E: 15df95701e78b35f783d250801092825)`);
|
|
684
778
|
}
|
|
685
779
|
}
|
|
686
780
|
if (tryCount > 1) {
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module gemini-helpers.mts
|
|
3
|
+
*
|
|
4
|
+
* ## MIGRATION to @google/genai
|
|
5
|
+
*
|
|
6
|
+
* See migration notes in agent-witness-gemini.mts.
|
|
7
|
+
*/
|
|
8
|
+
import { FunctionCallPart, FunctionResponsePart, } from "./gemini-types.mjs";
|
|
9
|
+
import { Content, FunctionCall, FunctionResponse, } from "@google/genai";
|
|
3
10
|
|
|
4
11
|
import { extractErrorMsg, pretty } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
|
|
5
12
|
import { IbGib_V1 } from "@ibgib/ts-gib/dist/V1/types.mjs";
|
|
@@ -22,7 +29,8 @@ export function textSourceToGeminiRole(src: TextSource): string {
|
|
|
22
29
|
case TextSource.AI:
|
|
23
30
|
return 'model';
|
|
24
31
|
case TextSource.FUNCTION:
|
|
25
|
-
return 'function';
|
|
32
|
+
// return 'function';
|
|
33
|
+
return 'user';
|
|
26
34
|
case TextSource.HARDCODED:
|
|
27
35
|
return 'user';
|
|
28
36
|
case TextSource.UNKNOWN:
|
|
@@ -55,6 +63,7 @@ export function geminiFunctionCallToAPIFunctionInfo({
|
|
|
55
63
|
functionCall: FunctionCall
|
|
56
64
|
}): { info: APIFunctionInfo, args: any } {
|
|
57
65
|
const lc = `[${geminiFunctionCallToAPIFunctionInfo.name}]`;
|
|
66
|
+
if (!functionCall.name) { throw new Error(`(UNEXPECTED) functionCall.name is falsy? (E: b2c638cf22f88493d823e7e9915fd625)`); }
|
|
58
67
|
const functionInfo = getAllFunctionInfos().get(functionCall.name);
|
|
59
68
|
if (!functionInfo) {
|
|
60
69
|
throw new Error(`${lc} no APIFunctionInfo found matching name: ${functionCall.name} (E: 7c5c7c17988a666a86e72299630c7f25)`);
|
|
@@ -68,7 +77,6 @@ export function geminiFunctionCallToAPIFunctionInfo({
|
|
|
68
77
|
/**
|
|
69
78
|
* Takes 0 or more entries and combines them into a single {@link Content}
|
|
70
79
|
* object that Gemini API expects for `systemInstruction` when using the fn
|
|
71
|
-
* {@link GoogleGenerativeAI.getGenerativeModel} (@see {@link ModelParams}).
|
|
72
80
|
*
|
|
73
81
|
* @param entries for system instruction, probably from {@link AgentWitnessGemini_V1.systemPromptParts}
|
|
74
82
|
* @returns undefined if no entries, else single Gemini API Content object with role === "user" and combined parts from {@link systemPromptEntries}
|
|
@@ -88,7 +96,10 @@ export function systemPromptEntriesToSystemInstructionContent({
|
|
|
88
96
|
}
|
|
89
97
|
const sysInstructionContent: Content = {
|
|
90
98
|
role: "user",
|
|
91
|
-
parts:
|
|
99
|
+
parts:
|
|
100
|
+
systemPromptEntries
|
|
101
|
+
.filter(entry => !!entry.content.parts)
|
|
102
|
+
.flatMap(entry => entry.content.parts!),
|
|
92
103
|
};
|
|
93
104
|
if (logalot) { console.log(`${lc} sysInstructionContent: ${pretty(sysInstructionContent)} (I: 011e5b865c23eb0b640df3f464ac2525)`); }
|
|
94
105
|
return sysInstructionContent;
|
|
@@ -160,7 +171,7 @@ export function isFunctionCallRequestComment({ ibGib }: { ibGib: IbGib_V1 }): bo
|
|
|
160
171
|
*
|
|
161
172
|
* @param {object} arg - Arguments object.
|
|
162
173
|
* @param {FunctionInfoIbGib_V1} arg.functionInfoIbGib - The FunctionInfoIbGib_V1 instance containing function call details.
|
|
163
|
-
* @returns {{ call:
|
|
174
|
+
* @returns {{ call: Part; response: Part }} - An object containing both FunctionCallPart and FunctionResponsePart objects.
|
|
164
175
|
* @throws {Error} If there's an error during the process, such as missing function name or arguments.
|
|
165
176
|
*/
|
|
166
177
|
export function getFunctionCallAndResponseParts({
|