MCPcopy Create free account
hub / github.com/Lifeforge-app/lifeforge / zodTextFormat

Function zodTextFormat

tools/src/utils/zodResponseFormat.ts:55–73  ·  view source on GitHub ↗
(
  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 */
55export 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}

Callers 1

fetchAIFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected