mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
feat(ai): send a per-entry reasoning effort to Local and gateway providers
Reasoning models on Ollama and similar servers think by default and can spend the whole max_tokens budget before the visible answer starts, so the call comes back empty or times out. The Local and OpenAI-compatible chain entries now carry an optional reasoning setting: Default sends nothing, Off sends reasoning_effort "none", Low / Medium / High send their own value. It is stored on the entry in aiProviderChain, so a chain can mix a thinking model with one that does not know the field. - Every exported resolver binds the entry's value onto the client, the connection test included, keyed on the instance type so the operator provider, OpenAI, Anthropic and Codex never carry it. - PATCH /api/user/ai-provider accepts localReasoningEffort and compatReasoningEffort and GET reports them. A provider absent from the chain holds its value on a disabled entry; restating Default on a chain that was never customised writes nothing. - PUT /api/insights/provider-chain accepts reasoningEffort on local and openai-compatible entries, refuses it on any other, and keeps the stored value when the body leaves it out. Its schema is now shared with the OpenAPI registry. - A Default request body is byte-identical to the one sent before. Refs #1126
This commit is contained in:
1 parent
808b2672cd
commit
befac59576
18 files changed
+1350
-84
No files matched your search
@@ -16,6 +16,12 @@
|
||||
*/
|
||||
import { z } from "zod/v4";
|
||||
|
||||
import { PROVIDER_CHAIN_TYPES } from "@/lib/ai/provider-chain";
|
||||
import {
|
||||
isReasoningProviderType,
|
||||
REASONING_EFFORTS,
|
||||
} from "@/lib/ai/reasoning-effort";
|
||||
|
||||
/** The five provider kinds a user may select. */
|
||||
export const AI_PROVIDER_KINDS = [
|
||||
"OPENAI",
|
||||
@@ -38,6 +44,17 @@ export const aiProviderKindSchema = z.enum(AI_PROVIDER_KINDS);
|
||||
*/
|
||||
const clearableString = z.string().nullable();
|
||||
|
||||
/**
|
||||
* #1126 — a provider entry's reasoning setting. `null` is "Default": nothing
|
||||
* is sent and the model decides. `none` is "Off".
|
||||
*/
|
||||
export const reasoningEffortSchema = z
|
||||
.enum(REASONING_EFFORTS)
|
||||
.nullable()
|
||||
.describe(
|
||||
"Reasoning setting for a Local or OpenAI-compatible provider, sent as `reasoning_effort` in the `/chat/completions` body. `none` switches reasoning off, which stops a thinking model (Gemma, Qwen and the like) spending the answer budget on reasoning. `null` is Default: the key is not sent at all and the model decides.",
|
||||
);
|
||||
|
||||
/**
|
||||
* `PATCH /api/user/ai-provider` — a partial update of the provider config.
|
||||
*
|
||||
@@ -93,6 +110,22 @@ export const aiProviderPatchSchema = z.object({
|
||||
.max(600, "Response timeout must be between 10 and 600 seconds")
|
||||
.nullable()
|
||||
.optional(),
|
||||
/**
|
||||
* #1126 — the reasoning setting of the Local entry. Stored on the entry in
|
||||
* the provider chain; a chain never customised is materialised from the
|
||||
* default to hold it. `null` restores Default.
|
||||
*/
|
||||
localReasoningEffort: reasoningEffortSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Reasoning setting of the Local provider entry, stored on that entry of the provider chain. `none` = Off, `null` = Default (nothing sent). Omitted leaves it untouched.",
|
||||
),
|
||||
/** #1126 — the same for the OpenAI-compatible gateway entry. */
|
||||
compatReasoningEffort: reasoningEffortSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Reasoning setting of the OpenAI-compatible gateway entry, stored on that entry of the provider chain. `none` = Off, `null` = Default (nothing sent). Omitted leaves it untouched.",
|
||||
),
|
||||
});
|
||||
|
||||
export type AiProviderPatchInput = z.infer<typeof aiProviderPatchSchema>;
|
||||
@@ -115,3 +148,61 @@ export const aiTestOverrideSchema = z
|
||||
.strict();
|
||||
|
||||
export type AiTestOverrideInput = z.infer<typeof aiTestOverrideSchema>;
|
||||
|
||||
/**
|
||||
* One entry of `PUT /api/insights/provider-chain`. Shared by the route and the
|
||||
* OpenAPI registry, so the published contract and the parser are one object.
|
||||
*/
|
||||
export const providerChainEntrySchema = z
|
||||
.object({
|
||||
providerType: z
|
||||
.enum(PROVIDER_CHAIN_TYPES)
|
||||
.describe(
|
||||
"Closed allow-list. The mock provider is excluded from it structurally, which is what keeps production from reaching one.",
|
||||
),
|
||||
// Priority is recomputed server-side from insertion order so a stale
|
||||
// client cannot persist a chain whose displayed order disagrees with
|
||||
// its priority field. The number is accepted (and may be present) but
|
||||
// ignored on the wire.
|
||||
priority: z
|
||||
.number()
|
||||
.int()
|
||||
.optional()
|
||||
.describe(
|
||||
"ACCEPTED AND IGNORED. Priority is recomputed from the array's insertion order, so a stale client cannot persist a chain whose displayed order disagrees with its stored one. Send the order you want as the order of the array.",
|
||||
),
|
||||
enabled: z.boolean(),
|
||||
reasoningEffort: reasoningEffortSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Only on a `local` or `openai-compatible` entry; refused on any other. Omitted keeps the value already stored for that provider, `null` restores Default, `none` / `low` / `medium` / `high` are sent as `reasoning_effort`.",
|
||||
),
|
||||
})
|
||||
.strict()
|
||||
.superRefine((entry, ctx) => {
|
||||
if (
|
||||
entry.reasoningEffort !== undefined &&
|
||||
!isReasoningProviderType(entry.providerType)
|
||||
) {
|
||||
ctx.addIssue({
|
||||
code: "custom",
|
||||
path: ["reasoningEffort"],
|
||||
message:
|
||||
"A reasoning setting applies to the local and openai-compatible providers only",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const providerChainPutSchema = z
|
||||
.object({
|
||||
chain: z
|
||||
.array(providerChainEntrySchema)
|
||||
.min(1, "Chain must contain at least one provider")
|
||||
.max(PROVIDER_CHAIN_TYPES.length, "Too many providers")
|
||||
.describe(
|
||||
"The whole chain, in the order it should be walked. At least one entry and at most one per known provider type; a repeated type is refused.",
|
||||
),
|
||||
})
|
||||
.strict();
|
||||
|
||||
export type ProviderChainPutInput = z.infer<typeof providerChainPutSchema>;
|
||||
Reference in new issue
Block a user