smoltalk 0.0.2 → 0.0.4

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.
Files changed (46) hide show
  1. package/dist/classes/ToolCall.d.ts +11 -0
  2. package/dist/classes/ToolCall.js +33 -0
  3. package/dist/classes/message/AssistantMessage.d.ts +32 -0
  4. package/dist/classes/message/AssistantMessage.js +56 -0
  5. package/dist/classes/message/BaseMessage.d.ts +12 -0
  6. package/dist/classes/message/BaseMessage.js +2 -0
  7. package/dist/classes/message/DeveloperMessage.d.ts +20 -0
  8. package/dist/classes/message/DeveloperMessage.js +33 -0
  9. package/dist/classes/message/SystemMessage.d.ts +20 -0
  10. package/dist/classes/message/SystemMessage.js +33 -0
  11. package/dist/classes/message/ToolMessage.d.ts +21 -0
  12. package/dist/classes/message/ToolMessage.js +40 -0
  13. package/dist/classes/message/UserMessage.d.ts +19 -0
  14. package/dist/classes/message/UserMessage.js +31 -0
  15. package/dist/classes/message/index.d.ts +37 -0
  16. package/dist/classes/message/index.js +26 -0
  17. package/dist/{lib/client.d.ts → client.d.ts} +1 -1
  18. package/dist/{lib/client.js → client.js} +1 -3
  19. package/dist/clients/baseClient.d.ts +5 -0
  20. package/dist/clients/baseClient.js +14 -0
  21. package/dist/clients/google.d.ts +12 -0
  22. package/dist/clients/google.js +30 -0
  23. package/dist/{lib/clients → clients}/openai.d.ts +3 -2
  24. package/dist/{lib/clients → clients}/openai.js +13 -10
  25. package/dist/index.d.ts +6 -1
  26. package/dist/index.js +6 -37
  27. package/dist/logger.d.ts +2 -0
  28. package/dist/logger.js +9 -0
  29. package/dist/{lib/types.d.ts → types.d.ts} +12 -16
  30. package/dist/{lib/util → util}/openai.d.ts +0 -2
  31. package/dist/util/openai.js +3 -0
  32. package/package.json +1 -1
  33. package/dist/lib/clients/google.d.ts +0 -11
  34. package/dist/lib/clients/google.js +0 -39
  35. package/dist/lib/index.d.ts +0 -4
  36. package/dist/lib/index.js +0 -4
  37. package/dist/lib/util/openai.js +0 -10
  38. /package/dist/{lib/models.d.ts → models.d.ts} +0 -0
  39. /package/dist/{lib/models.js → models.js} +0 -0
  40. /package/dist/{lib/smolError.d.ts → smolError.d.ts} +0 -0
  41. /package/dist/{lib/smolError.js → smolError.js} +0 -0
  42. /package/dist/{lib/types → types}/result.d.ts +0 -0
  43. /package/dist/{lib/types → types}/result.js +0 -0
  44. /package/dist/{lib/types.js → types.js} +0 -0
  45. /package/dist/{lib/util.d.ts → util.d.ts} +0 -0
  46. /package/dist/{lib/util.js → util.js} +0 -0
@@ -0,0 +1,11 @@
1
+ export type ToolCallOptions = {};
2
+ export declare class ToolCall {
3
+ private _id;
4
+ private _name;
5
+ private _arguments;
6
+ private logger;
7
+ constructor(id: string, name: string, args: Record<string, any> | string, options?: ToolCallOptions);
8
+ get id(): string;
9
+ get name(): string;
10
+ get arguments(): Record<string, any>;
11
+ }
@@ -0,0 +1,33 @@
1
+ import { getLogger } from "../logger.js";
2
+ export class ToolCall {
3
+ _id;
4
+ _name;
5
+ _arguments;
6
+ logger;
7
+ constructor(id, name, args, options = {}) {
8
+ this._id = id;
9
+ this._name = name;
10
+ this.logger = getLogger();
11
+ if (typeof args === "string") {
12
+ try {
13
+ this._arguments = JSON.parse(args);
14
+ }
15
+ catch (e) {
16
+ this.logger.error(`Failed to parse arguments for ToolCall ${name} with id ${id}:`, e, args);
17
+ this._arguments = {};
18
+ }
19
+ }
20
+ else {
21
+ this._arguments = args;
22
+ }
23
+ }
24
+ get id() {
25
+ return this._id;
26
+ }
27
+ get name() {
28
+ return this._name;
29
+ }
30
+ get arguments() {
31
+ return this._arguments;
32
+ }
33
+ }
@@ -0,0 +1,32 @@
1
+ import { BaseMessage, MessageClass } from "./BaseMessage.js";
2
+ import { TextPart } from "../../types.js";
3
+ import { ChatCompletionMessageParam } from "openai/resources";
4
+ import { Content } from "@google/genai";
5
+ export declare class AssistantMessage extends BaseMessage implements MessageClass {
6
+ _role: "assistant";
7
+ _content: string | Array<TextPart> | null;
8
+ _name?: string;
9
+ _audio?: any | null;
10
+ _function_call?: any | null;
11
+ _refusal?: string | null;
12
+ _tool_calls?: Array<any>;
13
+ _rawData?: any;
14
+ constructor(content: string | Array<TextPart> | null, options?: {
15
+ name?: string;
16
+ audio?: any | null;
17
+ function_call?: any | null;
18
+ refusal?: string | null;
19
+ tool_calls?: Array<any>;
20
+ rawData?: any;
21
+ });
22
+ get content(): string;
23
+ get role(): "assistant";
24
+ get name(): string | undefined;
25
+ get audio(): any | null | undefined;
26
+ get function_call(): any | null | undefined;
27
+ get refusal(): string | null | undefined;
28
+ get tool_calls(): Array<any> | undefined;
29
+ get rawData(): any;
30
+ toOpenAIMessage(): ChatCompletionMessageParam;
31
+ toGoogleMessage(): Content;
32
+ }
@@ -0,0 +1,56 @@
1
+ import { BaseMessage } from "./BaseMessage.js";
2
+ export class AssistantMessage extends BaseMessage {
3
+ _role = "assistant";
4
+ _content;
5
+ _name;
6
+ _audio;
7
+ _function_call;
8
+ _refusal;
9
+ _tool_calls;
10
+ _rawData;
11
+ constructor(content, options = {}) {
12
+ super();
13
+ this._content = content;
14
+ this._name = options.name;
15
+ this._audio = options.audio;
16
+ this._function_call = options.function_call;
17
+ this._refusal = options.refusal;
18
+ this._tool_calls = options.tool_calls;
19
+ this._rawData = options.rawData;
20
+ }
21
+ get content() {
22
+ if (this._content === null || this._content === undefined) {
23
+ return "";
24
+ }
25
+ return typeof this._content === "string"
26
+ ? this._content
27
+ : JSON.stringify(this._content);
28
+ }
29
+ get role() {
30
+ return this._role;
31
+ }
32
+ get name() {
33
+ return this._name;
34
+ }
35
+ get audio() {
36
+ return this._audio;
37
+ }
38
+ get function_call() {
39
+ return this._function_call;
40
+ }
41
+ get refusal() {
42
+ return this._refusal;
43
+ }
44
+ get tool_calls() {
45
+ return this._tool_calls;
46
+ }
47
+ get rawData() {
48
+ return this._rawData;
49
+ }
50
+ toOpenAIMessage() {
51
+ return { role: this.role, content: this.content, name: this.name };
52
+ }
53
+ toGoogleMessage() {
54
+ return { role: this.role, parts: [{ text: this.content }] };
55
+ }
56
+ }
@@ -0,0 +1,12 @@
1
+ import { Content } from "@google/genai";
2
+ import { ChatCompletionMessageParam } from "openai/resources";
3
+ export declare class BaseMessage {
4
+ }
5
+ export interface MessageClass {
6
+ get content(): string;
7
+ get role(): string;
8
+ get name(): string | undefined;
9
+ get rawData(): any;
10
+ toOpenAIMessage(): ChatCompletionMessageParam;
11
+ toGoogleMessage(): Content;
12
+ }
@@ -0,0 +1,2 @@
1
+ export class BaseMessage {
2
+ }
@@ -0,0 +1,20 @@
1
+ import { BaseMessage, MessageClass } from "./BaseMessage.js";
2
+ import { TextPart } from "../../types.js";
3
+ import { ChatCompletionMessageParam } from "openai/resources";
4
+ import { Content } from "@google/genai";
5
+ export declare class DeveloperMessage extends BaseMessage implements MessageClass {
6
+ _role: "developer";
7
+ _content: string | Array<TextPart>;
8
+ _name?: string;
9
+ _rawData?: any;
10
+ constructor(content: string | Array<TextPart>, options?: {
11
+ name?: string;
12
+ rawData?: any;
13
+ });
14
+ get content(): string;
15
+ get role(): "developer";
16
+ get name(): string | undefined;
17
+ get rawData(): any;
18
+ toOpenAIMessage(): ChatCompletionMessageParam;
19
+ toGoogleMessage(): Content;
20
+ }
@@ -0,0 +1,33 @@
1
+ import { BaseMessage } from "./BaseMessage.js";
2
+ export class DeveloperMessage extends BaseMessage {
3
+ _role = "developer";
4
+ _content;
5
+ _name;
6
+ _rawData;
7
+ constructor(content, options = {}) {
8
+ super();
9
+ this._content = content;
10
+ this._name = options.name;
11
+ this._rawData = options.rawData;
12
+ }
13
+ get content() {
14
+ return typeof this._content === "string"
15
+ ? this._content
16
+ : JSON.stringify(this._content);
17
+ }
18
+ get role() {
19
+ return this._role;
20
+ }
21
+ get name() {
22
+ return this._name;
23
+ }
24
+ get rawData() {
25
+ return this._rawData;
26
+ }
27
+ toOpenAIMessage() {
28
+ return { role: this.role, content: this.content, name: this.name };
29
+ }
30
+ toGoogleMessage() {
31
+ return { role: this.role, parts: [{ text: this.content }] };
32
+ }
33
+ }
@@ -0,0 +1,20 @@
1
+ import { BaseMessage, MessageClass } from "./BaseMessage.js";
2
+ import { TextPart } from "../../types.js";
3
+ import { ChatCompletionMessageParam } from "openai/resources";
4
+ import { Content } from "@google/genai";
5
+ export declare class SystemMessage extends BaseMessage implements MessageClass {
6
+ _role: "system";
7
+ _content: string | Array<TextPart>;
8
+ _name?: string;
9
+ _rawData?: any;
10
+ constructor(content: string | Array<TextPart>, options?: {
11
+ name?: string;
12
+ rawData?: any;
13
+ });
14
+ get content(): string;
15
+ get role(): "system";
16
+ get name(): string | undefined;
17
+ get rawData(): any;
18
+ toOpenAIMessage(): ChatCompletionMessageParam;
19
+ toGoogleMessage(): Content;
20
+ }
@@ -0,0 +1,33 @@
1
+ import { BaseMessage } from "./BaseMessage.js";
2
+ export class SystemMessage extends BaseMessage {
3
+ _role = "system";
4
+ _content;
5
+ _name;
6
+ _rawData;
7
+ constructor(content, options = {}) {
8
+ super();
9
+ this._content = content;
10
+ this._name = options.name;
11
+ this._rawData = options.rawData;
12
+ }
13
+ get content() {
14
+ return typeof this._content === "string"
15
+ ? this._content
16
+ : JSON.stringify(this._content);
17
+ }
18
+ get role() {
19
+ return this._role;
20
+ }
21
+ get name() {
22
+ return this._name;
23
+ }
24
+ get rawData() {
25
+ return this._rawData;
26
+ }
27
+ toOpenAIMessage() {
28
+ return { role: this.role, content: this.content, name: this.name };
29
+ }
30
+ toGoogleMessage() {
31
+ return { role: this.role, parts: [{ text: this.content }] };
32
+ }
33
+ }
@@ -0,0 +1,21 @@
1
+ import { BaseMessage, MessageClass } from "./BaseMessage.js";
2
+ import { TextPart } from "../../types.js";
3
+ import { ChatCompletionMessageParam } from "openai/resources";
4
+ import { Content } from "@google/genai";
5
+ export declare class ToolMessage extends BaseMessage implements MessageClass {
6
+ _role: "tool";
7
+ _content: string | Array<TextPart>;
8
+ _tool_call_id: string;
9
+ _rawData?: any;
10
+ constructor(content: string | Array<TextPart>, options: {
11
+ tool_call_id: string;
12
+ rawData?: any;
13
+ });
14
+ get content(): string;
15
+ get role(): "tool";
16
+ get name(): string | undefined;
17
+ get tool_call_id(): string;
18
+ get rawData(): any;
19
+ toOpenAIMessage(): ChatCompletionMessageParam;
20
+ toGoogleMessage(): Content;
21
+ }
@@ -0,0 +1,40 @@
1
+ import { BaseMessage } from "./BaseMessage.js";
2
+ export class ToolMessage extends BaseMessage {
3
+ _role = "tool";
4
+ _content;
5
+ _tool_call_id;
6
+ _rawData;
7
+ constructor(content, options) {
8
+ super();
9
+ this._content = content;
10
+ this._tool_call_id = options.tool_call_id;
11
+ this._rawData = options.rawData;
12
+ }
13
+ get content() {
14
+ return typeof this._content === "string"
15
+ ? this._content
16
+ : JSON.stringify(this._content);
17
+ }
18
+ get role() {
19
+ return this._role;
20
+ }
21
+ get name() {
22
+ return undefined;
23
+ }
24
+ get tool_call_id() {
25
+ return this._tool_call_id;
26
+ }
27
+ get rawData() {
28
+ return this._rawData;
29
+ }
30
+ toOpenAIMessage() {
31
+ return {
32
+ role: this.role,
33
+ content: this.content,
34
+ tool_call_id: this.tool_call_id,
35
+ };
36
+ }
37
+ toGoogleMessage() {
38
+ return { role: this.role, parts: [{ text: this.content }] };
39
+ }
40
+ }
@@ -0,0 +1,19 @@
1
+ import { BaseMessage, MessageClass } from "./BaseMessage.js";
2
+ import { ChatCompletionMessageParam } from "openai/resources";
3
+ import { Content } from "@google/genai";
4
+ export declare class UserMessage extends BaseMessage implements MessageClass {
5
+ _role: "user";
6
+ _content: string;
7
+ _name?: string;
8
+ _rawData?: any;
9
+ constructor(content: string, options?: {
10
+ name?: string;
11
+ rawData?: any;
12
+ });
13
+ get content(): string;
14
+ get role(): "user";
15
+ get name(): string | undefined;
16
+ get rawData(): any;
17
+ toOpenAIMessage(): ChatCompletionMessageParam;
18
+ toGoogleMessage(): Content;
19
+ }
@@ -0,0 +1,31 @@
1
+ import { BaseMessage } from "./BaseMessage.js";
2
+ export class UserMessage extends BaseMessage {
3
+ _role = "user";
4
+ _content;
5
+ _name;
6
+ _rawData;
7
+ constructor(content, options = {}) {
8
+ super();
9
+ this._content = content;
10
+ this._name = options.name;
11
+ this._rawData = options.rawData;
12
+ }
13
+ get content() {
14
+ return this._content;
15
+ }
16
+ get role() {
17
+ return this._role;
18
+ }
19
+ get name() {
20
+ return this._name;
21
+ }
22
+ get rawData() {
23
+ return this._rawData;
24
+ }
25
+ toOpenAIMessage() {
26
+ return { role: this.role, content: this.content, name: this.name };
27
+ }
28
+ toGoogleMessage() {
29
+ return { role: this.role, parts: [{ text: this.content }] };
30
+ }
31
+ }
@@ -0,0 +1,37 @@
1
+ import { UserMessage } from "./UserMessage.js";
2
+ import { AssistantMessage } from "./AssistantMessage.js";
3
+ import { DeveloperMessage } from "./DeveloperMessage.js";
4
+ import { SystemMessage } from "./SystemMessage.js";
5
+ import { ToolMessage } from "./ToolMessage.js";
6
+ import { TextPart } from "../../types.js";
7
+ export * from "./AssistantMessage.js";
8
+ export * from "./BaseMessage.js";
9
+ export * from "./DeveloperMessage.js";
10
+ export * from "./SystemMessage.js";
11
+ export * from "./ToolMessage.js";
12
+ export * from "./UserMessage.js";
13
+ export declare function userMessage(content: string, options?: {
14
+ name?: string;
15
+ rawData?: any;
16
+ }): UserMessage;
17
+ export declare function assistantMessage(content: string | Array<TextPart> | null, options?: {
18
+ name?: string;
19
+ audio?: any | null;
20
+ function_call?: any | null;
21
+ refusal?: string | null;
22
+ tool_calls?: Array<any>;
23
+ rawData?: any;
24
+ }): AssistantMessage;
25
+ export declare function developerMessage(content: string | Array<TextPart>, options?: {
26
+ name?: string;
27
+ rawData?: any;
28
+ }): DeveloperMessage;
29
+ export declare function systemMessage(content: string | Array<TextPart>, options?: {
30
+ name?: string;
31
+ rawData?: any;
32
+ }): SystemMessage;
33
+ export declare function toolMessage(content: string | Array<TextPart>, options: {
34
+ tool_call_id: string;
35
+ rawData?: any;
36
+ }): ToolMessage;
37
+ export type Message = ToolMessage | UserMessage | AssistantMessage | DeveloperMessage | SystemMessage;
@@ -0,0 +1,26 @@
1
+ import { UserMessage } from "./UserMessage.js";
2
+ import { AssistantMessage } from "./AssistantMessage.js";
3
+ import { DeveloperMessage } from "./DeveloperMessage.js";
4
+ import { SystemMessage } from "./SystemMessage.js";
5
+ import { ToolMessage } from "./ToolMessage.js";
6
+ export * from "./AssistantMessage.js";
7
+ export * from "./BaseMessage.js";
8
+ export * from "./DeveloperMessage.js";
9
+ export * from "./SystemMessage.js";
10
+ export * from "./ToolMessage.js";
11
+ export * from "./UserMessage.js";
12
+ export function userMessage(content, options = {}) {
13
+ return new UserMessage(content, options);
14
+ }
15
+ export function assistantMessage(content, options = {}) {
16
+ return new AssistantMessage(content, options);
17
+ }
18
+ export function developerMessage(content, options = {}) {
19
+ return new DeveloperMessage(content, options);
20
+ }
21
+ export function systemMessage(content, options = {}) {
22
+ return new SystemMessage(content, options);
23
+ }
24
+ export function toolMessage(content, options) {
25
+ return new ToolMessage(content, options);
26
+ }
@@ -3,4 +3,4 @@ export * from "./clients/openai.js";
3
3
  import { SmolGoogle } from "./clients/google.js";
4
4
  import { SmolOpenAi } from "./clients/openai.js";
5
5
  import { SmolConfig } from "./types.js";
6
- export declare function getClient(config: SmolConfig): SmolOpenAi | SmolGoogle;
6
+ export declare function getClient(config: SmolConfig): SmolGoogle | SmolOpenAi;
@@ -4,15 +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 { EgonLog } from "egonlog";
8
7
  export function getClient(config) {
9
8
  const apiKey = config.apiKey;
10
- const logger = new EgonLog({ level: config.logLevel || "info" });
11
9
  const model = getModel(config.model);
12
10
  if (model === undefined || !isTextModel(model)) {
13
11
  throw new SmolError(`Only text models are supported currently. ${config.model} is a ${model?.type} model.`);
14
12
  }
15
- const clientConfig = { ...config, logger };
13
+ const clientConfig = { ...config };
16
14
  switch (model.source) {
17
15
  case "openai":
18
16
  return new SmolOpenAi(clientConfig);
@@ -0,0 +1,5 @@
1
+ import { PromptConfig, PromptResult, Result, SmolClient } from "../types.js";
2
+ export declare class BaseClient implements SmolClient {
3
+ text(config: PromptConfig): Promise<Result<PromptResult>>;
4
+ prompt(text: string, config?: PromptConfig): Promise<Result<PromptResult>>;
5
+ }
@@ -0,0 +1,14 @@
1
+ import { userMessage } from "../classes/message/index.js";
2
+ export class BaseClient {
3
+ text(config) {
4
+ throw new Error("Method not implemented.");
5
+ }
6
+ prompt(text, config) {
7
+ const msg = userMessage(text);
8
+ const promptConfig = {
9
+ ...config,
10
+ messages: config?.messages ? [...config.messages, msg] : [msg],
11
+ };
12
+ return this.text(promptConfig);
13
+ }
14
+ }
@@ -0,0 +1,12 @@
1
+ import { GoogleGenAI } from "@google/genai";
2
+ import { BaseClientConfig, PromptConfig, PromptResult, Result, SmolClient } from "../types.js";
3
+ import { BaseClient } from "./baseClient.js";
4
+ export type SmolGoogleConfig = BaseClientConfig;
5
+ export declare class SmolGoogle extends BaseClient implements SmolClient {
6
+ private client;
7
+ private logger;
8
+ private model;
9
+ constructor(config: SmolGoogleConfig);
10
+ getClient(): GoogleGenAI;
11
+ text(config: PromptConfig): Promise<Result<PromptResult>>;
12
+ }
@@ -0,0 +1,30 @@
1
+ import { GoogleGenAI } from "@google/genai";
2
+ import { getLogger } from "../logger.js";
3
+ import { success, } from "../types.js";
4
+ import { BaseClient } from "./baseClient.js";
5
+ export class SmolGoogle extends BaseClient {
6
+ client;
7
+ logger;
8
+ model;
9
+ constructor(config) {
10
+ super();
11
+ this.client = new GoogleGenAI({ apiKey: config.apiKey });
12
+ this.logger = getLogger();
13
+ this.model = config.model;
14
+ }
15
+ getClient() {
16
+ return this.client;
17
+ }
18
+ async text(config) {
19
+ const messages = config.messages.map((msg) => msg.toGoogleMessage());
20
+ // Send the prompt as the latest message
21
+ const result = await this.client.models.generateContent({
22
+ contents: messages,
23
+ model: this.model,
24
+ });
25
+ //console.log("Full response:", JSON.stringify(result, null, 2));
26
+ const text = result.text || null;
27
+ // Return the response, updating the chat history
28
+ return success({ output: text, toolCalls: [] });
29
+ }
30
+ }
@@ -1,11 +1,12 @@
1
1
  import OpenAI from "openai";
2
2
  import { BaseClientConfig, PromptConfig, PromptResult, Result, SmolClient } from "../types.js";
3
+ import { BaseClient } from "./baseClient.js";
3
4
  export type SmolOpenAiConfig = BaseClientConfig;
4
- export declare class SmolOpenAi implements SmolClient {
5
+ export declare class SmolOpenAi extends BaseClient implements SmolClient {
5
6
  private client;
6
7
  private logger;
7
8
  private model;
8
9
  constructor(config: SmolOpenAiConfig);
9
10
  getClient(): OpenAI;
10
- text(content: string, config?: PromptConfig): Promise<Result<PromptResult>>;
11
+ text(config: PromptConfig): Promise<Result<PromptResult>>;
11
12
  }
@@ -1,26 +1,29 @@
1
1
  import OpenAI from "openai";
2
2
  import { success, } from "../types.js";
3
- import { isFunctionToolCall, openAIToToolCall } from "../util.js";
4
- export class SmolOpenAi {
3
+ import { ToolCall } from "../classes/ToolCall.js";
4
+ import { isFunctionToolCall } from "../util.js";
5
+ import { getLogger } from "../logger.js";
6
+ import { BaseClient } from "./baseClient.js";
7
+ export class SmolOpenAi extends BaseClient {
5
8
  client;
6
9
  logger;
7
10
  model;
8
11
  constructor(config) {
12
+ super();
9
13
  this.client = new OpenAI({ apiKey: config.apiKey });
10
- this.logger = config.logger;
14
+ this.logger = getLogger();
11
15
  this.model = config.model;
12
16
  }
13
17
  getClient() {
14
18
  return this.client;
15
19
  }
16
- async text(content, config) {
17
- const messages = structuredClone(config?.messages) || [];
18
- messages.push({ role: "user", content });
20
+ async text(config) {
21
+ const messages = config.messages.map((msg) => msg.toOpenAIMessage());
19
22
  const completion = await this.client.chat.completions.create({
20
23
  model: this.model,
21
24
  messages,
22
- tools: config?.tools,
23
- response_format: config?.responseFormat,
25
+ tools: config.tools,
26
+ response_format: config.responseFormat,
24
27
  });
25
28
  this.logger.debug("Response from OpenAI:", JSON.stringify(completion, null, 2));
26
29
  const message = completion.choices[0].message;
@@ -30,7 +33,7 @@ export class SmolOpenAi {
30
33
  if (_toolCalls) {
31
34
  for (const tc of _toolCalls) {
32
35
  if (isFunctionToolCall(tc)) {
33
- toolCalls.push(openAIToToolCall(tc));
36
+ toolCalls.push(new ToolCall(tc.id, tc.function.name, tc.function.arguments));
34
37
  }
35
38
  else {
36
39
  this.logger.warn(`Unsupported tool call type: ${tc.type} for tool call ID: ${tc.id}`);
@@ -38,7 +41,7 @@ export class SmolOpenAi {
38
41
  }
39
42
  }
40
43
  if (toolCalls.length > 0) {
41
- this.logger.info("Tool calls detected:", toolCalls);
44
+ this.logger.debug("Tool calls detected:", toolCalls);
42
45
  }
43
46
  return success({ output, toolCalls });
44
47
  }
package/dist/index.d.ts CHANGED
@@ -1 +1,6 @@
1
- export {};
1
+ export * from "./client.js";
2
+ export * from "./types.js";
3
+ export * from "./models.js";
4
+ export * from "./smolError.js";
5
+ export * from "./util.js";
6
+ export * from "./classes/message/index.js";
package/dist/index.js CHANGED
@@ -1,37 +1,6 @@
1
- import { getClient } from "./lib/client.js";
2
- function add({ a, b }) {
3
- return a + b;
4
- }
5
- // Define the function tool for OpenAI
6
- const addTool = {
7
- type: "function",
8
- function: {
9
- name: "add",
10
- description: "Adds two numbers together and returns the result.",
11
- parameters: {
12
- type: "object",
13
- properties: {
14
- a: {
15
- type: "number",
16
- description: "The first number to add",
17
- },
18
- b: {
19
- type: "number",
20
- description: "The second number to add",
21
- },
22
- },
23
- required: ["a", "b"],
24
- additionalProperties: false,
25
- },
26
- },
27
- };
28
- const client = getClient({
29
- apiKey: process.env.OPENAI_API_KEY || "",
30
- logLevel: "debug",
31
- model: "gpt-4o-mini",
32
- });
33
- async function main() {
34
- const resp = await client.text("add 2 + 2", { tools: [addTool] });
35
- console.log(resp);
36
- }
37
- main();
1
+ export * from "./client.js";
2
+ export * from "./types.js";
3
+ export * from "./models.js";
4
+ export * from "./smolError.js";
5
+ export * from "./util.js";
6
+ export * from "./classes/message/index.js";
@@ -0,0 +1,2 @@
1
+ import { EgonLog, LogLevel } from "egonlog";
2
+ export declare function getLogger(level?: LogLevel): EgonLog;
package/dist/logger.js ADDED
@@ -0,0 +1,9 @@
1
+ import { EgonLog } from "egonlog";
2
+ let loggerInstance = null;
3
+ export function getLogger(level = "error") {
4
+ if (loggerInstance) {
5
+ return loggerInstance;
6
+ }
7
+ loggerInstance = new EgonLog({ level });
8
+ return loggerInstance;
9
+ }
@@ -1,14 +1,12 @@
1
1
  export * from "./types/result.js";
2
- import { EgonLog, LogLevel } from "egonlog";
2
+ import { LogLevel } from "egonlog";
3
3
  import { ModelName } from "./models.js";
4
- import { Result } from "./index.js";
4
+ import { Message } from "./classes/message/index.js";
5
+ import { Result } from "./types/result.js";
6
+ import { ToolCall } from "./classes/ToolCall.js";
5
7
  export type PromptConfig<Tool = any> = {
8
+ messages: Message[];
6
9
  tools?: Tool[];
7
- messages?: {
8
- role: string;
9
- content: string;
10
- name?: string;
11
- }[];
12
10
  instructions?: string;
13
11
  maxTokens?: number;
14
12
  temperature?: number;
@@ -21,18 +19,16 @@ export type SmolConfig = {
21
19
  model: ModelName;
22
20
  logLevel?: LogLevel;
23
21
  };
24
- export type BaseClientConfig = SmolConfig & {
25
- logger: EgonLog;
26
- };
27
- export type ToolCall = {
28
- id: string;
29
- name: string;
30
- arguments: Record<string, any>;
31
- };
22
+ export type BaseClientConfig = SmolConfig & {};
32
23
  export type PromptResult = {
33
24
  output: string | null;
34
25
  toolCalls: ToolCall[];
35
26
  };
36
27
  export interface SmolClient {
37
- text(content: string, config?: PromptConfig): Promise<Result<PromptResult>>;
28
+ text(config: PromptConfig): Promise<Result<PromptResult>>;
29
+ prompt(text: string, config?: PromptConfig): Promise<Result<PromptResult>>;
38
30
  }
31
+ export type TextPart = {
32
+ type: "text";
33
+ text: string;
34
+ };
@@ -1,4 +1,2 @@
1
1
  import { ChatCompletionMessageFunctionToolCall, ChatCompletionMessageToolCall } from "openai/resources";
2
- import { ToolCall } from "../types.js";
3
- export declare function openAIToToolCall(toolCall: ChatCompletionMessageFunctionToolCall): ToolCall;
4
2
  export declare function isFunctionToolCall(message: ChatCompletionMessageToolCall): message is ChatCompletionMessageFunctionToolCall;
@@ -0,0 +1,3 @@
1
+ export function isFunctionToolCall(message) {
2
+ return message.type === "function";
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smoltalk",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "A common interface for LLM APIs",
5
5
  "homepage": "https://github.com/egonSchiele/smoltalk",
6
6
  "scripts": {
@@ -1,11 +0,0 @@
1
- import { GoogleGenAI } from "@google/genai";
2
- import { BaseClientConfig, PromptConfig, PromptResult, Result } from "../types.js";
3
- export type SmolGoogleConfig = BaseClientConfig;
4
- export declare class SmolGoogle implements SmolClient {
5
- private client;
6
- private logger;
7
- private model;
8
- constructor(config: SmolGoogleConfig);
9
- getClient(): GoogleGenAI;
10
- text(content: string, config?: PromptConfig): Promise<Result<PromptResult>>;
11
- }
@@ -1,39 +0,0 @@
1
- // @ts-nocheck
2
- import { GoogleGenAI } from "@google/genai";
3
- import { success, } from "../types.js";
4
- export class SmolGoogle {
5
- client;
6
- logger;
7
- model;
8
- constructor(config) {
9
- this.client = new GoogleGenAI({ apiKey: config.apiKey });
10
- this.logger = config.logger;
11
- this.model = config.model;
12
- }
13
- getClient() {
14
- return this.client;
15
- }
16
- async text(content, config) {
17
- const messages = structuredClone(config?.messages) || [];
18
- messages.push({ role: "user", content });
19
- /* const contents = messages.map((message) => ({
20
- role: message.role === "user" ? "user" : "model", // Use consistent roles
21
- parts: [makePart(message)] as Part[],
22
- }));
23
-
24
- role: "user",
25
- parts: [{ text: sanitizedPrompt }],
26
- });
27
- contents.push({
28
- */
29
- // Send the prompt as the latest message
30
- const result = await this.client.models.generateContent({
31
- contents: content,
32
- model: this.model,
33
- });
34
- //console.log("Full response:", JSON.stringify(result, null, 2));
35
- const text = result.text;
36
- // Return the response, updating the chat history
37
- return success({ output: result.text, toolCalls: [] });
38
- }
39
- }
@@ -1,4 +0,0 @@
1
- export * from "./client.js";
2
- export * from "./types.js";
3
- export * from "./models.js";
4
- export * from "./smolError.js";
package/dist/lib/index.js DELETED
@@ -1,4 +0,0 @@
1
- export * from "./client.js";
2
- export * from "./types.js";
3
- export * from "./models.js";
4
- export * from "./smolError.js";
@@ -1,10 +0,0 @@
1
- export function openAIToToolCall(toolCall) {
2
- return {
3
- id: toolCall.id,
4
- name: toolCall.function.name,
5
- arguments: JSON.parse(toolCall.function.arguments),
6
- };
7
- }
8
- export function isFunctionToolCall(message) {
9
- return message.type === "function";
10
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes