mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 04:15:30 +00:00
fix(ask): Extract reasoning tokens for openai compatible models (#582)
This commit is contained in:
parent
727a6da105
commit
d09d65dce7
10 changed files with 113 additions and 2 deletions
|
|
@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- [ask sb] Fixed issue where reasoning tokens would appear in `text` content for openai compatible models. [#582](https://github.com/sourcebot-dev/sourcebot/pull/582)
|
||||||
|
|
||||||
## [4.8.1] - 2025-10-29
|
## [4.8.1] - 2025-10-29
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
||||||
|
|
@ -292,6 +292,7 @@ The OpenAI compatible provider allows you to use any model that is compatible wi
|
||||||
|
|
||||||
<Accordion title="Troubleshooting">
|
<Accordion title="Troubleshooting">
|
||||||
- When using [llama.cpp](https://github.com/ggml-org/llama.cpp), if you hit "Failed after 3 attempts. Last error: tools param requires --jinja flag", add the `--jinja` flag to your `llama-server` command.
|
- When using [llama.cpp](https://github.com/ggml-org/llama.cpp), if you hit "Failed after 3 attempts. Last error: tools param requires --jinja flag", add the `--jinja` flag to your `llama-server` command.
|
||||||
|
- If you're seeing the LLM outputing reasoning tokens wrapped in XML tags (e.g., `<reasoning>`, `<thinking>`, etc.), you can configure the `reasoningTag` parameter to the name of the tag (without angle brackets). This parameter defaults to `think`.
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
### OpenRouter
|
### OpenRouter
|
||||||
|
|
|
||||||
|
|
@ -2633,6 +2633,16 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"reasoningTag": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The name of the XML tag to extract reasoning from (without angle brackets). Defaults to `think`.",
|
||||||
|
"default": "think",
|
||||||
|
"examples": [
|
||||||
|
"think",
|
||||||
|
"thinking",
|
||||||
|
"reasoning"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
|
|
@ -4052,6 +4062,16 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"reasoningTag": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The name of the XML tag to extract reasoning from (without angle brackets). Defaults to `think`.",
|
||||||
|
"default": "think",
|
||||||
|
"examples": [
|
||||||
|
"think",
|
||||||
|
"thinking",
|
||||||
|
"reasoning"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
|
|
|
||||||
|
|
@ -1202,6 +1202,16 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"reasoningTag": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The name of the XML tag to extract reasoning from (without angle brackets). Defaults to `think`.",
|
||||||
|
"default": "think",
|
||||||
|
"examples": [
|
||||||
|
"think",
|
||||||
|
"thinking",
|
||||||
|
"reasoning"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
|
|
@ -2621,6 +2631,16 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"reasoningTag": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The name of the XML tag to extract reasoning from (without angle brackets). Defaults to `think`.",
|
||||||
|
"default": "think",
|
||||||
|
"examples": [
|
||||||
|
"think",
|
||||||
|
"thinking",
|
||||||
|
"reasoning"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
|
|
|
||||||
|
|
@ -2632,6 +2632,16 @@ const schema = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"reasoningTag": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The name of the XML tag to extract reasoning from (without angle brackets). Defaults to `think`.",
|
||||||
|
"default": "think",
|
||||||
|
"examples": [
|
||||||
|
"think",
|
||||||
|
"thinking",
|
||||||
|
"reasoning"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
|
|
@ -4051,6 +4061,16 @@ const schema = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"reasoningTag": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The name of the XML tag to extract reasoning from (without angle brackets). Defaults to `think`.",
|
||||||
|
"default": "think",
|
||||||
|
"examples": [
|
||||||
|
"think",
|
||||||
|
"thinking",
|
||||||
|
"reasoning"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
|
|
|
||||||
|
|
@ -974,6 +974,10 @@ export interface OpenAICompatibleLanguageModel {
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
headers?: LanguageModelHeaders;
|
headers?: LanguageModelHeaders;
|
||||||
queryParams?: LanguageModelQueryParams;
|
queryParams?: LanguageModelQueryParams;
|
||||||
|
/**
|
||||||
|
* The name of the XML tag to extract reasoning from (without angle brackets). Defaults to `think`.
|
||||||
|
*/
|
||||||
|
reasoningTag?: string;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Optional query parameters to include in the request url.
|
* Optional query parameters to include in the request url.
|
||||||
|
|
|
||||||
|
|
@ -1201,6 +1201,16 @@ const schema = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"reasoningTag": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The name of the XML tag to extract reasoning from (without angle brackets). Defaults to `think`.",
|
||||||
|
"default": "think",
|
||||||
|
"examples": [
|
||||||
|
"think",
|
||||||
|
"thinking",
|
||||||
|
"reasoning"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
|
|
@ -2620,6 +2630,16 @@ const schema = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"reasoningTag": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The name of the XML tag to extract reasoning from (without angle brackets). Defaults to `think`.",
|
||||||
|
"default": "think",
|
||||||
|
"examples": [
|
||||||
|
"think",
|
||||||
|
"thinking",
|
||||||
|
"reasoning"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
|
|
|
||||||
|
|
@ -453,6 +453,10 @@ export interface OpenAICompatibleLanguageModel {
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
headers?: LanguageModelHeaders;
|
headers?: LanguageModelHeaders;
|
||||||
queryParams?: LanguageModelQueryParams;
|
queryParams?: LanguageModelQueryParams;
|
||||||
|
/**
|
||||||
|
* The name of the XML tag to extract reasoning from (without angle brackets). Defaults to `think`.
|
||||||
|
*/
|
||||||
|
reasoningTag?: string;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Optional query parameters to include in the request url.
|
* Optional query parameters to include in the request url.
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import { ChatVisibility, OrgRole, Prisma, PrismaClient } from "@sourcebot/db";
|
||||||
import { LanguageModel } from "@sourcebot/schemas/v3/languageModel.type";
|
import { LanguageModel } from "@sourcebot/schemas/v3/languageModel.type";
|
||||||
import { Token } from "@sourcebot/schemas/v3/shared.type";
|
import { Token } from "@sourcebot/schemas/v3/shared.type";
|
||||||
import { loadConfig } from "@sourcebot/shared";
|
import { loadConfig } from "@sourcebot/shared";
|
||||||
import { generateText, JSONValue } from "ai";
|
import { generateText, JSONValue, extractReasoningMiddleware, wrapLanguageModel } from "ai";
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { StatusCodes } from "http-status-codes";
|
import { StatusCodes } from "http-status-codes";
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
@ -568,8 +568,17 @@ export const _getAISDKLanguageModelAndOptions = async (config: LanguageModel, or
|
||||||
: undefined,
|
: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
const model = wrapLanguageModel({
|
||||||
model: openai.chatModel(modelId),
|
model: openai.chatModel(modelId),
|
||||||
|
middleware: [
|
||||||
|
extractReasoningMiddleware({
|
||||||
|
tagName: config.reasoningTag ?? 'think',
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
model,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'openrouter': {
|
case 'openrouter': {
|
||||||
|
|
|
||||||
|
|
@ -425,6 +425,16 @@
|
||||||
},
|
},
|
||||||
"queryParams": {
|
"queryParams": {
|
||||||
"$ref": "./shared.json#/definitions/LanguageModelQueryParams"
|
"$ref": "./shared.json#/definitions/LanguageModelQueryParams"
|
||||||
|
},
|
||||||
|
"reasoningTag": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The name of the XML tag to extract reasoning from (without angle brackets). Defaults to `think`.",
|
||||||
|
"default": "think",
|
||||||
|
"examples": [
|
||||||
|
"think",
|
||||||
|
"thinking",
|
||||||
|
"reasoning"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue