smoltalk 0.0.5 → 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/UserMessage.js +5 -1
- package/dist/classes/message/index.d.ts +1 -2
- package/dist/clients/google.js +4 -0
- package/dist/clients/openai.js +4 -5
- package/dist/types.d.ts +4 -1
- package/dist/types.js +6 -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
|
}
|
|
@@ -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?: {
|
package/dist/clients/google.js
CHANGED
|
@@ -27,6 +27,10 @@ export class SmolGoogle extends BaseClient {
|
|
|
27
27
|
if (tools.length > 0) {
|
|
28
28
|
genConfig.tools = [{ functionDeclarations: tools }];
|
|
29
29
|
}
|
|
30
|
+
if (config.responseFormat && config.responseFormat.type === "json_schema") {
|
|
31
|
+
genConfig.responseMimeType = "application/json";
|
|
32
|
+
genConfig.responseJsonSchema = config.responseFormat.json_schema.schema;
|
|
33
|
+
}
|
|
30
34
|
const request = {
|
|
31
35
|
contents: messages,
|
|
32
36
|
model: this.model,
|
package/dist/clients/openai.js
CHANGED
|
@@ -22,12 +22,14 @@ export class SmolOpenAi extends BaseClient {
|
|
|
22
22
|
}
|
|
23
23
|
async text(config) {
|
|
24
24
|
const messages = config.messages.map((msg) => msg.toOpenAIMessage());
|
|
25
|
-
const
|
|
25
|
+
const request = {
|
|
26
26
|
model: this.model,
|
|
27
27
|
messages,
|
|
28
28
|
tools: config.tools,
|
|
29
29
|
response_format: config.responseFormat,
|
|
30
|
-
}
|
|
30
|
+
};
|
|
31
|
+
this.logger.debug("Sending request to OpenAI:", JSON.stringify(request, null, 2));
|
|
32
|
+
const completion = await this.client.chat.completions.create(request);
|
|
31
33
|
this.logger.debug("Response from OpenAI:", JSON.stringify(completion, null, 2));
|
|
32
34
|
const message = completion.choices[0].message;
|
|
33
35
|
const output = message.content;
|
|
@@ -43,9 +45,6 @@ export class SmolOpenAi extends BaseClient {
|
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
|
-
if (toolCalls.length > 0) {
|
|
47
|
-
this.logger.debug("Tool calls detected:", toolCalls);
|
|
48
|
-
}
|
|
49
48
|
return success({ output, toolCalls });
|
|
50
49
|
}
|
|
51
50
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ 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";
|
|
8
9
|
export type PromptConfig = {
|
|
9
10
|
messages: Message[];
|
|
10
11
|
tools?: OpenAIToolDefinition[];
|
|
@@ -13,9 +14,11 @@ export type PromptConfig = {
|
|
|
13
14
|
temperature?: number;
|
|
14
15
|
numSuggestions?: number;
|
|
15
16
|
parallelToolCalls?: boolean;
|
|
16
|
-
responseFormat?:
|
|
17
|
+
responseFormat?: ResponseFormatText | ResponseFormatJSONSchema;
|
|
17
18
|
rawAttributes?: Record<string, any>;
|
|
18
19
|
};
|
|
20
|
+
export declare function responseFormatText(): ResponseFormatText;
|
|
21
|
+
export declare function responseFormatJSONSchema(schema: ResponseFormatJSONSchema.JSONSchema): ResponseFormatJSONSchema;
|
|
19
22
|
export type SmolConfig = {
|
|
20
23
|
openAiApiKey?: string;
|
|
21
24
|
googleApiKey?: string;
|
package/dist/types.js
CHANGED
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",
|