Update reasoning/local.js
Browse files- reasoning/local.js +1 -25
reasoning/local.js
CHANGED
@@ -1,6 +1,4 @@
|
|
1 |
-
// local.js
|
2 |
import { strictFormat } from '../utils/text.js';
|
3 |
-
import { log } from '../../logger.js';
|
4 |
|
5 |
export class Local {
|
6 |
constructor(model_name, url) {
|
@@ -22,7 +20,7 @@ export class Local {
|
|
22 |
messages.unshift({ role: 'system', content: systemMessage });
|
23 |
console.log('Messages:', messages);
|
24 |
|
25 |
-
// We'll do up to 5 attempts for "deepseek-r1" if the <think> tags are mismatched
|
26 |
const maxAttempts = 5;
|
27 |
let attempt = 0;
|
28 |
let finalRes = null;
|
@@ -63,36 +61,15 @@ export class Local {
|
|
63 |
// Attempt another loop iteration to get a complete or no-think response
|
64 |
continue;
|
65 |
}
|
66 |
-
|
67 |
-
// LOGGING:
|
68 |
-
// We only log if the response does not contain "Error:" or "exception:"
|
69 |
-
if (res && !res.includes("Error:") && !res.includes("exception:")) {
|
70 |
-
log(JSON.stringify(messages), res);
|
71 |
-
} else {
|
72 |
-
// If there’s a potential error in the content, skip logging
|
73 |
-
console.warn(`Not logging due to potential error in model response: ${res}`);
|
74 |
-
}
|
75 |
-
|
76 |
// If both tags appear, remove them (and everything inside)
|
77 |
if (hasOpenTag && hasCloseTag) {
|
78 |
res = res.replace(/<think>[\s\S]*?<\/think>/g, '');
|
79 |
}
|
80 |
}
|
81 |
-
|
82 |
-
// LOGGING:
|
83 |
-
// We only log if the response does not contain "Error:" or "exception:"
|
84 |
-
if (res && !res.includes("Error:") && !res.includes("exception:")) {
|
85 |
-
log(JSON.stringify(messages), res);
|
86 |
-
} else {
|
87 |
-
// If there’s a potential error in the content, skip logging
|
88 |
-
console.warn(`Not logging due to potential error in model response: ${res}`);
|
89 |
-
}
|
90 |
-
|
91 |
// We made it here with either a fully valid or not-needed to handle <think> scenario
|
92 |
finalRes = res;
|
93 |
break; // Break out of the while loop
|
94 |
}
|
95 |
-
|
96 |
// If after max attempts we STILL have partial tags, finalRes might be partial
|
97 |
// Or we never set finalRes because all attempts threw partial tags
|
98 |
if (finalRes == null) {
|
@@ -100,7 +77,6 @@ export class Local {
|
|
100 |
console.warn("Could not get a valid <think> block or normal response after max attempts.");
|
101 |
finalRes = 'Response incomplete, please try again.';
|
102 |
}
|
103 |
-
|
104 |
return finalRes;
|
105 |
}
|
106 |
|
|
|
|
|
1 |
import { strictFormat } from '../utils/text.js';
|
|
|
2 |
|
3 |
export class Local {
|
4 |
constructor(model_name, url) {
|
|
|
20 |
messages.unshift({ role: 'system', content: systemMessage });
|
21 |
console.log('Messages:', messages);
|
22 |
|
23 |
+
// We'll do up to 5 attempts for "deepseek-r1" as well as Andy_3.5 if the <think> tags are mismatched
|
24 |
const maxAttempts = 5;
|
25 |
let attempt = 0;
|
26 |
let finalRes = null;
|
|
|
61 |
// Attempt another loop iteration to get a complete or no-think response
|
62 |
continue;
|
63 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
// If both tags appear, remove them (and everything inside)
|
65 |
if (hasOpenTag && hasCloseTag) {
|
66 |
res = res.replace(/<think>[\s\S]*?<\/think>/g, '');
|
67 |
}
|
68 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
// We made it here with either a fully valid or not-needed to handle <think> scenario
|
70 |
finalRes = res;
|
71 |
break; // Break out of the while loop
|
72 |
}
|
|
|
73 |
// If after max attempts we STILL have partial tags, finalRes might be partial
|
74 |
// Or we never set finalRes because all attempts threw partial tags
|
75 |
if (finalRes == null) {
|
|
|
77 |
console.warn("Could not get a valid <think> block or normal response after max attempts.");
|
78 |
finalRes = 'Response incomplete, please try again.';
|
79 |
}
|
|
|
80 |
return finalRes;
|
81 |
}
|
82 |
|