mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
LM studio reasoning support (thinking block) (#3719)
lmstudio reasoning support (thinking block) Similar to ollama implementation in #1080
This commit is contained in:
parent
82a87b30a9
commit
af6eb1fc4d
1 changed files with 17 additions and 4 deletions
|
|
@ -7,6 +7,7 @@ import { ApiHandlerOptions, ModelInfo, openAiModelInfoSaneDefaults } from "../..
|
|||
import { convertToOpenAiMessages } from "../transform/openai-format"
|
||||
import { ApiStream } from "../transform/stream"
|
||||
import { BaseProvider } from "./base-provider"
|
||||
import { XmlMatcher } from "../../utils/xml-matcher"
|
||||
|
||||
const LMSTUDIO_DEFAULT_TEMPERATURE = 0
|
||||
|
||||
|
|
@ -44,18 +45,30 @@ export class LmStudioHandler extends BaseProvider implements SingleCompletionHan
|
|||
}
|
||||
|
||||
const results = await this.client.chat.completions.create(params)
|
||||
|
||||
|
||||
const matcher = new XmlMatcher(
|
||||
"think",
|
||||
(chunk) =>
|
||||
({
|
||||
type: chunk.matched ? "reasoning" : "text",
|
||||
text: chunk.data,
|
||||
}) as const,
|
||||
)
|
||||
|
||||
// Stream handling
|
||||
// @ts-ignore
|
||||
for await (const chunk of results) {
|
||||
const delta = chunk.choices[0]?.delta
|
||||
|
||||
if (delta?.content) {
|
||||
yield {
|
||||
type: "text",
|
||||
text: delta.content,
|
||||
for (const chunk of matcher.update(delta.content)) {
|
||||
yield chunk
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const chunk of matcher.final()) {
|
||||
yield chunk
|
||||
}
|
||||
} catch (error) {
|
||||
// LM Studio doesn't return an error code/body for now
|
||||
throw new Error(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue