smoltalk 0.0.40 → 0.0.42

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.
@@ -65,11 +65,10 @@ export class SmolGoogle extends BaseClient {
65
65
  if (tools.length > 0) {
66
66
  genConfig.tools = [{ functionDeclarations: tools }];
67
67
  }
68
- // Google Gemini does not support combining function calling with
69
- // responseMimeType 'application/json'. When tools are present, skip
70
- // setting the JSON response format — the BaseClient's textWithRetry
71
- // will still validate/parse the response against the schema.
72
- if (config.responseFormat && tools.length === 0) {
68
+ if (config.responseFormat && tools.length > 0) {
69
+ console.error("Warning: Both responseFormat and tools are specified in the prompt config. Google Gemini does not support enforcing a response format when tools are included, so the responseFormat will be ignored.");
70
+ }
71
+ else if (config.responseFormat && tools.length === 0) {
73
72
  genConfig.responseMimeType = "application/json";
74
73
  genConfig.responseJsonSchema = config.responseFormat.toJSONSchema();
75
74
  }
@@ -1,5 +1,8 @@
1
1
  export class BaseStrategy {
2
2
  async text(config) {
3
+ if (config.hooks?.onStrategyStart) {
4
+ config.hooks.onStrategyStart(this, config);
5
+ }
3
6
  return this._text({ ...config, strategy: undefined });
4
7
  }
5
8
  async textSync(config) {
@@ -5,6 +5,10 @@ export declare class FallbackStrategy extends BaseStrategy {
5
5
  strategies: Strategy[];
6
6
  config: FallbackStrategyConfig;
7
7
  constructor(strategies: Strategy[], config: FallbackStrategyConfig);
8
- _text(config: SmolPromptConfig): Promise<import("../types.js").Result<import("../types.js").PromptResult>>;
8
+ toString(): string;
9
+ _text(config: SmolPromptConfig): Promise<import("../types.js").Result<import("../types.js").PromptResult> | import("../types.js").Success<{
10
+ output: null;
11
+ toolCalls: never[];
12
+ }>>;
9
13
  toJSON(): StrategyJSON;
10
14
  }
@@ -1,4 +1,5 @@
1
1
  import { SmolStructuredOutputError, SmolTimeoutError } from "../smolError.js";
2
+ import { success } from "../types.js";
2
3
  import { BaseStrategy } from "./baseStrategy.js";
3
4
  export class FallbackStrategy extends BaseStrategy {
4
5
  strategies;
@@ -8,6 +9,9 @@ export class FallbackStrategy extends BaseStrategy {
8
9
  this.strategies = strategies;
9
10
  this.config = config;
10
11
  }
12
+ toString() {
13
+ return `FallbackStrategy([${this.strategies.map((s) => s.toString()).join(", ")}], config: ${JSON.stringify(this.config)})`;
14
+ }
11
15
  async _text(config) {
12
16
  for (let i = 0; i < this.strategies.length; i++) {
13
17
  const strategy = this.strategies[i];
@@ -16,6 +20,11 @@ export class FallbackStrategy extends BaseStrategy {
16
20
  return result;
17
21
  }
18
22
  catch (error) {
23
+ // If the abort signal was triggered (e.g. by a race strategy winner
24
+ // or external cancellation), stop without trying further fallbacks.
25
+ if (config.abortSignal?.aborted) {
26
+ return success({ output: null, toolCalls: [] });
27
+ }
19
28
  if (error instanceof SmolTimeoutError) {
20
29
  if (this.config.fallbackOn.includes("timeout")) {
21
30
  continue;
@@ -5,6 +5,7 @@ import { StrategyJSON } from "./types.js";
5
5
  export declare class IDStrategy extends BaseStrategy {
6
6
  model: Model;
7
7
  constructor(model: Model);
8
+ toString(): string;
8
9
  _text(_config: SmolPromptConfig): Promise<import("../types.js").Result<import("../types.js").PromptResult>>;
9
10
  toJSON(): StrategyJSON;
10
11
  }
@@ -6,14 +6,14 @@ export class IDStrategy extends BaseStrategy {
6
6
  super();
7
7
  this.model = model;
8
8
  }
9
+ toString() {
10
+ return `IDStrategy(model: ${this.model.getResolvedModel()})`;
11
+ }
9
12
  async _text(_config) {
10
13
  const config = {
11
14
  ..._config,
12
15
  model: this.model.getResolvedModel(),
13
16
  };
14
- if (config.hooks?.onStrategyStart) {
15
- config.hooks.onStrategyStart(config);
16
- }
17
17
  return text({ ...config, stream: false });
18
18
  }
19
19
  toJSON() {
@@ -4,6 +4,7 @@ import { Strategy, StrategyJSON } from "./types.js";
4
4
  export declare class RaceStrategy extends BaseStrategy {
5
5
  strategies: Strategy[];
6
6
  constructor(strategies: Strategy[]);
7
+ toString(): string;
7
8
  _text(config: SmolPromptConfig): Promise<import("../types.js").Failure | import("../types.js").Success<import("../types.js").PromptResult>>;
8
9
  toJSON(): StrategyJSON;
9
10
  }
@@ -5,6 +5,9 @@ export class RaceStrategy extends BaseStrategy {
5
5
  super();
6
6
  this.strategies = strategies;
7
7
  }
8
+ toString() {
9
+ return `RaceStrategy([${this.strategies.map((s) => s.toString()).join(", ")}])`;
10
+ }
8
11
  async _text(config) {
9
12
  const controllers = this.strategies.map(() => new AbortController());
10
13
  // Link to any existing abort signal so external cancellation still works
package/dist/types.d.ts CHANGED
@@ -54,7 +54,7 @@ export type PromptConfig = {
54
54
  onToolCall: (toolCall: ToolCall) => void;
55
55
  onEnd: (result: PromptResult) => void;
56
56
  onError: (error: Error) => void;
57
- onStrategyStart: (config: SmolPromptConfig) => void;
57
+ onStrategyStart: (strategy: Strategy, config: SmolPromptConfig) => void;
58
58
  }>;
59
59
  strategy?: Strategy | StrategyJSON;
60
60
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smoltalk",
3
- "version": "0.0.40",
3
+ "version": "0.0.42",
4
4
  "description": "A common interface for LLM APIs",
5
5
  "homepage": "https://github.com/egonSchiele/smoltalk",
6
6
  "scripts": {