chore: generate
This commit is contained in:
parent
f011d77128
commit
134f4136da
1 changed files with 12 additions and 11 deletions
|
|
@ -25,17 +25,18 @@ export const optionalNull = <const S extends Schema.Top>(schema: S) => Schema.op
|
||||||
/** OpenAI function schemas require one flat object at the top level. */
|
/** OpenAI function schemas require one flat object at the top level. */
|
||||||
export const openAiToolInputSchema = (schema: JsonSchema.JsonSchema): JsonSchema.JsonSchema => {
|
export const openAiToolInputSchema = (schema: JsonSchema.JsonSchema): JsonSchema.JsonSchema => {
|
||||||
const variants = Array.isArray(schema.anyOf) ? schema.anyOf.filter(isRecord) : []
|
const variants = Array.isArray(schema.anyOf) ? schema.anyOf.filter(isRecord) : []
|
||||||
const flattened = variants.length === 0
|
const flattened =
|
||||||
? { ...schema, type: "object" }
|
variants.length === 0
|
||||||
: {
|
? { ...schema, type: "object" }
|
||||||
...Object.fromEntries(Object.entries(schema).filter(([key]) => key !== "anyOf")),
|
: {
|
||||||
type: "object",
|
...Object.fromEntries(Object.entries(schema).filter(([key]) => key !== "anyOf")),
|
||||||
properties: variants.reduce(
|
type: "object",
|
||||||
(properties, variant) => ({ ...(isRecord(variant.properties) ? variant.properties : {}), ...properties }),
|
properties: variants.reduce(
|
||||||
{},
|
(properties, variant) => ({ ...(isRecord(variant.properties) ? variant.properties : {}), ...properties }),
|
||||||
),
|
{},
|
||||||
additionalProperties: false,
|
),
|
||||||
}
|
additionalProperties: false,
|
||||||
|
}
|
||||||
const normalized = removeNullSchemas(flattened)
|
const normalized = removeNullSchemas(flattened)
|
||||||
return isRecord(normalized) ? normalized : { type: "object" }
|
return isRecord(normalized) ? normalized : { type: "object" }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue