feat(ai): support custom reasoning fields (#38227)
This commit is contained in:
parent
69c05ae3fc
commit
23483ea013
24 changed files with 306 additions and 67 deletions
|
|
@ -41,6 +41,17 @@ export interface Ref extends Schema.Schema.Type<typeof Ref> {}
|
|||
export const Family = Schema.String.pipe(Schema.brand("Model.Family"))
|
||||
export type Family = typeof Family.Type
|
||||
|
||||
export type ReasoningField = "reasoning" | "reasoning_content" | "reasoning_text" | (string & {})
|
||||
export const ReasoningField: Schema.Codec<ReasoningField> = Schema.Union([
|
||||
Schema.Literals(["reasoning", "reasoning_content", "reasoning_text"]),
|
||||
Schema.String,
|
||||
]).annotate({ identifier: "Model.ReasoningField" })
|
||||
|
||||
export interface Compatibility extends Schema.Schema.Type<typeof Compatibility> {}
|
||||
export const Compatibility = Schema.Struct({
|
||||
reasoningField: ReasoningField.pipe(optional),
|
||||
}).annotate({ identifier: "Model.Compatibility" })
|
||||
|
||||
export interface Capabilities extends Schema.Schema.Type<typeof Capabilities> {}
|
||||
export const Capabilities = Schema.Struct({
|
||||
tools: Schema.Boolean,
|
||||
|
|
@ -75,6 +86,7 @@ export const Info = Schema.Struct({
|
|||
providerID: Provider.ID,
|
||||
family: Family.pipe(optional),
|
||||
name: Schema.String,
|
||||
compatibility: Compatibility.pipe(optional),
|
||||
package: Provider.Package.pipe(optional),
|
||||
...Provider.Overlays,
|
||||
capabilities: Capabilities,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { describe, expect, test } from "bun:test"
|
||||
import { Schema } from "effect"
|
||||
import { Model } from "../src/model.js"
|
||||
|
||||
describe("Model.Ref", () => {
|
||||
|
|
@ -20,3 +21,12 @@ describe("Model.Ref", () => {
|
|||
expect(() => Model.Ref.parse("openai/gpt-5#high#extra")).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe("Model.ReasoningField", () => {
|
||||
test("accepts suggested and custom fields", () => {
|
||||
const decode = Schema.decodeUnknownSync(Model.ReasoningField)
|
||||
|
||||
for (const field of ["reasoning", "reasoning_content", "reasoning_text", "vendor_reasoning"])
|
||||
expect(decode(field)).toBe(field)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue