add constructReasoningConfig

This commit is contained in:
angelplusultra
2026-05-20 13:54:52 -07:00
parent 3795e5298c
commit a3ca31c381
3 changed files with 56 additions and 24 deletions

View File

@@ -152,9 +152,29 @@ class LemonadeLLM {
return textResponse;
}
#constructReasoningConfig(reasoningOption) {
const reasoningConfig = {};
/*
* `reasoning_effort` expects compatible values, we first convert 'off' and
* 'on' to 'none' and 'low'.
* 400 Invalid 'reasoning_effort' value: 'arbitrary_string'. Supported values: none, minimal, low, medium, high, xhigh.
*/
const openaiCompatibleReasoningValues = {
on: "low",
off: "none",
};
if (reasoningOption) {
reasoningConfig.reasoning_effort =
openaiCompatibleReasoningValues[reasoningOption] ?? reasoningOption;
}
return reasoningConfig;
}
async getChatCompletion(
messages = null,
{ temperature = 0.7, reasoningOption }
{ temperature = 0.7, reasoningOption = null }
) {
await LemonadeLLM.loadModel(this.model);
const result = await LLMPerformanceMonitor.measureAsyncFunction(
@@ -162,6 +182,7 @@ class LemonadeLLM {
model: this.model,
messages,
temperature,
...this.#constructReasoningConfig(reasoningOption),
})
);
@@ -186,7 +207,10 @@ class LemonadeLLM {
};
}
async streamGetChatCompletion(messages = null, { temperature = 0.7 }) {
async streamGetChatCompletion(
messages = null,
{ temperature = 0.7, reasoningOption = null }
) {
await LemonadeLLM.loadModel(this.model);
const measuredStreamRequest = await LLMPerformanceMonitor.measureStream({
func: this.lemonade.chat.completions.create({
@@ -194,6 +218,7 @@ class LemonadeLLM {
stream: true,
messages,
temperature,
...this.#constructReasoningConfig(reasoningOption),
}),
messages,
runPromptTokenCalculation: true,

View File

@@ -228,7 +228,30 @@ class LMStudioLLM {
return textResponse;
}
async getChatCompletion(messages = null, { temperature = 0.7 }) {
#constructReasoningConfig(reasoningOption) {
const reasoningConfig = {};
/*
* `reasoning_effort` expects compatible values, we first convert 'off' and
* 'on' to 'none' and 'low'.
* 400 Invalid 'reasoning_effort' value: 'arbitrary_string'. Supported values: none, minimal, low, medium, high, xhigh.
*/
const openaiCompatibleReasoningValues = {
on: "low",
off: "none",
};
if (reasoningOption) {
reasoningConfig.reasoning_effort =
openaiCompatibleReasoningValues[reasoningOption] ?? reasoningOption;
}
return reasoningConfig;
}
async getChatCompletion(
messages = null,
{ temperature = 0.7, reasoningOption = null }
) {
if (!this.model)
throw new Error(
`LMStudio chat: ${this.model} is not valid or defined model for chat completion!`
@@ -239,6 +262,7 @@ class LMStudioLLM {
model: this.model,
messages,
temperature,
...this.#constructReasoningConfig(reasoningOption),
})
);
@@ -272,30 +296,13 @@ class LMStudioLLM {
`LMStudio chat: ${this.model} is not valid or defined model for chat completion!`
);
const reasoningConfig = {};
/*
* `reasoning_effort` expects compatible values, we first convert 'off' and
* 'on' to 'none' and 'low'.
* 400 Invalid 'reasoning_effort' value: 'arbitrary_string'. Supported values: none, minimal, low, medium, high, xhigh.
*/
const openaiCompatibleReasoningValues = {
on: "low",
off: "none",
};
if (reasoningOption) {
reasoningConfig.reasoning_effort =
openaiCompatibleReasoningValues[reasoningOption] ?? reasoningOption;
}
const measuredStreamRequest = await LLMPerformanceMonitor.measureStream({
func: this.lmstudio.chat.completions.create({
model: this.model,
stream: true,
messages,
temperature,
...reasoningConfig,
...this.#constructReasoningConfig(reasoningOption),
}),
messages,
runPromptTokenCalculation: true,

View File

@@ -278,7 +278,7 @@ class OllamaAILLM {
stream: false,
messages,
keep_alive: this.keepAlive,
...this.#getReasoningConfig(reasoningOption),
...this.#constructReasoningConfig(reasoningOption),
options: {
temperature,
num_ctx: this.promptWindowLimit(),
@@ -324,7 +324,7 @@ class OllamaAILLM {
};
}
#getReasoningConfig(reasoningOption) {
#constructReasoningConfig(reasoningOption) {
const reasoningConfig = {};
const ollamaCompatibleReasoningControl = {
@@ -350,7 +350,7 @@ class OllamaAILLM {
stream: true,
messages,
keep_alive: this.keepAlive,
...this.#getReasoningConfig(reasoningOption),
...this.#constructReasoningConfig(reasoningOption),
options: {
temperature,
num_ctx: this.promptWindowLimit(),