Skip to content

Commit

Permalink
updating deps (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
roodboi committed Feb 21, 2024
1 parent 96414a8 commit 70d3874
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-eagles-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@instructor-ai/instructor": patch
---

updating zod-stream/schema-stream to pick up on updates to enums and handling better defaults
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
"homepage": "https://github.com/instructor-ai/instructor-js#readme",
"dependencies": {
"zod-stream": "0.0.6",
"zod-stream": "0.0.8",
"zod-validation-error": "^2.1.0"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/dsl/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const LLMValidator = (
if (!validated.isValid) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: validated.reason
message: validated?.reason ?? "Unknown reason"
})
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/instructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Instructor {
const makeCompletionCall = async () => {
let resolvedParams = completionParams

if (validationIssues) {
if (validationIssues?.length > 0) {
resolvedParams = {
...completionParams,
messages: [
Expand Down Expand Up @@ -168,10 +168,12 @@ class Instructor {
} catch (error) {
if (attempts < max_retries) {
this.log("debug", response_model.name, "Retrying, attempt: ", attempts)
this.log("warn", response_model.name, "Validation error: ", validationIssues)
attempts++
return await makeCompletionCallWithRetries()
} else {
this.log("debug", response_model.name, "Max attempts reached: ", attempts)
this.log("error", response_model.name, "Error: ", validationIssues)
throw error
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const instructor = Instructor({
mode: "TOOLS"
})

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

const QA = z.object({
question: z.string(),
Expand Down

0 comments on commit 70d3874

Please sign in to comment.