Skip to content

Commit 8fd2ec1

Browse files
authored
feat(ai): send min_p on xAI Responses (#58889)
1 parent 9a1f3d4 commit 8fd2ec1

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎packages/ai/src/protocols/xai-responses.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@ const XAIResponsesHostedToolItem = Schema.Union([
3131
),
3232
])
3333

34+
const Options = Schema.Struct({
35+
minP: Schema.optional(Schema.Number),
36+
})
37+
export type OptionsInput = typeof Options.Type
38+
3439
const Body = Schema.Struct({
3540
...OpenResponses.OpenResponsesBody.fields,
3641
top_k: Schema.optional(Schema.Number),
42+
min_p: Schema.optional(Schema.Number),
3743
})
3844

3945
const adapter = {
@@ -58,13 +64,15 @@ const fromRequest = Effect.fn("XAIResponses.fromRequest")(function* (request: LL
5864
message:
5965
"xAI requires explicit compaction through LLMClient.compact; automatic context management is not supported",
6066
})
67+
const options = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))(request.providerOptions ?? {})
6168
const body = yield* OpenResponses.fromRequestWithAdapter(request, adapter)
6269
// xAI Responses does not support penalties (they are ignored), but does support top_k.
6370
return {
6471
...body,
6572
presence_penalty: undefined,
6673
frequency_penalty: undefined,
6774
top_k: request.generation?.topK,
75+
min_p: options.minP,
6876
}
6977
})
7078

‎packages/ai/src/providers/xai.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import type { ProviderPackage } from "../provider-package.js"
1414
export const id = ProviderID.make("xai")
1515
const baseURL = "https://api.x.ai/v1"
1616

17-
export type XAIProviderOptionsInput = OpenAIOptionsInput & { readonly contextManagement?: never }
17+
export type XAIProviderOptionsInput = OpenAIOptionsInput &
18+
XAIResponses.OptionsInput & { readonly contextManagement?: never }
1819

1920
export type LanguageModelOptions = Omit<RouteDefaultsInput, "providerOptions"> &
2021
ProviderAuthOption<"optional"> & {

‎packages/ai/test/provider/xai-responses.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ describe("xAI Responses route", () => {
8989
}),
9090
)
9191

92+
it.effect("sends min_p from provider options", () =>
93+
Effect.gen(function* () {
94+
const prepared = yield* compileRequest(LLM.request({ model, prompt: "Hello", providerOptions: { minP: 0.1 } }))
95+
96+
expect(prepared.body.min_p).toBe(0.1)
97+
}),
98+
)
99+
92100
it.effect("parses xAI reasoning summaries", () =>
93101
Effect.gen(function* () {
94102
const response = yield* LLMClient.generate(LLM.request({ model, prompt: "Think" })).pipe(

0 commit comments

Comments
 (0)