smoltalk 0.0.4 → 0.0.6
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/classes/ToolCall.d.ts +5 -0
- package/dist/classes/ToolCall.js +18 -0
- package/dist/classes/message/AssistantMessage.d.ts +4 -6
- package/dist/classes/message/AssistantMessage.js +20 -11
- package/dist/classes/message/ToolMessage.d.ts +3 -1
- package/dist/classes/message/ToolMessage.js +13 -2
- package/dist/classes/message/UserMessage.js +5 -1
- package/dist/classes/message/index.d.ts +2 -2
- package/dist/client.js +6 -1
- package/dist/clients/google.js +37 -6
- package/dist/clients/openai.js +8 -6
- package/dist/logger.js +1 -0
- package/dist/models.d.ts +178 -8
- package/dist/models.js +98 -4
- package/dist/types.d.ts +10 -4
- package/dist/types.js +6 -0
- package/dist/util/common.d.ts +54 -0
- package/dist/util/common.js +75 -0
- package/package.json +4 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FunctionCall } from "@google/genai";
|
|
1
2
|
export type ToolCallOptions = {};
|
|
2
3
|
export declare class ToolCall {
|
|
3
4
|
private _id;
|
|
@@ -8,4 +9,8 @@ export declare class ToolCall {
|
|
|
8
9
|
get id(): string;
|
|
9
10
|
get name(): string;
|
|
10
11
|
get arguments(): Record<string, any>;
|
|
12
|
+
toOpenAI(): any;
|
|
13
|
+
toGoogle(): {
|
|
14
|
+
functionCall: FunctionCall;
|
|
15
|
+
};
|
|
11
16
|
}
|
package/dist/classes/ToolCall.js
CHANGED
|
@@ -30,4 +30,22 @@ export class ToolCall {
|
|
|
30
30
|
get arguments() {
|
|
31
31
|
return this._arguments;
|
|
32
32
|
}
|
|
33
|
+
toOpenAI() {
|
|
34
|
+
return {
|
|
35
|
+
id: this._id,
|
|
36
|
+
type: "function",
|
|
37
|
+
function: {
|
|
38
|
+
name: this.name,
|
|
39
|
+
arguments: JSON.stringify(this.arguments),
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
toGoogle() {
|
|
44
|
+
return {
|
|
45
|
+
functionCall: {
|
|
46
|
+
name: this.name,
|
|
47
|
+
args: this.arguments,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
33
51
|
}
|
|
@@ -2,30 +2,28 @@ import { BaseMessage, MessageClass } from "./BaseMessage.js";
|
|
|
2
2
|
import { TextPart } from "../../types.js";
|
|
3
3
|
import { ChatCompletionMessageParam } from "openai/resources";
|
|
4
4
|
import { Content } from "@google/genai";
|
|
5
|
+
import { ToolCall } from "../ToolCall.js";
|
|
5
6
|
export declare class AssistantMessage extends BaseMessage implements MessageClass {
|
|
6
7
|
_role: "assistant";
|
|
7
8
|
_content: string | Array<TextPart> | null;
|
|
8
9
|
_name?: string;
|
|
9
10
|
_audio?: any | null;
|
|
10
|
-
_function_call?: any | null;
|
|
11
11
|
_refusal?: string | null;
|
|
12
|
-
|
|
12
|
+
_toolCalls?: ToolCall[];
|
|
13
13
|
_rawData?: any;
|
|
14
14
|
constructor(content: string | Array<TextPart> | null, options?: {
|
|
15
15
|
name?: string;
|
|
16
16
|
audio?: any | null;
|
|
17
|
-
function_call?: any | null;
|
|
18
17
|
refusal?: string | null;
|
|
19
|
-
|
|
18
|
+
toolCalls?: ToolCall[];
|
|
20
19
|
rawData?: any;
|
|
21
20
|
});
|
|
22
21
|
get content(): string;
|
|
23
22
|
get role(): "assistant";
|
|
24
23
|
get name(): string | undefined;
|
|
25
24
|
get audio(): any | null | undefined;
|
|
26
|
-
get function_call(): any | null | undefined;
|
|
27
25
|
get refusal(): string | null | undefined;
|
|
28
|
-
get
|
|
26
|
+
get toolCalls(): ToolCall[] | undefined;
|
|
29
27
|
get rawData(): any;
|
|
30
28
|
toOpenAIMessage(): ChatCompletionMessageParam;
|
|
31
29
|
toGoogleMessage(): Content;
|
|
@@ -4,18 +4,16 @@ export class AssistantMessage extends BaseMessage {
|
|
|
4
4
|
_content;
|
|
5
5
|
_name;
|
|
6
6
|
_audio;
|
|
7
|
-
_function_call;
|
|
8
7
|
_refusal;
|
|
9
|
-
|
|
8
|
+
_toolCalls;
|
|
10
9
|
_rawData;
|
|
11
10
|
constructor(content, options = {}) {
|
|
12
11
|
super();
|
|
13
12
|
this._content = content;
|
|
14
13
|
this._name = options.name;
|
|
15
14
|
this._audio = options.audio;
|
|
16
|
-
this._function_call = options.function_call;
|
|
17
15
|
this._refusal = options.refusal;
|
|
18
|
-
this.
|
|
16
|
+
this._toolCalls = options.toolCalls;
|
|
19
17
|
this._rawData = options.rawData;
|
|
20
18
|
}
|
|
21
19
|
get content() {
|
|
@@ -35,22 +33,33 @@ export class AssistantMessage extends BaseMessage {
|
|
|
35
33
|
get audio() {
|
|
36
34
|
return this._audio;
|
|
37
35
|
}
|
|
38
|
-
get function_call() {
|
|
39
|
-
return this._function_call;
|
|
40
|
-
}
|
|
41
36
|
get refusal() {
|
|
42
37
|
return this._refusal;
|
|
43
38
|
}
|
|
44
|
-
get
|
|
45
|
-
return this.
|
|
39
|
+
get toolCalls() {
|
|
40
|
+
return this._toolCalls;
|
|
46
41
|
}
|
|
47
42
|
get rawData() {
|
|
48
43
|
return this._rawData;
|
|
49
44
|
}
|
|
50
45
|
toOpenAIMessage() {
|
|
51
|
-
return {
|
|
46
|
+
return {
|
|
47
|
+
role: this.role,
|
|
48
|
+
content: this.content,
|
|
49
|
+
name: this.name,
|
|
50
|
+
tool_calls: this.toolCalls?.map((tc) => tc.toOpenAI()),
|
|
51
|
+
};
|
|
52
52
|
}
|
|
53
53
|
toGoogleMessage() {
|
|
54
|
-
|
|
54
|
+
const parts = [];
|
|
55
|
+
if (this.content) {
|
|
56
|
+
parts.push({ text: this.content });
|
|
57
|
+
}
|
|
58
|
+
if (this.toolCalls) {
|
|
59
|
+
for (const tc of this.toolCalls) {
|
|
60
|
+
parts.push(tc.toGoogle());
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return { role: "model", parts };
|
|
55
64
|
}
|
|
56
65
|
}
|
|
@@ -7,13 +7,15 @@ export declare class ToolMessage extends BaseMessage implements MessageClass {
|
|
|
7
7
|
_content: string | Array<TextPart>;
|
|
8
8
|
_tool_call_id: string;
|
|
9
9
|
_rawData?: any;
|
|
10
|
+
_name: string;
|
|
10
11
|
constructor(content: string | Array<TextPart>, options: {
|
|
11
12
|
tool_call_id: string;
|
|
12
13
|
rawData?: any;
|
|
14
|
+
name: string;
|
|
13
15
|
});
|
|
14
16
|
get content(): string;
|
|
15
17
|
get role(): "tool";
|
|
16
|
-
get name(): string
|
|
18
|
+
get name(): string;
|
|
17
19
|
get tool_call_id(): string;
|
|
18
20
|
get rawData(): any;
|
|
19
21
|
toOpenAIMessage(): ChatCompletionMessageParam;
|
|
@@ -4,11 +4,13 @@ export class ToolMessage extends BaseMessage {
|
|
|
4
4
|
_content;
|
|
5
5
|
_tool_call_id;
|
|
6
6
|
_rawData;
|
|
7
|
+
_name;
|
|
7
8
|
constructor(content, options) {
|
|
8
9
|
super();
|
|
9
10
|
this._content = content;
|
|
10
11
|
this._tool_call_id = options.tool_call_id;
|
|
11
12
|
this._rawData = options.rawData;
|
|
13
|
+
this._name = options.name;
|
|
12
14
|
}
|
|
13
15
|
get content() {
|
|
14
16
|
return typeof this._content === "string"
|
|
@@ -19,7 +21,7 @@ export class ToolMessage extends BaseMessage {
|
|
|
19
21
|
return this._role;
|
|
20
22
|
}
|
|
21
23
|
get name() {
|
|
22
|
-
return
|
|
24
|
+
return this._name;
|
|
23
25
|
}
|
|
24
26
|
get tool_call_id() {
|
|
25
27
|
return this._tool_call_id;
|
|
@@ -35,6 +37,15 @@ export class ToolMessage extends BaseMessage {
|
|
|
35
37
|
};
|
|
36
38
|
}
|
|
37
39
|
toGoogleMessage() {
|
|
38
|
-
return {
|
|
40
|
+
return {
|
|
41
|
+
role: "user", parts: [{
|
|
42
|
+
functionResponse: {
|
|
43
|
+
name: this.name,
|
|
44
|
+
response: {
|
|
45
|
+
result: this.content
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}]
|
|
49
|
+
};
|
|
39
50
|
}
|
|
40
51
|
}
|
|
@@ -23,7 +23,11 @@ export class UserMessage extends BaseMessage {
|
|
|
23
23
|
return this._rawData;
|
|
24
24
|
}
|
|
25
25
|
toOpenAIMessage() {
|
|
26
|
-
return {
|
|
26
|
+
return {
|
|
27
|
+
role: this.role,
|
|
28
|
+
content: this.content,
|
|
29
|
+
name: this.name,
|
|
30
|
+
};
|
|
27
31
|
}
|
|
28
32
|
toGoogleMessage() {
|
|
29
33
|
return { role: this.role, parts: [{ text: this.content }] };
|
|
@@ -17,9 +17,8 @@ export declare function userMessage(content: string, options?: {
|
|
|
17
17
|
export declare function assistantMessage(content: string | Array<TextPart> | null, options?: {
|
|
18
18
|
name?: string;
|
|
19
19
|
audio?: any | null;
|
|
20
|
-
function_call?: any | null;
|
|
21
20
|
refusal?: string | null;
|
|
22
|
-
|
|
21
|
+
toolCalls?: Array<any>;
|
|
23
22
|
rawData?: any;
|
|
24
23
|
}): AssistantMessage;
|
|
25
24
|
export declare function developerMessage(content: string | Array<TextPart>, options?: {
|
|
@@ -33,5 +32,6 @@ export declare function systemMessage(content: string | Array<TextPart>, options
|
|
|
33
32
|
export declare function toolMessage(content: string | Array<TextPart>, options: {
|
|
34
33
|
tool_call_id: string;
|
|
35
34
|
rawData?: any;
|
|
35
|
+
name: string;
|
|
36
36
|
}): ToolMessage;
|
|
37
37
|
export type Message = ToolMessage | UserMessage | AssistantMessage | DeveloperMessage | SystemMessage;
|
package/dist/client.js
CHANGED
|
@@ -4,8 +4,13 @@ import { SmolGoogle } from "./clients/google.js";
|
|
|
4
4
|
import { SmolOpenAi } from "./clients/openai.js";
|
|
5
5
|
import { getModel, isTextModel } from "./models.js";
|
|
6
6
|
import { SmolError } from "./smolError.js";
|
|
7
|
+
import { getLogger } from "./logger.js";
|
|
7
8
|
export function getClient(config) {
|
|
8
|
-
|
|
9
|
+
if (!config.openAiApiKey && !config.googleApiKey) {
|
|
10
|
+
throw new SmolError("No API key provided. Please provide an OpenAI or Google API key in the config using openAiApiKey or googleApiKey.");
|
|
11
|
+
}
|
|
12
|
+
// Initialize logger singleton with desired log level
|
|
13
|
+
const logger = getLogger(config.logLevel);
|
|
9
14
|
const model = getModel(config.model);
|
|
10
15
|
if (model === undefined || !isTextModel(model)) {
|
|
11
16
|
throw new SmolError(`Only text models are supported currently. ${config.model} is a ${model?.type} model.`);
|
package/dist/clients/google.js
CHANGED
|
@@ -2,13 +2,18 @@ import { GoogleGenAI } from "@google/genai";
|
|
|
2
2
|
import { getLogger } from "../logger.js";
|
|
3
3
|
import { success, } from "../types.js";
|
|
4
4
|
import { BaseClient } from "./baseClient.js";
|
|
5
|
+
import { ToolCall } from "../classes/ToolCall.js";
|
|
6
|
+
import { convertOpenAIToolToGoogle } from "../util/common.js";
|
|
5
7
|
export class SmolGoogle extends BaseClient {
|
|
6
8
|
client;
|
|
7
9
|
logger;
|
|
8
10
|
model;
|
|
9
11
|
constructor(config) {
|
|
10
12
|
super();
|
|
11
|
-
|
|
13
|
+
if (!config.googleApiKey) {
|
|
14
|
+
throw new Error("Google API key is required for SmolGoogle client.");
|
|
15
|
+
}
|
|
16
|
+
this.client = new GoogleGenAI({ apiKey: config.googleApiKey });
|
|
12
17
|
this.logger = getLogger();
|
|
13
18
|
this.model = config.model;
|
|
14
19
|
}
|
|
@@ -17,14 +22,40 @@ export class SmolGoogle extends BaseClient {
|
|
|
17
22
|
}
|
|
18
23
|
async text(config) {
|
|
19
24
|
const messages = config.messages.map((msg) => msg.toGoogleMessage());
|
|
20
|
-
|
|
21
|
-
const
|
|
25
|
+
const tools = (config.tools || []).map((tool) => convertOpenAIToolToGoogle(tool));
|
|
26
|
+
const genConfig = {};
|
|
27
|
+
if (tools.length > 0) {
|
|
28
|
+
genConfig.tools = [{ functionDeclarations: tools }];
|
|
29
|
+
}
|
|
30
|
+
if (config.responseFormat && config.responseFormat.type === "json_schema") {
|
|
31
|
+
genConfig.responseMimeType = "application/json";
|
|
32
|
+
genConfig.responseJsonSchema = config.responseFormat.json_schema.schema;
|
|
33
|
+
}
|
|
34
|
+
const request = {
|
|
22
35
|
contents: messages,
|
|
23
36
|
model: this.model,
|
|
24
|
-
|
|
25
|
-
|
|
37
|
+
config: genConfig,
|
|
38
|
+
};
|
|
39
|
+
if (config.rawAttributes) {
|
|
40
|
+
Object.assign(request, config.rawAttributes);
|
|
41
|
+
}
|
|
42
|
+
this.logger.debug("Sending request to Google Gemini:", JSON.stringify(request, null, 2));
|
|
43
|
+
// Send the prompt as the latest message
|
|
44
|
+
const result = await this.client.models.generateContent(request);
|
|
45
|
+
this.logger.debug("Response from Google Gemini:", JSON.stringify(result, null, 2));
|
|
26
46
|
const text = result.text || null;
|
|
47
|
+
const toolCalls = [];
|
|
48
|
+
result.candidates?.forEach((candidate) => {
|
|
49
|
+
if (candidate.content && candidate.content.parts) {
|
|
50
|
+
candidate.content.parts.forEach((part) => {
|
|
51
|
+
if (part.functionCall) {
|
|
52
|
+
const functionCall = part.functionCall;
|
|
53
|
+
toolCalls.push(new ToolCall("", functionCall.name, functionCall.args));
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
27
58
|
// Return the response, updating the chat history
|
|
28
|
-
return success({ output: text, toolCalls
|
|
59
|
+
return success({ output: text, toolCalls });
|
|
29
60
|
}
|
|
30
61
|
}
|
package/dist/clients/openai.js
CHANGED
|
@@ -10,7 +10,10 @@ export class SmolOpenAi extends BaseClient {
|
|
|
10
10
|
model;
|
|
11
11
|
constructor(config) {
|
|
12
12
|
super();
|
|
13
|
-
|
|
13
|
+
if (!config.openAiApiKey) {
|
|
14
|
+
throw new Error("OpenAI API key is required for SmolOpenAi client.");
|
|
15
|
+
}
|
|
16
|
+
this.client = new OpenAI({ apiKey: config.openAiApiKey });
|
|
14
17
|
this.logger = getLogger();
|
|
15
18
|
this.model = config.model;
|
|
16
19
|
}
|
|
@@ -19,12 +22,14 @@ export class SmolOpenAi extends BaseClient {
|
|
|
19
22
|
}
|
|
20
23
|
async text(config) {
|
|
21
24
|
const messages = config.messages.map((msg) => msg.toOpenAIMessage());
|
|
22
|
-
const
|
|
25
|
+
const request = {
|
|
23
26
|
model: this.model,
|
|
24
27
|
messages,
|
|
25
28
|
tools: config.tools,
|
|
26
29
|
response_format: config.responseFormat,
|
|
27
|
-
}
|
|
30
|
+
};
|
|
31
|
+
this.logger.debug("Sending request to OpenAI:", JSON.stringify(request, null, 2));
|
|
32
|
+
const completion = await this.client.chat.completions.create(request);
|
|
28
33
|
this.logger.debug("Response from OpenAI:", JSON.stringify(completion, null, 2));
|
|
29
34
|
const message = completion.choices[0].message;
|
|
30
35
|
const output = message.content;
|
|
@@ -40,9 +45,6 @@ export class SmolOpenAi extends BaseClient {
|
|
|
40
45
|
}
|
|
41
46
|
}
|
|
42
47
|
}
|
|
43
|
-
if (toolCalls.length > 0) {
|
|
44
|
-
this.logger.debug("Tool calls detected:", toolCalls);
|
|
45
|
-
}
|
|
46
48
|
return success({ output, toolCalls });
|
|
47
49
|
}
|
|
48
50
|
}
|
package/dist/logger.js
CHANGED
package/dist/models.d.ts
CHANGED
|
@@ -60,6 +60,16 @@ export declare const textModels: readonly [{
|
|
|
60
60
|
readonly cachedInputTokenCost: 1.25;
|
|
61
61
|
readonly outputTokenCost: 10;
|
|
62
62
|
readonly source: "openai";
|
|
63
|
+
}, {
|
|
64
|
+
readonly type: "text";
|
|
65
|
+
readonly modelName: "o3";
|
|
66
|
+
readonly description: "o3 is a reasoning model that sets a new standard for math, science, and coding, visual reasoning tasks, and technical writing. Part of the o-series of reasoning models. The knowledge cutoff for o3 models is October, 2023.";
|
|
67
|
+
readonly maxInputTokens: 200000;
|
|
68
|
+
readonly maxOutputTokens: 100000;
|
|
69
|
+
readonly inputTokenCost: 2;
|
|
70
|
+
readonly cachedInputTokenCost: 1;
|
|
71
|
+
readonly outputTokenCost: 8;
|
|
72
|
+
readonly source: "openai";
|
|
63
73
|
}, {
|
|
64
74
|
readonly type: "text";
|
|
65
75
|
readonly modelName: "o3-mini";
|
|
@@ -70,6 +80,26 @@ export declare const textModels: readonly [{
|
|
|
70
80
|
readonly cachedInputTokenCost: 0.55;
|
|
71
81
|
readonly outputTokenCost: 4.4;
|
|
72
82
|
readonly source: "openai";
|
|
83
|
+
}, {
|
|
84
|
+
readonly type: "text";
|
|
85
|
+
readonly modelName: "o4-mini";
|
|
86
|
+
readonly description: "o4-mini is a new o-series reasoning model that replaced o3-mini, providing excellent performance for math, science, and coding tasks. Available in ChatGPT Plus, Pro, and Team.";
|
|
87
|
+
readonly maxInputTokens: 200000;
|
|
88
|
+
readonly maxOutputTokens: 100000;
|
|
89
|
+
readonly inputTokenCost: 1.1;
|
|
90
|
+
readonly cachedInputTokenCost: 0.55;
|
|
91
|
+
readonly outputTokenCost: 4.4;
|
|
92
|
+
readonly source: "openai";
|
|
93
|
+
}, {
|
|
94
|
+
readonly type: "text";
|
|
95
|
+
readonly modelName: "o1";
|
|
96
|
+
readonly description: "o1 is a reasoning model designed to excel at complex reasoning tasks including science, math, and coding. The knowledge cutoff for o1 models is October, 2023.";
|
|
97
|
+
readonly maxInputTokens: 200000;
|
|
98
|
+
readonly maxOutputTokens: 100000;
|
|
99
|
+
readonly inputTokenCost: 15;
|
|
100
|
+
readonly cachedInputTokenCost: 7.5;
|
|
101
|
+
readonly outputTokenCost: 60;
|
|
102
|
+
readonly source: "openai";
|
|
73
103
|
}, {
|
|
74
104
|
readonly type: "text";
|
|
75
105
|
readonly modelName: "gpt-4-turbo";
|
|
@@ -100,14 +130,69 @@ export declare const textModels: readonly [{
|
|
|
100
130
|
readonly outputTokenCost: 1.5;
|
|
101
131
|
readonly disabled: true;
|
|
102
132
|
readonly source: "openai";
|
|
133
|
+
}, {
|
|
134
|
+
readonly type: "text";
|
|
135
|
+
readonly modelName: "gpt-4.1";
|
|
136
|
+
readonly description: "GPT-4.1 supports up to 1 million tokens of context, representing a significant increase in context window capacity. Ideal for processing large documents and extended conversations.";
|
|
137
|
+
readonly maxInputTokens: 1047576;
|
|
138
|
+
readonly maxOutputTokens: 32768;
|
|
139
|
+
readonly inputTokenCost: 2.5;
|
|
140
|
+
readonly cachedInputTokenCost: 1.25;
|
|
141
|
+
readonly outputTokenCost: 10;
|
|
142
|
+
readonly source: "openai";
|
|
143
|
+
}, {
|
|
144
|
+
readonly type: "text";
|
|
145
|
+
readonly modelName: "gemini-3-pro-preview";
|
|
146
|
+
readonly description: "Strongest Gemini 3 model quality with 2M context window. Standard pricing for ≤200k tokens, higher rates for >200k tokens.";
|
|
147
|
+
readonly maxInputTokens: 2097152;
|
|
148
|
+
readonly maxOutputTokens: 8192;
|
|
149
|
+
readonly inputTokenCost: 2;
|
|
150
|
+
readonly outputTokenCost: 12;
|
|
151
|
+
readonly source: "google";
|
|
152
|
+
}, {
|
|
153
|
+
readonly type: "text";
|
|
154
|
+
readonly modelName: "gemini-3-flash-preview";
|
|
155
|
+
readonly description: "Latest Gemini 3 flash model with 1M context window. Excellent performance for high-volume tasks.";
|
|
156
|
+
readonly maxInputTokens: 1048576;
|
|
157
|
+
readonly maxOutputTokens: 8192;
|
|
158
|
+
readonly inputTokenCost: 0.5;
|
|
159
|
+
readonly outputTokenCost: 3;
|
|
160
|
+
readonly source: "google";
|
|
161
|
+
}, {
|
|
162
|
+
readonly type: "text";
|
|
163
|
+
readonly modelName: "gemini-2.5-pro";
|
|
164
|
+
readonly description: "High-performance Gemini 2.5 model with 2M context window. Standard pricing for ≤200k tokens, higher rates for >200k tokens.";
|
|
165
|
+
readonly maxInputTokens: 2097152;
|
|
166
|
+
readonly maxOutputTokens: 8192;
|
|
167
|
+
readonly inputTokenCost: 1.25;
|
|
168
|
+
readonly outputTokenCost: 10;
|
|
169
|
+
readonly source: "google";
|
|
170
|
+
}, {
|
|
171
|
+
readonly type: "text";
|
|
172
|
+
readonly modelName: "gemini-2.5-flash";
|
|
173
|
+
readonly description: "Balanced Gemini 2.5 model with excellent performance-to-cost ratio. 1M context window with free tier available.";
|
|
174
|
+
readonly maxInputTokens: 1048576;
|
|
175
|
+
readonly maxOutputTokens: 8192;
|
|
176
|
+
readonly inputTokenCost: 0.3;
|
|
177
|
+
readonly outputTokenCost: 2.5;
|
|
178
|
+
readonly source: "google";
|
|
179
|
+
}, {
|
|
180
|
+
readonly type: "text";
|
|
181
|
+
readonly modelName: "gemini-2.5-flash-lite";
|
|
182
|
+
readonly description: "Most cost-effective Gemini 2.5 option for high-throughput applications. 1M context window.";
|
|
183
|
+
readonly maxInputTokens: 1048576;
|
|
184
|
+
readonly maxOutputTokens: 8192;
|
|
185
|
+
readonly inputTokenCost: 0.1;
|
|
186
|
+
readonly outputTokenCost: 0.4;
|
|
187
|
+
readonly source: "google";
|
|
103
188
|
}, {
|
|
104
189
|
readonly type: "text";
|
|
105
190
|
readonly modelName: "gemini-2.0-flash";
|
|
106
|
-
readonly description: "Workhorse model for all daily tasks. Strong overall performance and supports real-time streaming Live API";
|
|
191
|
+
readonly description: "Workhorse model for all daily tasks. Strong overall performance and supports real-time streaming Live API. 1M context window.";
|
|
107
192
|
readonly maxInputTokens: 1048576;
|
|
108
193
|
readonly maxOutputTokens: 8192;
|
|
109
|
-
readonly inputTokenCost: 0.
|
|
110
|
-
readonly outputTokenCost: 0.
|
|
194
|
+
readonly inputTokenCost: 0.1;
|
|
195
|
+
readonly outputTokenCost: 0.4;
|
|
111
196
|
readonly source: "google";
|
|
112
197
|
}, {
|
|
113
198
|
readonly type: "text";
|
|
@@ -122,7 +207,7 @@ export declare const textModels: readonly [{
|
|
|
122
207
|
}, {
|
|
123
208
|
readonly type: "text";
|
|
124
209
|
readonly modelName: "gemini-2.0-flash-lite";
|
|
125
|
-
readonly description: "
|
|
210
|
+
readonly description: "Cost effective offering to support high throughput. Note: May be deprecated in favor of 2.5-flash-lite.";
|
|
126
211
|
readonly maxInputTokens: 1048576;
|
|
127
212
|
readonly maxOutputTokens: 8192;
|
|
128
213
|
readonly inputTokenCost: 0.075;
|
|
@@ -277,6 +362,16 @@ export declare function getModel(modelName: ModelName): {
|
|
|
277
362
|
readonly cachedInputTokenCost: 1.25;
|
|
278
363
|
readonly outputTokenCost: 10;
|
|
279
364
|
readonly source: "openai";
|
|
365
|
+
} | {
|
|
366
|
+
readonly type: "text";
|
|
367
|
+
readonly modelName: "o3";
|
|
368
|
+
readonly description: "o3 is a reasoning model that sets a new standard for math, science, and coding, visual reasoning tasks, and technical writing. Part of the o-series of reasoning models. The knowledge cutoff for o3 models is October, 2023.";
|
|
369
|
+
readonly maxInputTokens: 200000;
|
|
370
|
+
readonly maxOutputTokens: 100000;
|
|
371
|
+
readonly inputTokenCost: 2;
|
|
372
|
+
readonly cachedInputTokenCost: 1;
|
|
373
|
+
readonly outputTokenCost: 8;
|
|
374
|
+
readonly source: "openai";
|
|
280
375
|
} | {
|
|
281
376
|
readonly type: "text";
|
|
282
377
|
readonly modelName: "o3-mini";
|
|
@@ -287,6 +382,26 @@ export declare function getModel(modelName: ModelName): {
|
|
|
287
382
|
readonly cachedInputTokenCost: 0.55;
|
|
288
383
|
readonly outputTokenCost: 4.4;
|
|
289
384
|
readonly source: "openai";
|
|
385
|
+
} | {
|
|
386
|
+
readonly type: "text";
|
|
387
|
+
readonly modelName: "o4-mini";
|
|
388
|
+
readonly description: "o4-mini is a new o-series reasoning model that replaced o3-mini, providing excellent performance for math, science, and coding tasks. Available in ChatGPT Plus, Pro, and Team.";
|
|
389
|
+
readonly maxInputTokens: 200000;
|
|
390
|
+
readonly maxOutputTokens: 100000;
|
|
391
|
+
readonly inputTokenCost: 1.1;
|
|
392
|
+
readonly cachedInputTokenCost: 0.55;
|
|
393
|
+
readonly outputTokenCost: 4.4;
|
|
394
|
+
readonly source: "openai";
|
|
395
|
+
} | {
|
|
396
|
+
readonly type: "text";
|
|
397
|
+
readonly modelName: "o1";
|
|
398
|
+
readonly description: "o1 is a reasoning model designed to excel at complex reasoning tasks including science, math, and coding. The knowledge cutoff for o1 models is October, 2023.";
|
|
399
|
+
readonly maxInputTokens: 200000;
|
|
400
|
+
readonly maxOutputTokens: 100000;
|
|
401
|
+
readonly inputTokenCost: 15;
|
|
402
|
+
readonly cachedInputTokenCost: 7.5;
|
|
403
|
+
readonly outputTokenCost: 60;
|
|
404
|
+
readonly source: "openai";
|
|
290
405
|
} | {
|
|
291
406
|
readonly type: "text";
|
|
292
407
|
readonly modelName: "gpt-4-turbo";
|
|
@@ -317,14 +432,69 @@ export declare function getModel(modelName: ModelName): {
|
|
|
317
432
|
readonly outputTokenCost: 1.5;
|
|
318
433
|
readonly disabled: true;
|
|
319
434
|
readonly source: "openai";
|
|
435
|
+
} | {
|
|
436
|
+
readonly type: "text";
|
|
437
|
+
readonly modelName: "gpt-4.1";
|
|
438
|
+
readonly description: "GPT-4.1 supports up to 1 million tokens of context, representing a significant increase in context window capacity. Ideal for processing large documents and extended conversations.";
|
|
439
|
+
readonly maxInputTokens: 1047576;
|
|
440
|
+
readonly maxOutputTokens: 32768;
|
|
441
|
+
readonly inputTokenCost: 2.5;
|
|
442
|
+
readonly cachedInputTokenCost: 1.25;
|
|
443
|
+
readonly outputTokenCost: 10;
|
|
444
|
+
readonly source: "openai";
|
|
445
|
+
} | {
|
|
446
|
+
readonly type: "text";
|
|
447
|
+
readonly modelName: "gemini-3-pro-preview";
|
|
448
|
+
readonly description: "Strongest Gemini 3 model quality with 2M context window. Standard pricing for ≤200k tokens, higher rates for >200k tokens.";
|
|
449
|
+
readonly maxInputTokens: 2097152;
|
|
450
|
+
readonly maxOutputTokens: 8192;
|
|
451
|
+
readonly inputTokenCost: 2;
|
|
452
|
+
readonly outputTokenCost: 12;
|
|
453
|
+
readonly source: "google";
|
|
454
|
+
} | {
|
|
455
|
+
readonly type: "text";
|
|
456
|
+
readonly modelName: "gemini-3-flash-preview";
|
|
457
|
+
readonly description: "Latest Gemini 3 flash model with 1M context window. Excellent performance for high-volume tasks.";
|
|
458
|
+
readonly maxInputTokens: 1048576;
|
|
459
|
+
readonly maxOutputTokens: 8192;
|
|
460
|
+
readonly inputTokenCost: 0.5;
|
|
461
|
+
readonly outputTokenCost: 3;
|
|
462
|
+
readonly source: "google";
|
|
463
|
+
} | {
|
|
464
|
+
readonly type: "text";
|
|
465
|
+
readonly modelName: "gemini-2.5-pro";
|
|
466
|
+
readonly description: "High-performance Gemini 2.5 model with 2M context window. Standard pricing for ≤200k tokens, higher rates for >200k tokens.";
|
|
467
|
+
readonly maxInputTokens: 2097152;
|
|
468
|
+
readonly maxOutputTokens: 8192;
|
|
469
|
+
readonly inputTokenCost: 1.25;
|
|
470
|
+
readonly outputTokenCost: 10;
|
|
471
|
+
readonly source: "google";
|
|
472
|
+
} | {
|
|
473
|
+
readonly type: "text";
|
|
474
|
+
readonly modelName: "gemini-2.5-flash";
|
|
475
|
+
readonly description: "Balanced Gemini 2.5 model with excellent performance-to-cost ratio. 1M context window with free tier available.";
|
|
476
|
+
readonly maxInputTokens: 1048576;
|
|
477
|
+
readonly maxOutputTokens: 8192;
|
|
478
|
+
readonly inputTokenCost: 0.3;
|
|
479
|
+
readonly outputTokenCost: 2.5;
|
|
480
|
+
readonly source: "google";
|
|
481
|
+
} | {
|
|
482
|
+
readonly type: "text";
|
|
483
|
+
readonly modelName: "gemini-2.5-flash-lite";
|
|
484
|
+
readonly description: "Most cost-effective Gemini 2.5 option for high-throughput applications. 1M context window.";
|
|
485
|
+
readonly maxInputTokens: 1048576;
|
|
486
|
+
readonly maxOutputTokens: 8192;
|
|
487
|
+
readonly inputTokenCost: 0.1;
|
|
488
|
+
readonly outputTokenCost: 0.4;
|
|
489
|
+
readonly source: "google";
|
|
320
490
|
} | {
|
|
321
491
|
readonly type: "text";
|
|
322
492
|
readonly modelName: "gemini-2.0-flash";
|
|
323
|
-
readonly description: "Workhorse model for all daily tasks. Strong overall performance and supports real-time streaming Live API";
|
|
493
|
+
readonly description: "Workhorse model for all daily tasks. Strong overall performance and supports real-time streaming Live API. 1M context window.";
|
|
324
494
|
readonly maxInputTokens: 1048576;
|
|
325
495
|
readonly maxOutputTokens: 8192;
|
|
326
|
-
readonly inputTokenCost: 0.
|
|
327
|
-
readonly outputTokenCost: 0.
|
|
496
|
+
readonly inputTokenCost: 0.1;
|
|
497
|
+
readonly outputTokenCost: 0.4;
|
|
328
498
|
readonly source: "google";
|
|
329
499
|
} | {
|
|
330
500
|
readonly type: "text";
|
|
@@ -339,7 +509,7 @@ export declare function getModel(modelName: ModelName): {
|
|
|
339
509
|
} | {
|
|
340
510
|
readonly type: "text";
|
|
341
511
|
readonly modelName: "gemini-2.0-flash-lite";
|
|
342
|
-
readonly description: "
|
|
512
|
+
readonly description: "Cost effective offering to support high throughput. Note: May be deprecated in favor of 2.5-flash-lite.";
|
|
343
513
|
readonly maxInputTokens: 1048576;
|
|
344
514
|
readonly maxOutputTokens: 8192;
|
|
345
515
|
readonly inputTokenCost: 0.075;
|
package/dist/models.js
CHANGED
|
@@ -40,6 +40,17 @@ export const textModels = [
|
|
|
40
40
|
outputTokenCost: 10,
|
|
41
41
|
source: "openai",
|
|
42
42
|
},
|
|
43
|
+
{
|
|
44
|
+
type: "text",
|
|
45
|
+
modelName: "o3",
|
|
46
|
+
description: "o3 is a reasoning model that sets a new standard for math, science, and coding, visual reasoning tasks, and technical writing. Part of the o-series of reasoning models. The knowledge cutoff for o3 models is October, 2023.",
|
|
47
|
+
maxInputTokens: 200000,
|
|
48
|
+
maxOutputTokens: 100000,
|
|
49
|
+
inputTokenCost: 2,
|
|
50
|
+
cachedInputTokenCost: 1,
|
|
51
|
+
outputTokenCost: 8,
|
|
52
|
+
source: "openai",
|
|
53
|
+
},
|
|
43
54
|
{
|
|
44
55
|
type: "text",
|
|
45
56
|
modelName: "o3-mini",
|
|
@@ -51,6 +62,28 @@ export const textModels = [
|
|
|
51
62
|
outputTokenCost: 4.4,
|
|
52
63
|
source: "openai",
|
|
53
64
|
},
|
|
65
|
+
{
|
|
66
|
+
type: "text",
|
|
67
|
+
modelName: "o4-mini",
|
|
68
|
+
description: "o4-mini is a new o-series reasoning model that replaced o3-mini, providing excellent performance for math, science, and coding tasks. Available in ChatGPT Plus, Pro, and Team.",
|
|
69
|
+
maxInputTokens: 200000,
|
|
70
|
+
maxOutputTokens: 100000,
|
|
71
|
+
inputTokenCost: 1.1,
|
|
72
|
+
cachedInputTokenCost: 0.55,
|
|
73
|
+
outputTokenCost: 4.4,
|
|
74
|
+
source: "openai",
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
type: "text",
|
|
78
|
+
modelName: "o1",
|
|
79
|
+
description: "o1 is a reasoning model designed to excel at complex reasoning tasks including science, math, and coding. The knowledge cutoff for o1 models is October, 2023.",
|
|
80
|
+
maxInputTokens: 200000,
|
|
81
|
+
maxOutputTokens: 100000,
|
|
82
|
+
inputTokenCost: 15,
|
|
83
|
+
cachedInputTokenCost: 7.5,
|
|
84
|
+
outputTokenCost: 60,
|
|
85
|
+
source: "openai",
|
|
86
|
+
},
|
|
54
87
|
{
|
|
55
88
|
type: "text",
|
|
56
89
|
modelName: "gpt-4-turbo",
|
|
@@ -84,14 +117,75 @@ export const textModels = [
|
|
|
84
117
|
disabled: true,
|
|
85
118
|
source: "openai",
|
|
86
119
|
},
|
|
120
|
+
{
|
|
121
|
+
type: "text",
|
|
122
|
+
modelName: "gpt-4.1",
|
|
123
|
+
description: "GPT-4.1 supports up to 1 million tokens of context, representing a significant increase in context window capacity. Ideal for processing large documents and extended conversations.",
|
|
124
|
+
maxInputTokens: 1047576,
|
|
125
|
+
maxOutputTokens: 32768,
|
|
126
|
+
inputTokenCost: 2.5,
|
|
127
|
+
cachedInputTokenCost: 1.25,
|
|
128
|
+
outputTokenCost: 10,
|
|
129
|
+
source: "openai",
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
type: "text",
|
|
133
|
+
modelName: "gemini-3-pro-preview",
|
|
134
|
+
description: "Strongest Gemini 3 model quality with 2M context window. Standard pricing for ≤200k tokens, higher rates for >200k tokens.",
|
|
135
|
+
maxInputTokens: 2_097_152,
|
|
136
|
+
maxOutputTokens: 8192,
|
|
137
|
+
inputTokenCost: 2.0,
|
|
138
|
+
outputTokenCost: 12.0,
|
|
139
|
+
source: "google",
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
type: "text",
|
|
143
|
+
modelName: "gemini-3-flash-preview",
|
|
144
|
+
description: "Latest Gemini 3 flash model with 1M context window. Excellent performance for high-volume tasks.",
|
|
145
|
+
maxInputTokens: 1_048_576,
|
|
146
|
+
maxOutputTokens: 8192,
|
|
147
|
+
inputTokenCost: 0.5,
|
|
148
|
+
outputTokenCost: 3.0,
|
|
149
|
+
source: "google",
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
type: "text",
|
|
153
|
+
modelName: "gemini-2.5-pro",
|
|
154
|
+
description: "High-performance Gemini 2.5 model with 2M context window. Standard pricing for ≤200k tokens, higher rates for >200k tokens.",
|
|
155
|
+
maxInputTokens: 2_097_152,
|
|
156
|
+
maxOutputTokens: 8192,
|
|
157
|
+
inputTokenCost: 1.25,
|
|
158
|
+
outputTokenCost: 10.0,
|
|
159
|
+
source: "google",
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
type: "text",
|
|
163
|
+
modelName: "gemini-2.5-flash",
|
|
164
|
+
description: "Balanced Gemini 2.5 model with excellent performance-to-cost ratio. 1M context window with free tier available.",
|
|
165
|
+
maxInputTokens: 1_048_576,
|
|
166
|
+
maxOutputTokens: 8192,
|
|
167
|
+
inputTokenCost: 0.3,
|
|
168
|
+
outputTokenCost: 2.5,
|
|
169
|
+
source: "google",
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
type: "text",
|
|
173
|
+
modelName: "gemini-2.5-flash-lite",
|
|
174
|
+
description: "Most cost-effective Gemini 2.5 option for high-throughput applications. 1M context window.",
|
|
175
|
+
maxInputTokens: 1_048_576,
|
|
176
|
+
maxOutputTokens: 8192,
|
|
177
|
+
inputTokenCost: 0.1,
|
|
178
|
+
outputTokenCost: 0.4,
|
|
179
|
+
source: "google",
|
|
180
|
+
},
|
|
87
181
|
{
|
|
88
182
|
type: "text",
|
|
89
183
|
modelName: "gemini-2.0-flash",
|
|
90
|
-
description: "Workhorse model for all daily tasks. Strong overall performance and supports real-time streaming Live API",
|
|
184
|
+
description: "Workhorse model for all daily tasks. Strong overall performance and supports real-time streaming Live API. 1M context window.",
|
|
91
185
|
maxInputTokens: 1_048_576,
|
|
92
186
|
maxOutputTokens: 8192,
|
|
93
|
-
inputTokenCost: 0.
|
|
94
|
-
outputTokenCost: 0.
|
|
187
|
+
inputTokenCost: 0.1,
|
|
188
|
+
outputTokenCost: 0.4,
|
|
95
189
|
source: "google",
|
|
96
190
|
},
|
|
97
191
|
{
|
|
@@ -108,7 +202,7 @@ export const textModels = [
|
|
|
108
202
|
{
|
|
109
203
|
type: "text",
|
|
110
204
|
modelName: "gemini-2.0-flash-lite",
|
|
111
|
-
description: "
|
|
205
|
+
description: "Cost effective offering to support high throughput. Note: May be deprecated in favor of 2.5-flash-lite.",
|
|
112
206
|
maxInputTokens: 1_048_576,
|
|
113
207
|
maxOutputTokens: 8192,
|
|
114
208
|
inputTokenCost: 0.075,
|
package/dist/types.d.ts
CHANGED
|
@@ -4,18 +4,24 @@ import { ModelName } from "./models.js";
|
|
|
4
4
|
import { Message } from "./classes/message/index.js";
|
|
5
5
|
import { Result } from "./types/result.js";
|
|
6
6
|
import { ToolCall } from "./classes/ToolCall.js";
|
|
7
|
-
|
|
7
|
+
import { OpenAIToolDefinition } from "./util/common.js";
|
|
8
|
+
import { ResponseFormatJSONSchema, ResponseFormatText } from "openai/resources";
|
|
9
|
+
export type PromptConfig = {
|
|
8
10
|
messages: Message[];
|
|
9
|
-
tools?:
|
|
11
|
+
tools?: OpenAIToolDefinition[];
|
|
10
12
|
instructions?: string;
|
|
11
13
|
maxTokens?: number;
|
|
12
14
|
temperature?: number;
|
|
13
15
|
numSuggestions?: number;
|
|
14
16
|
parallelToolCalls?: boolean;
|
|
15
|
-
responseFormat?:
|
|
17
|
+
responseFormat?: ResponseFormatText | ResponseFormatJSONSchema;
|
|
18
|
+
rawAttributes?: Record<string, any>;
|
|
16
19
|
};
|
|
20
|
+
export declare function responseFormatText(): ResponseFormatText;
|
|
21
|
+
export declare function responseFormatJSONSchema(schema: ResponseFormatJSONSchema.JSONSchema): ResponseFormatJSONSchema;
|
|
17
22
|
export type SmolConfig = {
|
|
18
|
-
|
|
23
|
+
openAiApiKey?: string;
|
|
24
|
+
googleApiKey?: string;
|
|
19
25
|
model: ModelName;
|
|
20
26
|
logLevel?: LogLevel;
|
|
21
27
|
};
|
package/dist/types.js
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { FunctionDeclaration } from "@google/genai";
|
|
2
|
+
/**
|
|
3
|
+
* OpenAI tool definition format
|
|
4
|
+
*/
|
|
5
|
+
export interface OpenAIToolDefinition {
|
|
6
|
+
type: "function";
|
|
7
|
+
function: {
|
|
8
|
+
name: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
parameters: Record<string, unknown>;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Converts an OpenAI tool definition to a Google FunctionDeclaration format
|
|
15
|
+
*
|
|
16
|
+
* @param openAITool - The tool definition in OpenAI format
|
|
17
|
+
* @returns The tool definition in Google FunctionDeclaration format
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const openAITool = {
|
|
22
|
+
* type: "function" as const,
|
|
23
|
+
* function: {
|
|
24
|
+
* name: "add",
|
|
25
|
+
* description: "Adds two numbers together",
|
|
26
|
+
* parameters: {
|
|
27
|
+
* type: "object",
|
|
28
|
+
* properties: {
|
|
29
|
+
* a: { type: "number", description: "First number" },
|
|
30
|
+
* b: { type: "number", description: "Second number" }
|
|
31
|
+
* },
|
|
32
|
+
* required: ["a", "b"],
|
|
33
|
+
* additionalProperties: false
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
* };
|
|
37
|
+
*
|
|
38
|
+
* const googleTool = convertOpenAIToolToGoogle(openAITool);
|
|
39
|
+
* // Returns:
|
|
40
|
+
* // {
|
|
41
|
+
* // name: "add",
|
|
42
|
+
* // description: "Adds two numbers together",
|
|
43
|
+
* // parametersJsonSchema: {
|
|
44
|
+
* // type: "object",
|
|
45
|
+
* // properties: {
|
|
46
|
+
* // a: { type: "number", description: "First number" },
|
|
47
|
+
* // b: { type: "number", description: "Second number" }
|
|
48
|
+
* // },
|
|
49
|
+
* // required: ["a", "b"]
|
|
50
|
+
* // }
|
|
51
|
+
* // }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function convertOpenAIToolToGoogle(openAITool: OpenAIToolDefinition): FunctionDeclaration;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes properties that Google's API doesn't support from JSON schemas
|
|
3
|
+
*/
|
|
4
|
+
function removeUnsupportedProperties(obj) {
|
|
5
|
+
if (typeof obj === "object" && obj !== null) {
|
|
6
|
+
const newObj = { ...obj };
|
|
7
|
+
// Remove properties that Google's API doesn't support
|
|
8
|
+
delete newObj.additionalProperties;
|
|
9
|
+
delete newObj.$schema;
|
|
10
|
+
delete newObj.strict;
|
|
11
|
+
// Recursively process nested objects and arrays
|
|
12
|
+
for (const key in newObj) {
|
|
13
|
+
if (key in newObj) {
|
|
14
|
+
if (Array.isArray(newObj[key])) {
|
|
15
|
+
newObj[key] = newObj[key].map((item) => typeof item === "object" && item !== null
|
|
16
|
+
? removeUnsupportedProperties(item)
|
|
17
|
+
: item);
|
|
18
|
+
}
|
|
19
|
+
else if (typeof newObj[key] === "object" && newObj[key] !== null) {
|
|
20
|
+
newObj[key] = removeUnsupportedProperties(newObj[key]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return newObj;
|
|
25
|
+
}
|
|
26
|
+
return obj;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Converts an OpenAI tool definition to a Google FunctionDeclaration format
|
|
30
|
+
*
|
|
31
|
+
* @param openAITool - The tool definition in OpenAI format
|
|
32
|
+
* @returns The tool definition in Google FunctionDeclaration format
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const openAITool = {
|
|
37
|
+
* type: "function" as const,
|
|
38
|
+
* function: {
|
|
39
|
+
* name: "add",
|
|
40
|
+
* description: "Adds two numbers together",
|
|
41
|
+
* parameters: {
|
|
42
|
+
* type: "object",
|
|
43
|
+
* properties: {
|
|
44
|
+
* a: { type: "number", description: "First number" },
|
|
45
|
+
* b: { type: "number", description: "Second number" }
|
|
46
|
+
* },
|
|
47
|
+
* required: ["a", "b"],
|
|
48
|
+
* additionalProperties: false
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
* };
|
|
52
|
+
*
|
|
53
|
+
* const googleTool = convertOpenAIToolToGoogle(openAITool);
|
|
54
|
+
* // Returns:
|
|
55
|
+
* // {
|
|
56
|
+
* // name: "add",
|
|
57
|
+
* // description: "Adds two numbers together",
|
|
58
|
+
* // parametersJsonSchema: {
|
|
59
|
+
* // type: "object",
|
|
60
|
+
* // properties: {
|
|
61
|
+
* // a: { type: "number", description: "First number" },
|
|
62
|
+
* // b: { type: "number", description: "Second number" }
|
|
63
|
+
* // },
|
|
64
|
+
* // required: ["a", "b"]
|
|
65
|
+
* // }
|
|
66
|
+
* // }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function convertOpenAIToolToGoogle(openAITool) {
|
|
70
|
+
return {
|
|
71
|
+
name: openAITool.function.name,
|
|
72
|
+
description: openAITool.function.description,
|
|
73
|
+
parametersJsonSchema: removeUnsupportedProperties(openAITool.function.parameters),
|
|
74
|
+
};
|
|
75
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smoltalk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "A common interface for LLM APIs",
|
|
5
5
|
"homepage": "https://github.com/egonSchiele/smoltalk",
|
|
6
6
|
"scripts": {
|
|
@@ -31,8 +31,10 @@
|
|
|
31
31
|
"license": "ISC",
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^25.0.3",
|
|
34
|
+
"termcolors": "github:egonSchiele/termcolors",
|
|
34
35
|
"typescript": "^5.9.3",
|
|
35
|
-
"vitest": "^4.0.16"
|
|
36
|
+
"vitest": "^4.0.16",
|
|
37
|
+
"zod": "^4.3.5"
|
|
36
38
|
},
|
|
37
39
|
"dependencies": {
|
|
38
40
|
"@google/genai": "^1.34.0",
|