smoltalk 0.0.61 → 0.0.62
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/clients/baseClient.js +5 -1
- package/dist/functions.js +14 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { userMessage, assistantMessage
|
|
1
|
+
import { userMessage, assistantMessage } from "../classes/message/index.js";
|
|
2
2
|
import { latencyTracker } from "../latencyTracker.js";
|
|
3
3
|
import { getLogger } from "../util/logger.js";
|
|
4
4
|
import { SmolStructuredOutputError } from "../smolError.js";
|
|
@@ -149,6 +149,10 @@ export class BaseClient {
|
|
|
149
149
|
return rawValue;
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
|
+
// 1.5 Look for { type: "object", properties: { response: { ... } } } pattern
|
|
153
|
+
if (rawValue.type === "object" && rawValue.properties) {
|
|
154
|
+
return this.extractResponse(promptConfig, rawValue.properties, schema, depth + 1);
|
|
155
|
+
}
|
|
152
156
|
// 2. String → try JSON.parse, then recurse
|
|
153
157
|
if (typeof rawValue === "string") {
|
|
154
158
|
const stripped = rawValue
|
package/dist/functions.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { BaseMessage, messageFromJSON, } from "./classes/message/index.js";
|
|
1
2
|
import { Model } from "./model.js";
|
|
2
3
|
import { BaseStrategy } from "./strategies/baseStrategy.js";
|
|
3
4
|
import { fromJSON } from "./strategies/index.js";
|
|
5
|
+
import { getLogger } from "./util/logger.js";
|
|
4
6
|
function getStrategy(model) {
|
|
5
7
|
if (model instanceof BaseStrategy)
|
|
6
8
|
return model;
|
|
@@ -28,15 +30,27 @@ export function splitConfig(config) {
|
|
|
28
30
|
promptConfig,
|
|
29
31
|
};
|
|
30
32
|
}
|
|
33
|
+
function fixMessagesIfNecessary(messages) {
|
|
34
|
+
if (messages && messages.length > 0) {
|
|
35
|
+
if (!(messages[0] instanceof BaseMessage)) {
|
|
36
|
+
getLogger().warn("Messages are not instances of smoltalk.BaseMessage");
|
|
37
|
+
return messages.map((m) => messageFromJSON(m));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return messages;
|
|
41
|
+
}
|
|
31
42
|
export function text(config) {
|
|
32
43
|
const strategy = getStrategy(config.model);
|
|
44
|
+
config.messages = fixMessagesIfNecessary(config.messages);
|
|
33
45
|
return strategy.text(config);
|
|
34
46
|
}
|
|
35
47
|
export function textSync(config) {
|
|
36
48
|
const strategy = getStrategy(config.model);
|
|
49
|
+
config.messages = fixMessagesIfNecessary(config.messages);
|
|
37
50
|
return strategy.textSync(config);
|
|
38
51
|
}
|
|
39
52
|
export function textStream(config) {
|
|
40
53
|
const strategy = getStrategy(config.model);
|
|
54
|
+
config.messages = fixMessagesIfNecessary(config.messages);
|
|
41
55
|
return strategy.textStream(config);
|
|
42
56
|
}
|