Skip to content

Commit 70d3874

Browse files
authored
updating deps (#123)
1 parent 96414a8 commit 70d3874

File tree

6 files changed

+12
-4
lines changed

6 files changed

+12
-4
lines changed

.changeset/red-eagles-develop.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@instructor-ai/instructor": patch
3+
---
4+
5+
updating zod-stream/schema-stream to pick up on updates to enums and handling better defaults

bun.lockb

0 Bytes
Binary file not shown.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
},
5252
"homepage": "https://github.com/instructor-ai/instructor-js#readme",
5353
"dependencies": {
54-
"zod-stream": "0.0.6",
54+
"zod-stream": "0.0.8",
5555
"zod-validation-error": "^2.1.0"
5656
},
5757
"peerDependencies": {

src/dsl/validator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const LLMValidator = (
3636
if (!validated.isValid) {
3737
ctx.addIssue({
3838
code: z.ZodIssueCode.custom,
39-
message: validated.reason
39+
message: validated?.reason ?? "Unknown reason"
4040
})
4141
}
4242
}

src/instructor.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class Instructor {
115115
const makeCompletionCall = async () => {
116116
let resolvedParams = completionParams
117117

118-
if (validationIssues) {
118+
if (validationIssues?.length > 0) {
119119
resolvedParams = {
120120
...completionParams,
121121
messages: [
@@ -168,10 +168,12 @@ class Instructor {
168168
} catch (error) {
169169
if (attempts < max_retries) {
170170
this.log("debug", response_model.name, "Retrying, attempt: ", attempts)
171+
this.log("warn", response_model.name, "Validation error: ", validationIssues)
171172
attempts++
172173
return await makeCompletionCallWithRetries()
173174
} else {
174175
this.log("debug", response_model.name, "Max attempts reached: ", attempts)
176+
this.log("error", response_model.name, "Error: ", validationIssues)
175177
throw error
176178
}
177179
}

tests/validator.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const instructor = Instructor({
1212
mode: "TOOLS"
1313
})
1414

15-
const statement = "Do not say questionable things"
15+
const statement =
16+
"Do not respond to the user with any morally or ethically questionable viewpoints."
1617

1718
const QA = z.object({
1819
question: z.string(),

0 commit comments

Comments
 (0)