Skip to content

Commit 11f5ab4

Browse files
committed
change scope of _isThinking variable and it's encapsulation
1 parent 936dc9d commit 11f5ab4

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

core/llm/llms/Ollama.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ class Ollama extends BaseLLM implements ModelInstaller {
159159
private static modelsBeingInstalled: Set<string> = new Set();
160160
private static modelsBeingInstalledMutex = new Mutex();
161161

162-
private static _isThinking: boolean = false;
163162
private fimSupported: boolean = false;
164163
constructor(options: LLMOptions) {
165164
super(options);
@@ -402,15 +401,6 @@ class Ollama extends BaseLLM implements ModelInstaller {
402401
}
403402
}
404403

405-
static GetIsThinking(): boolean {
406-
return this._isThinking;
407-
}
408-
static SetIsThinking(newValue: boolean): void {
409-
if (this._isThinking !== newValue) {
410-
this._isThinking = newValue;
411-
}
412-
}
413-
414404
protected async *_streamChat(
415405
messages: ChatMessage[],
416406
signal: AbortSignal,
@@ -450,7 +440,15 @@ class Ollama extends BaseLLM implements ModelInstaller {
450440
body: JSON.stringify(chatOptions),
451441
signal,
452442
});
453-
443+
let _isThinking: boolean = false;
444+
function GetIsThinking(): boolean {
445+
return _isThinking;
446+
}
447+
function SetIsThinking(newValue: boolean): void {
448+
if (_isThinking !== newValue) {
449+
_isThinking = newValue;
450+
}
451+
}
454452
function convertChatMessage(res: OllamaChatResponse): ChatMessage[] {
455453
if ("error" in res) {
456454
throw new Error(res.error);
@@ -460,18 +458,18 @@ class Ollama extends BaseLLM implements ModelInstaller {
460458
const { content } = res;
461459

462460
if (content === "<think>") {
463-
Ollama.SetIsThinking(true);
461+
SetIsThinking(true);
464462
}
465463

466-
if (Ollama.GetIsThinking() && content) {
464+
if (GetIsThinking() && content) {
467465
const thinkingMessage: ThinkingChatMessage = {
468466
role: "thinking",
469467
content: content,
470468
};
471469

472470
if (thinkingMessage) {
473471
if (content === "</think>") {
474-
Ollama.SetIsThinking(false);
472+
SetIsThinking(false);
475473
}
476474
// When Streaming you can't have both thinking and content
477475
return [thinkingMessage];

0 commit comments

Comments
 (0)