Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/api/providers/lmstudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -44,18 +45,30 @@ export class LmStudioHandler extends BaseProvider implements SingleCompletionHan
}

const results = await this.client.chat.completions.create(params)


const matcher = new XmlMatcher(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add unit or integration tests to cover the new functionality for handling 'think' tags via XmlMatcher in accordance with our testing guidelines.

This comment was generated because it violated a code review rule: mrule_oAUXVfj5l9XxF01R.

"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(
Expand Down
Loading