Support Dynamic Thinking Models (#23281)
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
CI / AMD64 Build (push) Waiting to run
CI / ARM Extra Build (push) Blocked by required conditions

* Add ability to toggle thinking

* Disable thinking for descriptions automatically

* mypy

* Cleanup
This commit is contained in:
Nicolas Mowen
2026-05-21 12:54:23 -05:00
committed by GitHub
parent 555ef89800
commit 66a2417229
16 changed files with 410 additions and 175 deletions
+13 -1
View File
@@ -34,12 +34,17 @@ type StreamChunk =
* POST to chat/completion with stream: true, parse NDJSON stream, and invoke
* callbacks so the caller can update UI (e.g. React state).
*/
export type StreamChatOptions = {
enableThinking?: boolean;
};
export async function streamChatCompletion(
url: string,
headers: Record<string, string>,
apiMessages: { role: string; content: string }[],
callbacks: StreamChatCallbacks,
signal?: AbortSignal,
options: StreamChatOptions = {},
): Promise<void> {
const {
updateMessages,
@@ -50,10 +55,17 @@ export async function streamChatCompletion(
} = callbacks;
try {
const body: Record<string, unknown> = {
messages: apiMessages,
stream: true,
};
if (options.enableThinking !== undefined) {
body.enable_thinking = options.enableThinking;
}
const res = await fetch(url, {
method: "POST",
headers,
body: JSON.stringify({ messages: apiMessages, stream: true }),
body: JSON.stringify(body),
signal,
});