@core-ai/google-genai 0.18.0 → 0.19.0
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/index.d.ts +12 -12
- package/dist/index.js +54 -19
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { GoogleGenAI } from '@google/genai';
|
|
2
|
-
import { ChatModel, EmbeddingModel, ImageModel
|
|
2
|
+
import { ModelCapabilities, ChatModel, EmbeddingModel, ImageModel } from '@core-ai/core-ai';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
|
+
type GoogleModelCapabilities = Omit<ModelCapabilities, 'reasoning'> & {
|
|
6
|
+
reasoning: ModelCapabilities['reasoning'] & {
|
|
7
|
+
thinkingParam: 'thinkingLevel' | 'thinkingBudget';
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
declare function getGoogleModelCapabilities(modelId: string): GoogleModelCapabilities;
|
|
11
|
+
|
|
12
|
+
type GoogleReasoningMetadata = {
|
|
13
|
+
thoughtSignature?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
5
16
|
type GoogleGenAIClient = {
|
|
6
17
|
models: GoogleGenAI['models'];
|
|
7
18
|
};
|
|
@@ -23,17 +34,6 @@ type GoogleGenAIProvider = {
|
|
|
23
34
|
declare function createGoogleGenAIProvider(options?: GoogleGenAIProviderBaseOptions, factoryOptions?: GoogleGenAIProviderFactoryOptions): GoogleGenAIProvider;
|
|
24
35
|
declare function createGoogleGenAI(options?: GoogleGenAIProviderOptions): GoogleGenAIProvider;
|
|
25
36
|
|
|
26
|
-
type GoogleReasoningMetadata = {
|
|
27
|
-
thoughtSignature?: string;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
type GoogleModelCapabilities = {
|
|
31
|
-
reasoning: ModelCapabilities['reasoning'] & {
|
|
32
|
-
thinkingParam: 'thinkingLevel' | 'thinkingBudget';
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
declare function getGoogleModelCapabilities(modelId: string): GoogleModelCapabilities;
|
|
36
|
-
|
|
37
37
|
declare const googleGenerateProviderOptionsSchema: z.ZodObject<{
|
|
38
38
|
stopSequences: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
39
39
|
frequencyPenalty: z.ZodOptional<z.ZodNumber>;
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
// src/provider.ts
|
|
2
2
|
import { GoogleGenAI } from "@google/genai";
|
|
3
3
|
|
|
4
|
-
// src/chat-model.ts
|
|
5
|
-
import {
|
|
6
|
-
StructuredOutputNoObjectGeneratedError,
|
|
7
|
-
StructuredOutputParseError,
|
|
8
|
-
StructuredOutputValidationError,
|
|
9
|
-
createObjectStream,
|
|
10
|
-
createChatStream
|
|
11
|
-
} from "@core-ai/core-ai";
|
|
12
|
-
|
|
13
4
|
// src/chat-adapter.ts
|
|
14
5
|
import {
|
|
15
6
|
FunctionCallingConfigMode
|
|
16
7
|
} from "@google/genai";
|
|
17
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
getProviderMetadata,
|
|
10
|
+
validateInputModalities,
|
|
11
|
+
zodSchemaToJsonSchema
|
|
12
|
+
} from "@core-ai/core-ai";
|
|
18
13
|
|
|
19
14
|
// src/model-capabilities.ts
|
|
20
15
|
import {
|
|
@@ -27,6 +22,10 @@ var ALL_EFFORTS = [
|
|
|
27
22
|
"high",
|
|
28
23
|
"max"
|
|
29
24
|
];
|
|
25
|
+
var GOOGLE_INPUT_MODALITIES = {
|
|
26
|
+
input: ["text", "image", "file", "audio"],
|
|
27
|
+
output: ["text"]
|
|
28
|
+
};
|
|
30
29
|
function createCapabilities(config) {
|
|
31
30
|
return {
|
|
32
31
|
reasoning: {
|
|
@@ -35,7 +34,8 @@ function createCapabilities(config) {
|
|
|
35
34
|
restrictsSamplingParams: false,
|
|
36
35
|
supportedToolChoices: ["auto", "none", "required", "tool"],
|
|
37
36
|
thinkingParam: config.thinkingParam
|
|
38
|
-
}
|
|
37
|
+
},
|
|
38
|
+
modalities: GOOGLE_INPUT_MODALITIES
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
var DEFAULT_CAPABILITIES = createCapabilities({
|
|
@@ -151,6 +151,7 @@ function parseGoogleImageProviderOptions(providerOptions) {
|
|
|
151
151
|
var googleProviderOptionsSchema = googleGenerateProviderOptionsSchema;
|
|
152
152
|
|
|
153
153
|
// src/chat-adapter.ts
|
|
154
|
+
var DEFAULT_PROVIDER_ID = "google";
|
|
154
155
|
var DEFAULT_STRUCTURED_OUTPUT_TOOL_NAME = "core_ai_generate_object";
|
|
155
156
|
var DEFAULT_STRUCTURED_OUTPUT_TOOL_DESCRIPTION = "Return a JSON object that matches the requested schema.";
|
|
156
157
|
function convertMessages(messages) {
|
|
@@ -254,6 +255,14 @@ function convertUserContentPart(part) {
|
|
|
254
255
|
}
|
|
255
256
|
};
|
|
256
257
|
}
|
|
258
|
+
if (part.type === "audio") {
|
|
259
|
+
return {
|
|
260
|
+
inlineData: {
|
|
261
|
+
data: part.source.data,
|
|
262
|
+
mimeType: part.source.mediaType
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
257
266
|
return {
|
|
258
267
|
inlineData: {
|
|
259
268
|
data: part.data,
|
|
@@ -361,17 +370,24 @@ function inferMimeTypeFromUrl(url) {
|
|
|
361
370
|
}
|
|
362
371
|
return "application/octet-stream";
|
|
363
372
|
}
|
|
364
|
-
function createGenerateRequest(modelId, options) {
|
|
373
|
+
function createGenerateRequest(modelId, options, provider = DEFAULT_PROVIDER_ID, adapterOptions = {}) {
|
|
365
374
|
const googleOptions = parseGoogleGenerateProviderOptions(
|
|
366
375
|
options.providerOptions
|
|
367
376
|
);
|
|
377
|
+
const capabilities = adapterOptions.capabilities ?? getGoogleModelCapabilities(modelId);
|
|
378
|
+
validateInputModalities({
|
|
379
|
+
messages: options.messages,
|
|
380
|
+
capabilities,
|
|
381
|
+
modelId,
|
|
382
|
+
providerId: provider
|
|
383
|
+
});
|
|
368
384
|
const convertedMessages = convertMessages(options.messages);
|
|
369
385
|
const requestConfig = {
|
|
370
386
|
...convertedMessages.systemInstruction ? { systemInstruction: convertedMessages.systemInstruction } : {},
|
|
371
387
|
...options.tools && Object.keys(options.tools).length > 0 ? { tools: convertTools(options.tools) } : {},
|
|
372
388
|
...options.toolChoice ? { toolConfig: convertToolChoice(options.toolChoice) } : {},
|
|
373
389
|
...mapSamplingToConfig(options),
|
|
374
|
-
...mapReasoningToConfig(
|
|
390
|
+
...mapReasoningToConfig(options, capabilities),
|
|
375
391
|
...mapGoogleProviderOptionsToConfig(googleOptions),
|
|
376
392
|
...options.signal ? { abortSignal: options.signal } : {}
|
|
377
393
|
};
|
|
@@ -572,11 +588,10 @@ async function* transformStream(stream) {
|
|
|
572
588
|
usage
|
|
573
589
|
};
|
|
574
590
|
}
|
|
575
|
-
function mapReasoningToConfig(
|
|
591
|
+
function mapReasoningToConfig(options, capabilities) {
|
|
576
592
|
if (!options.reasoning) {
|
|
577
593
|
return {};
|
|
578
594
|
}
|
|
579
|
-
const capabilities = getGoogleModelCapabilities(modelId);
|
|
580
595
|
if (capabilities.reasoning.thinkingParam === "thinkingLevel") {
|
|
581
596
|
return {
|
|
582
597
|
thinkingConfig: {
|
|
@@ -681,6 +696,15 @@ function mapUsage(response, fallback) {
|
|
|
681
696
|
};
|
|
682
697
|
}
|
|
683
698
|
|
|
699
|
+
// src/chat-model.ts
|
|
700
|
+
import {
|
|
701
|
+
StructuredOutputNoObjectGeneratedError,
|
|
702
|
+
StructuredOutputParseError,
|
|
703
|
+
StructuredOutputValidationError,
|
|
704
|
+
createObjectStream,
|
|
705
|
+
createChatStream
|
|
706
|
+
} from "@core-ai/core-ai";
|
|
707
|
+
|
|
684
708
|
// src/google-error.ts
|
|
685
709
|
import { ApiError } from "@google/genai";
|
|
686
710
|
import {
|
|
@@ -814,6 +838,8 @@ function toNumericHttpCode(body) {
|
|
|
814
838
|
|
|
815
839
|
// src/chat-model.ts
|
|
816
840
|
function createGoogleGenAIChatModel(client, modelId, provider = "google") {
|
|
841
|
+
const capabilities = getGoogleModelCapabilities(modelId);
|
|
842
|
+
const adapterOptions = { capabilities };
|
|
817
843
|
async function callGenerateContentApi(request) {
|
|
818
844
|
try {
|
|
819
845
|
return await client.models.generateContent(request);
|
|
@@ -829,12 +855,22 @@ function createGoogleGenAIChatModel(client, modelId, provider = "google") {
|
|
|
829
855
|
}
|
|
830
856
|
}
|
|
831
857
|
async function generateChat(options) {
|
|
832
|
-
const request = createGenerateRequest(
|
|
858
|
+
const request = createGenerateRequest(
|
|
859
|
+
modelId,
|
|
860
|
+
options,
|
|
861
|
+
provider,
|
|
862
|
+
adapterOptions
|
|
863
|
+
);
|
|
833
864
|
const response = await callGenerateContentApi(request);
|
|
834
865
|
return mapGenerateResponse(response);
|
|
835
866
|
}
|
|
836
867
|
async function streamChat(options) {
|
|
837
|
-
const request = createGenerateRequest(
|
|
868
|
+
const request = createGenerateRequest(
|
|
869
|
+
modelId,
|
|
870
|
+
options,
|
|
871
|
+
provider,
|
|
872
|
+
adapterOptions
|
|
873
|
+
);
|
|
838
874
|
return createChatStream(
|
|
839
875
|
async () => transformStream(await callGenerateContentStreamApi(request)),
|
|
840
876
|
{ signal: options.signal }
|
|
@@ -843,7 +879,7 @@ function createGoogleGenAIChatModel(client, modelId, provider = "google") {
|
|
|
843
879
|
return {
|
|
844
880
|
provider,
|
|
845
881
|
modelId,
|
|
846
|
-
capabilities
|
|
882
|
+
capabilities,
|
|
847
883
|
generate: generateChat,
|
|
848
884
|
stream: streamChat,
|
|
849
885
|
async generateObject(options) {
|
|
@@ -1247,7 +1283,6 @@ function greatestCommonDivisor(a, b) {
|
|
|
1247
1283
|
}
|
|
1248
1284
|
|
|
1249
1285
|
// src/provider.ts
|
|
1250
|
-
var DEFAULT_PROVIDER_ID = "google";
|
|
1251
1286
|
function createGoogleGenAIProvider(options = {}, factoryOptions = {}) {
|
|
1252
1287
|
const client = options.client ?? new GoogleGenAI({
|
|
1253
1288
|
apiKey: options.apiKey,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@core-ai/google-genai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "Google GenAI provider package for @core-ai/core-ai",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Omnifact (https://omnifact.ai)",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"test:watch": "vitest"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@core-ai/core-ai": "^0.
|
|
48
|
+
"@core-ai/core-ai": "^0.19.0",
|
|
49
49
|
"@google/genai": "^1.42.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|