@tstdl/base 0.92.31 → 0.92.33

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.
@@ -12,6 +12,10 @@ export type SpecializedGenerationResultGenerator<T> = AsyncGenerator<T> & {
12
12
  };
13
13
  export declare class AiServiceOptions {
14
14
  apiKey: string;
15
+ vertex?: {
16
+ project: string;
17
+ location: string;
18
+ };
15
19
  defaultModel?: AiModel;
16
20
  }
17
21
  export type AiServiceArgument = AiServiceOptions;
package/ai/ai.service.js CHANGED
@@ -4,7 +4,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { FinishReason, FunctionCallingMode as GoogleFunctionCallingMode, GoogleGenerativeAI } from '@google/generative-ai';
7
+ import { FinishReason, FunctionCallingMode as GoogleFunctionCallingMode, VertexAI } from '@google-cloud/vertexai';
8
+ import { GoogleGenerativeAI } from '@google/generative-ai';
8
9
  import { NotSupportedError } from '../errors/not-supported.error.js';
9
10
  import { Singleton } from '../injector/decorators.js';
10
11
  import { inject, injectArgument } from '../injector/inject.js';
@@ -16,13 +17,14 @@ import { toArray } from '../utils/array/array.js';
16
17
  import { mapAsync } from '../utils/async-iterable-helpers/map.js';
17
18
  import { toArrayAsync } from '../utils/async-iterable-helpers/to-array.js';
18
19
  import { hasOwnProperty, objectEntries } from '../utils/object/object.js';
19
- import { assertDefinedPass, assertNotNullPass, isDefined, isUndefined } from '../utils/type-guards.js';
20
+ import { assertDefinedPass, assertNotNullPass, isDefined, isNotNull, isUndefined } from '../utils/type-guards.js';
20
21
  import { resolveValueOrAsyncProvider } from '../utils/value-or-provider.js';
21
22
  import { AiFileService } from './ai-file.service.js';
22
23
  import { AiSession } from './ai-session.js';
23
24
  import { isSchemaFunctionDeclarationWithHandler } from './types.js';
24
25
  export class AiServiceOptions {
25
26
  apiKey;
27
+ vertex;
26
28
  defaultModel;
27
29
  }
28
30
  ;
@@ -34,7 +36,9 @@ const functionCallingModeMap = {
34
36
  let AiService = class AiService {
35
37
  #options = injectArgument(this, { optional: true }) ?? inject(AiServiceOptions);
36
38
  #fileService = inject(AiFileService, this.#options);
37
- #genAI = new GoogleGenerativeAI(this.#options.apiKey);
39
+ #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));
38
42
  defaultModel = this.#options.defaultModel ?? 'gemini-2.0-flash-exp';
39
43
  createSession() {
40
44
  return new AiSession(this);
@@ -195,7 +199,6 @@ Always output the content and tags in ${options?.targetLanguage ?? 'the same lan
195
199
  topK: request.generationOptions?.topK,
196
200
  responseMimeType: isDefined(request.generationSchema) ? 'application/json' : undefined,
197
201
  responseSchema: isDefined(request.generationSchema) ? convertToOpenApiSchema(request.generationSchema) : undefined,
198
- presencePenalty: request.generationOptions?.presencePenalty,
199
202
  frequencyPenalty: request.generationOptions?.frequencyPenalty
200
203
  };
201
204
  const inputContent = this.convertContents(request.contents);
@@ -333,15 +336,18 @@ Always output the content and tags in ${options?.targetLanguage ?? 'the same lan
333
336
  convertGoogleContent(content) {
334
337
  return {
335
338
  role: content.role,
336
- parts: content.parts.map((part) => {
339
+ parts: content.parts
340
+ .map((part) => {
337
341
  if (isDefined(part.text)) {
342
+ if (part.text.length == 0) {
343
+ return null;
344
+ }
338
345
  return { text: part.text };
339
346
  }
340
347
  if (isDefined(part.fileData)) {
341
348
  const file = assertDefinedPass(this.#fileService.getFileByUri(part.fileData.fileUri), 'File not found.');
342
349
  return { file: file.id };
343
350
  }
344
- ;
345
351
  if (isDefined(part.functionResponse)) {
346
352
  return { functionResult: { name: part.functionResponse.name, value: part.functionResponse.response } };
347
353
  }
@@ -350,6 +356,7 @@ Always output the content and tags in ${options?.targetLanguage ?? 'the same lan
350
356
  }
351
357
  throw new NotSupportedError('Unsupported content part.');
352
358
  })
359
+ .filter(isNotNull)
353
360
  };
354
361
  }
355
362
  getModel(model) {
package/ai/types.d.ts CHANGED
@@ -58,7 +58,6 @@ export type GenerationOptions = {
58
58
  temperature?: number;
59
59
  topP?: number;
60
60
  topK?: number;
61
- presencePenalty?: number;
62
61
  frequencyPenalty?: number;
63
62
  };
64
63
  export type GenerationRequest = {
@@ -32,8 +32,8 @@ export declare const documentManagementApiDefinition: {
32
32
  resource: string;
33
33
  method: "GET";
34
34
  parameters: import("../../schema/index.js").ObjectSchema<{
35
- readonly id: string;
36
35
  readonly title: string | null;
36
+ readonly id: string;
37
37
  readonly download?: boolean | undefined;
38
38
  }>;
39
39
  result: Uint8ArrayConstructor;
@@ -43,8 +43,8 @@ export declare const documentManagementApiDefinition: {
43
43
  resource: string;
44
44
  method: "GET";
45
45
  parameters: import("../../schema/index.js").ObjectSchema<{
46
- readonly id: string;
47
46
  readonly title: string | null;
47
+ readonly id: string;
48
48
  readonly download?: boolean | undefined;
49
49
  }>;
50
50
  result: import("../../schema/index.js").StringSchema;
@@ -406,8 +406,8 @@ declare const _DocumentManagementApi: import("../../api/index.js").ApiClient<{
406
406
  resource: string;
407
407
  method: "GET";
408
408
  parameters: import("../../schema/index.js").ObjectSchema<{
409
- readonly id: string;
410
409
  readonly title: string | null;
410
+ readonly id: string;
411
411
  readonly download?: boolean | undefined;
412
412
  }>;
413
413
  result: Uint8ArrayConstructor;
@@ -417,8 +417,8 @@ declare const _DocumentManagementApi: import("../../api/index.js").ApiClient<{
417
417
  resource: string;
418
418
  method: "GET";
419
419
  parameters: import("../../schema/index.js").ObjectSchema<{
420
- readonly id: string;
421
420
  readonly title: string | null;
421
+ readonly id: string;
422
422
  readonly download?: boolean | undefined;
423
423
  }>;
424
424
  result: import("../../schema/index.js").StringSchema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.92.31",
3
+ "version": "0.92.33",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -118,6 +118,7 @@
118
118
  "./utils/string": "./utils/string/index.js"
119
119
  },
120
120
  "dependencies": {
121
+ "@google-cloud/vertexai": "^1.9.2",
121
122
  "disposablestack": "1.1",
122
123
  "luxon": "^3.5",
123
124
  "reflect-metadata": "^0.2",
@@ -89,7 +89,6 @@ function convertToOpenApiSchemaBase(schema) {
89
89
  const enumSchema = convertToOpenApiSchema(schema.schema);
90
90
  return {
91
91
  ...enumSchema,
92
- enum: [...enumSchema.enum, null],
93
92
  nullable: true
94
93
  };
95
94
  }