MCPcopy Create free account
hub / github.com/Effect-TS/effect / rewriteOpenAI

Function rewriteOpenAI

packages/effect/src/unstable/ai/OpenAiStructuredOutput.ts:80–101  ·  view source on GitHub ↗
(schema: JsonSchema.JsonSchema)

Source from the content-addressed store, hash-verified

78}
79
80function rewriteOpenAI(schema: JsonSchema.JsonSchema): JsonSchema.JsonSchema {
81 return InternalStructuredOutput.walkJsonSchema(schema, (schema) => {
82 const normalized = normalizeAllOf(schema)
83 const out: JsonSchema.JsonSchema = {}
84 let unsupportedFormat: string | undefined
85 for (const [key, value] of Object.entries(normalized)) {
86 if (key === "format") {
87 if (typeof value === "string" && formats.has(value) && supportsType(key, normalized.type)) out.format = value
88 else if (typeof value === "string") unsupportedFormat = value
89 } else if (supportedKeywords.has(key) && supportsType(key, normalized.type)) {
90 if (key !== "additionalProperties" || value === false) out[key] = value
91 }
92 }
93 if (unsupportedFormat !== undefined) {
94 InternalStructuredOutput.appendDescription(out, `a value with a format of ${unsupportedFormat}`)
95 }
96 if (out.type === "object" && out.properties === undefined && out.additionalProperties === false) {
97 out.properties = {}
98 }
99 return out
100 })
101}
102
103function supportsType(key: string, type: unknown): boolean {
104 if (typeof type !== "string") return true

Callers 1

toCodecOpenAIFunction · 0.85

Calls 3

normalizeAllOfFunction · 0.85
supportsTypeFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected