smoltalk 0.0.26 → 0.0.28
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 +11 -0
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { userMessage, assistantMessage } from "../classes/message/index.js";
|
|
2
2
|
import { getLogger } from "../logger.js";
|
|
3
3
|
import { success, } from "../types.js";
|
|
4
|
+
import { z } from "zod";
|
|
4
5
|
const DEFAULT_NUM_RETRIES = 2;
|
|
5
6
|
export class BaseClient {
|
|
6
7
|
config;
|
|
@@ -136,6 +137,13 @@ export class BaseClient {
|
|
|
136
137
|
async textWithRetry(promptConfig, retries) {
|
|
137
138
|
const result = await this._textSync(promptConfig);
|
|
138
139
|
if (result.success) {
|
|
140
|
+
if (!("output" in result.value)) {
|
|
141
|
+
const retryMessages = [
|
|
142
|
+
...promptConfig.messages,
|
|
143
|
+
userMessage(`You returned "undefined" instead of a valid response. Please provide a valid response.`),
|
|
144
|
+
];
|
|
145
|
+
return this.textWithRetry({ ...promptConfig, messages: retryMessages }, retries - 1);
|
|
146
|
+
}
|
|
139
147
|
const { output } = result.value;
|
|
140
148
|
if (output !== null &&
|
|
141
149
|
promptConfig.responseFormat &&
|
|
@@ -154,6 +162,9 @@ export class BaseClient {
|
|
|
154
162
|
const errorMessage = err.message;
|
|
155
163
|
const logger = getLogger();
|
|
156
164
|
logger.error(`Response format validation failed (retries left: ${retries}): `, errorMessage, "output:", JSON.stringify(output, null, 2), "responseFormat:", JSON.stringify(promptConfig.responseFormat, null, 2));
|
|
165
|
+
if (err instanceof z.ZodError) {
|
|
166
|
+
logger.error("Zod error details:", z.prettifyError(err));
|
|
167
|
+
}
|
|
157
168
|
const retryMessages = [
|
|
158
169
|
...promptConfig.messages,
|
|
159
170
|
assistantMessage(output),
|