fix think
Browse files- server.js +6 -2
- src/components/ask-ai/ask-ai.tsx +6 -3
server.js
CHANGED
|
@@ -227,6 +227,9 @@ app.post("/api/ask-ai", async (req, res) => {
|
|
| 227 |
});
|
| 228 |
}
|
| 229 |
|
|
|
|
|
|
|
|
|
|
| 230 |
const selectedModel = MODELS.find(
|
| 231 |
(m) => m.value === model || m.label === model
|
| 232 |
);
|
|
@@ -314,8 +317,9 @@ app.post("/api/ask-ai", async (req, res) => {
|
|
| 314 |
},
|
| 315 |
]
|
| 316 |
: []),
|
| 317 |
-
...(
|
| 318 |
-
?
|
|
|
|
| 319 |
{
|
| 320 |
role: "assistant",
|
| 321 |
content: `The current code is: ${html}.`,
|
|
|
|
| 227 |
});
|
| 228 |
}
|
| 229 |
|
| 230 |
+
const isFollowUp =
|
| 231 |
+
previousPrompt && previousPrompt.length > 0 && html && html.length > 0;
|
| 232 |
+
|
| 233 |
const selectedModel = MODELS.find(
|
| 234 |
(m) => m.value === model || m.label === model
|
| 235 |
);
|
|
|
|
| 317 |
},
|
| 318 |
]
|
| 319 |
: []),
|
| 320 |
+
...(isFollowUp
|
| 321 |
+
? // TODO try to do the git diff thing to only generate the changes and not the whole html
|
| 322 |
+
[
|
| 323 |
{
|
| 324 |
role: "assistant",
|
| 325 |
content: `The current code is: ${html}.`,
|
src/components/ask-ai/ask-ai.tsx
CHANGED
|
@@ -60,6 +60,7 @@ function AskAI({
|
|
| 60 |
setIsThinking(true);
|
| 61 |
|
| 62 |
let contentResponse = "";
|
|
|
|
| 63 |
let lastRenderTime = 0;
|
| 64 |
try {
|
| 65 |
onNewPrompt(prompt);
|
|
@@ -121,10 +122,10 @@ function AskAI({
|
|
| 121 |
}
|
| 122 |
|
| 123 |
const chunk = decoder.decode(value, { stream: true });
|
| 124 |
-
|
| 125 |
if (selectedModel?.isThinker) {
|
| 126 |
-
const thinkMatch =
|
| 127 |
-
if (thinkMatch && !
|
| 128 |
if ((contentThink?.length ?? 0) < 3) {
|
| 129 |
setOpenThink(true);
|
| 130 |
}
|
|
@@ -134,6 +135,8 @@ function AskAI({
|
|
| 134 |
}
|
| 135 |
}
|
| 136 |
|
|
|
|
|
|
|
| 137 |
const newHtml = contentResponse.match(/<!DOCTYPE html>[\s\S]*/)?.[0];
|
| 138 |
if (newHtml) {
|
| 139 |
setIsThinking(false);
|
|
|
|
| 60 |
setIsThinking(true);
|
| 61 |
|
| 62 |
let contentResponse = "";
|
| 63 |
+
let thinkResponse = "";
|
| 64 |
let lastRenderTime = 0;
|
| 65 |
try {
|
| 66 |
onNewPrompt(prompt);
|
|
|
|
| 122 |
}
|
| 123 |
|
| 124 |
const chunk = decoder.decode(value, { stream: true });
|
| 125 |
+
thinkResponse += chunk;
|
| 126 |
if (selectedModel?.isThinker) {
|
| 127 |
+
const thinkMatch = thinkResponse.match(/<think>[\s\S]*/)?.[0];
|
| 128 |
+
if (thinkMatch && !thinkResponse?.includes("</think>")) {
|
| 129 |
if ((contentThink?.length ?? 0) < 3) {
|
| 130 |
setOpenThink(true);
|
| 131 |
}
|
|
|
|
| 135 |
}
|
| 136 |
}
|
| 137 |
|
| 138 |
+
contentResponse += chunk;
|
| 139 |
+
|
| 140 |
const newHtml = contentResponse.match(/<!DOCTYPE html>[\s\S]*/)?.[0];
|
| 141 |
if (newHtml) {
|
| 142 |
setIsThinking(false);
|