Function
zodTextFormat
(
zodObject: ZodInput,
name: string,
props?: Omit<
ResponseFormatTextJSONSchemaConfig,
'schema' | 'type' | 'strict' | 'name'
>
)
Source from the content-addressed store, hash-verified
| 53 | * @returns An auto-parseable text format for use with OpenAI's API |
| 54 | */ |
| 55 | export function zodTextFormat<ZodInput extends z.ZodType>( |
| 56 | zodObject: ZodInput, |
| 57 | name: string, |
| 58 | props?: Omit< |
| 59 | ResponseFormatTextJSONSchemaConfig, |
| 60 | 'schema' | 'type' | 'strict' | 'name' |
| 61 | > |
| 62 | ): AutoParseableTextFormat<z.infer<ZodInput>> { |
| 63 | return makeParseableTextFormat( |
| 64 | { |
| 65 | type: 'json_schema', |
| 66 | ...props, |
| 67 | name, |
| 68 | strict: true, |
| 69 | schema: z.toJSONSchema(zodObject, { target: 'draft-7' }) |
| 70 | }, |
| 71 | content => zodObject.parse(JSON.parse(content)) |
| 72 | ) |
| 73 | } |
Tested by
no test coverage detected