Skip to content

Any chance to make it validator agnostic? #201

@damusix

Description

@damusix

I don't use Zod

Any chance the validator can be anything that has a minimum API?

EG: Anything that returns { validate(value: any): { result, error } }

Would allow technically to say:

const mySchema = Joi.object({ ... });

// or
const mySchema = { validate: (value: any): { result: MyType | null, error: Error | null }  => {

  try {
    validator.validate(value, schema)

    return { result: value, error: null }
  catch(error) {

    return { result: null, error }
  }
}}

const user = await client.chat.completions.create({
  messages: [{ role: "user", content: "Jason Liu is 30 years old" }],
  model: "gpt-3.5-turbo",
  response_model: { 
    schema: mySchema, 
    name: "User"
  }
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions