@tstdl/base 0.92.37 → 0.92.39
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/ai/ai-file.service.d.ts +1 -1
- package/ai/ai-file.service.js +2 -2
- package/ai/ai.service.d.ts +2 -1
- package/ai/ai.service.js +8 -5
- package/package.json +1 -1
package/ai/ai-file.service.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import '../polyfills.js';
|
|
|
2
2
|
import { Resolvable, type resolveArgumentType } from '../injector/interfaces.js';
|
|
3
3
|
import { AiServiceOptions } from './ai.service.js';
|
|
4
4
|
import { FileContentPart, FileInput } from './types.js';
|
|
5
|
-
export type AiFileServiceOptions = Pick<AiServiceOptions, 'apiKey' | 'vertex'>;
|
|
5
|
+
export type AiFileServiceOptions = Pick<AiServiceOptions, 'apiKey' | 'keyFile' | 'vertex'>;
|
|
6
6
|
export type AiFileServiceArgument = AiFileServiceOptions;
|
|
7
7
|
type File = {
|
|
8
8
|
id: string;
|
package/ai/ai-file.service.js
CHANGED
|
@@ -75,8 +75,8 @@ import { assertDefinedPass, isBlob, isDefined, isUndefined } from '../utils/type
|
|
|
75
75
|
import { millisecondsPerSecond } from '../utils/units.js';
|
|
76
76
|
let AiFileService = class AiFileService {
|
|
77
77
|
#options = injectArgument(this);
|
|
78
|
-
#fileManager = isUndefined(this.#options.vertex) ? new GoogleAIFileManager(this.#options.apiKey) : undefined;
|
|
79
|
-
#storage = isDefined(this.#options.vertex) ? new Storage({
|
|
78
|
+
#fileManager = isUndefined(this.#options.vertex) ? new GoogleAIFileManager(assertDefinedPass(this.#options.apiKey, 'Api key not defined')) : undefined;
|
|
79
|
+
#storage = isDefined(this.#options.vertex) ? new Storage({ keyFile: assertDefinedPass(this.#options.keyFile, 'Key file not defined'), projectId: this.#options.vertex.project }) : undefined;
|
|
80
80
|
#fileMap = new Map();
|
|
81
81
|
#fileUriMap = new Map();
|
|
82
82
|
#logger = inject(Logger, 'AiFileService');
|
package/ai/ai.service.d.ts
CHANGED
|
@@ -11,7 +11,8 @@ export type SpecializedGenerationResultGenerator<T> = AsyncGenerator<T> & {
|
|
|
11
11
|
raw: Promise<GenerationResult>;
|
|
12
12
|
};
|
|
13
13
|
export declare class AiServiceOptions {
|
|
14
|
-
apiKey
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
keyFile?: string;
|
|
15
16
|
vertex?: {
|
|
16
17
|
project: string;
|
|
17
18
|
location: string;
|
package/ai/ai.service.js
CHANGED
|
@@ -24,6 +24,7 @@ import { AiSession } from './ai-session.js';
|
|
|
24
24
|
import { isSchemaFunctionDeclarationWithHandler } from './types.js';
|
|
25
25
|
export class AiServiceOptions {
|
|
26
26
|
apiKey;
|
|
27
|
+
keyFile;
|
|
27
28
|
vertex;
|
|
28
29
|
defaultModel;
|
|
29
30
|
}
|
|
@@ -37,8 +38,8 @@ let AiService = class AiService {
|
|
|
37
38
|
#options = injectArgument(this, { optional: true }) ?? inject(AiServiceOptions);
|
|
38
39
|
#fileService = inject(AiFileService, this.#options);
|
|
39
40
|
#genAI = (isDefined(this.#options.vertex)
|
|
40
|
-
? new VertexAI({ project: this.#options.vertex.project, location: this.#options.vertex.location, googleAuthOptions: { apiKey: this.#options.apiKey } })
|
|
41
|
-
: new GoogleGenerativeAI(this.#options.apiKey));
|
|
41
|
+
? new VertexAI({ project: this.#options.vertex.project, location: this.#options.vertex.location, googleAuthOptions: { apiKey: this.#options.apiKey, keyFile: this.#options.keyFile } })
|
|
42
|
+
: new GoogleGenerativeAI(assertDefinedPass(this.#options.apiKey, 'Api key not defined')));
|
|
42
43
|
defaultModel = this.#options.defaultModel ?? 'gemini-2.0-flash-exp';
|
|
43
44
|
createSession() {
|
|
44
45
|
return new AiSession(this);
|
|
@@ -201,17 +202,19 @@ Always output the content and tags in ${options?.targetLanguage ?? 'the same lan
|
|
|
201
202
|
responseSchema: isDefined(request.generationSchema) ? convertToOpenApiSchema(request.generationSchema) : undefined,
|
|
202
203
|
frequencyPenalty: request.generationOptions?.frequencyPenalty
|
|
203
204
|
};
|
|
205
|
+
const model = request.model ?? this.defaultModel;
|
|
206
|
+
const maxModelTokens = model.includes('thinking') ? 65536 : 8192;
|
|
207
|
+
const maxTotalOutputTokens = request.generationOptions?.maxOutputTokens ?? maxModelTokens;
|
|
204
208
|
const inputContent = this.convertContents(request.contents);
|
|
205
|
-
const maxTotalOutputTokens = request.generationOptions?.maxOutputTokens ?? 8192;
|
|
206
209
|
let iterations = 0;
|
|
207
210
|
let totalPromptTokens = 0;
|
|
208
211
|
let totalOutputTokens = 0;
|
|
209
212
|
let totalTokens = 0;
|
|
210
213
|
while (totalOutputTokens < maxTotalOutputTokens) {
|
|
211
|
-
const generation = await this.getModel(
|
|
214
|
+
const generation = await this.getModel(model).generateContentStream({
|
|
212
215
|
generationConfig: {
|
|
213
216
|
...generationConfig,
|
|
214
|
-
maxOutputTokens: Math.min(
|
|
217
|
+
maxOutputTokens: Math.min(maxModelTokens, maxTotalOutputTokens - totalOutputTokens)
|
|
215
218
|
},
|
|
216
219
|
systemInstruction: request.systemInstruction,
|
|
217
220
|
tools: (isDefined(googleFunctionDeclarations) && (googleFunctionDeclarations.length > 0)) ? [{ functionDeclarations: googleFunctionDeclarations }] : undefined,
|