feat(ai): send min_p on xAI Responses (#58889)

This commit is contained in:
Aiden Cline
2026-10-25 00:27:58 -05:00
committed by GitHub
Unverified
parent 9a1f3d4250
commit 8fd2ec1b72
3 changed files with 18 additions and 1 deletions
@@ -31,9 +31,15 @@ const XAIResponsesHostedToolItem = Schema.Union([
),
])
const Options = Schema.Struct({
minP: Schema.optional(Schema.Number),
})
export type OptionsInput = typeof Options.Type
const Body = Schema.Struct({
...OpenResponses.OpenResponsesBody.fields,
top_k: Schema.optional(Schema.Number),
min_p: Schema.optional(Schema.Number),
})
const adapter = {
@@ -58,6 +64,7 @@ const fromRequest = Effect.fn("XAIResponses.fromRequest")(function* (request: LL
message:
"xAI requires explicit compaction through LLMClient.compact; automatic context management is not supported",
})
const options = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))(request.providerOptions ?? {})
const body = yield* OpenResponses.fromRequestWithAdapter(request, adapter)
// xAI Responses does not support penalties (they are ignored), but does support top_k.
return {
@@ -65,6 +72,7 @@ const fromRequest = Effect.fn("XAIResponses.fromRequest")(function* (request: LL
presence_penalty: undefined,
frequency_penalty: undefined,
top_k: request.generation?.topK,
min_p: options.minP,
}
})
+2 -1
View File
@@ -14,7 +14,8 @@ import type { ProviderPackage } from "../provider-package.js"
export const id = ProviderID.make("xai")
const baseURL = "https://api.x.ai/v1"
export type XAIProviderOptionsInput = OpenAIOptionsInput & { readonly contextManagement?: never }
export type XAIProviderOptionsInput = OpenAIOptionsInput &
XAIResponses.OptionsInput & { readonly contextManagement?: never }
export type LanguageModelOptions = Omit<RouteDefaultsInput, "providerOptions"> &
ProviderAuthOption<"optional"> & {
@@ -89,6 +89,14 @@ describe("xAI Responses route", () => {
}),
)
it.effect("sends min_p from provider options", () =>
Effect.gen(function* () {
const prepared = yield* compileRequest(LLM.request({ model, prompt: "Hello", providerOptions: { minP: 0.1 } }))
expect(prepared.body.min_p).toBe(0.1)
}),
)
it.effect("parses xAI reasoning summaries", () =>
Effect.gen(function* () {
const response = yield* LLMClient.generate(LLM.request({ model, prompt: "Think" })).pipe(