Skip to content

Commit 133a757

Browse files
committed
2 parents bf27b11 + df62736 commit 133a757

File tree

6 files changed

+45
-17
lines changed

6 files changed

+45
-17
lines changed

app/client/platforms/openai.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export class ChatGPTApi implements LLMApi {
160160
let requestPayload: RequestPayload | DalleRequestPayload;
161161

162162
const isDalle3 = _isDalle3(options.config.model);
163+
const isO1 = options.config.model.startsWith("o1");
163164
if (isDalle3) {
164165
const prompt = getMessageTextContent(
165166
options.messages.slice(-1)?.pop() as any,
@@ -181,30 +182,32 @@ export class ChatGPTApi implements LLMApi {
181182
const content = visionModel
182183
? await preProcessImageContent(v.content)
183184
: getMessageTextContent(v);
184-
messages.push({ role: v.role, content });
185+
if (!(isO1 && v.role === "system"))
186+
messages.push({ role: v.role, content });
185187
}
186188

189+
// O1 not support image, tools (plugin in ChatGPTNextWeb) and system, stream, logprobs, temperature, top_p, n, presence_penalty, frequency_penalty yet.
187190
requestPayload = {
188191
messages,
189-
stream: options.config.stream,
192+
stream: !isO1 ? options.config.stream : false,
190193
model: modelConfig.model,
191-
temperature: modelConfig.temperature,
192-
presence_penalty: modelConfig.presence_penalty,
193-
frequency_penalty: modelConfig.frequency_penalty,
194-
top_p: modelConfig.top_p,
194+
temperature: !isO1 ? modelConfig.temperature : 1,
195+
presence_penalty: !isO1 ? modelConfig.presence_penalty : 0,
196+
frequency_penalty: !isO1 ? modelConfig.frequency_penalty : 0,
197+
top_p: !isO1 ? modelConfig.top_p : 1,
195198
// max_tokens: Math.max(modelConfig.max_tokens, 1024),
196199
// Please do not ask me why not send max_tokens, no reason, this param is just shit, I dont want to explain anymore.
197200
};
198201

199202
// add max_tokens to vision model
200-
if (visionModel && modelConfig.model.includes("preview")) {
203+
if (visionModel) {
201204
requestPayload["max_tokens"] = Math.max(modelConfig.max_tokens, 4000);
202205
}
203206
}
204207

205208
console.log("[Request] openai payload: ", requestPayload);
206209

207-
const shouldStream = !isDalle3 && !!options.config.stream;
210+
const shouldStream = !isDalle3 && !!options.config.stream && !isO1;
208211
const controller = new AbortController();
209212
options.onController?.(controller);
210213

@@ -313,7 +316,7 @@ export class ChatGPTApi implements LLMApi {
313316
// make a fetch request
314317
const requestTimeoutId = setTimeout(
315318
() => controller.abort(),
316-
isDalle3 ? REQUEST_TIMEOUT_MS * 2 : REQUEST_TIMEOUT_MS, // dalle3 using b64_json is slow.
319+
isDalle3 || isO1 ? REQUEST_TIMEOUT_MS * 2 : REQUEST_TIMEOUT_MS, // dalle3 using b64_json is slow.
317320
);
318321

319322
const res = await fetch(chatPath, chatPayload);

app/components/artifacts.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const HTMLPreview = forwardRef<HTMLPreviewHander, HTMLPreviewProps>(
8080
}, [props.autoHeight, props.height, iframeHeight]);
8181

8282
const srcDoc = useMemo(() => {
83-
const script = `<script>new ResizeObserver((entries) => parent.postMessage({id: '${frameId}', height: entries[0].target.clientHeight}, '*')).observe(document.body)</script>`;
83+
const script = `<script>window.addEventListener("DOMContentLoaded", () => new ResizeObserver((entries) => parent.postMessage({id: '${frameId}', height: entries[0].target.clientHeight}, '*')).observe(document.body))</script>`;
8484
if (props.code.includes("<!DOCTYPE html>")) {
8585
props.code.replace("<!DOCTYPE html>", "<!DOCTYPE html>" + script);
8686
}

app/components/chat.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ export function ChatActions(props: {
507507
const currentStyle =
508508
chatStore.currentSession().mask.modelConfig?.style ?? "vivid";
509509

510+
const isMobileScreen = useMobileScreen();
511+
510512
useEffect(() => {
511513
const show = isVisionModel(currentModel);
512514
setShowUploadImage(show);
@@ -761,11 +763,13 @@ export function ChatActions(props: {
761763
/>
762764
)}
763765

764-
<ChatAction
765-
onClick={() => props.setShowShortcutKeyModal(true)}
766-
text={Locale.Chat.ShortcutKey.Title}
767-
icon={<ShortcutkeyIcon />}
768-
/>
766+
{!isMobileScreen && (
767+
<ChatAction
768+
onClick={() => props.setShowShortcutKeyModal(true)}
769+
text={Locale.Chat.ShortcutKey.Title}
770+
icon={<ShortcutkeyIcon />}
771+
/>
772+
)}
769773
</div>
770774
);
771775
}

app/components/markdown.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,26 @@ function escapeBrackets(text: string) {
237237
);
238238
}
239239

240+
function tryWrapHtmlCode(text: string) {
241+
// try add wrap html code (fixed: html codeblock include 2 newline)
242+
return text
243+
.replace(
244+
/([`]*?)(\w*?)([\n\r]*?)(<!DOCTYPE html>)/g,
245+
(match, quoteStart, lang, newLine, doctype) => {
246+
return !quoteStart ? "\n```html\n" + doctype : match;
247+
},
248+
)
249+
.replace(
250+
/(<\/body>)([\r\n\s]*?)(<\/html>)([\n\r]*?)([`]*?)([\n\r]*?)/g,
251+
(match, bodyEnd, space, htmlEnd, newLine, quoteEnd) => {
252+
return !quoteEnd ? bodyEnd + space + htmlEnd + "\n```\n" : match;
253+
},
254+
);
255+
}
256+
240257
function _MarkDownContent(props: { content: string }) {
241258
const escapedContent = useMemo(() => {
242-
return escapeBrackets(escapeDollarNumber(props.content));
259+
return tryWrapHtmlCode(escapeBrackets(escapeDollarNumber(props.content)));
243260
}, [props.content]);
244261

245262
return (

app/constant.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ export const KnowledgeCutOffDate: Record<string, string> = {
250250
"gpt-4o-mini": "2023-10",
251251
"gpt-4o-mini-2024-07-18": "2023-10",
252252
"gpt-4-vision-preview": "2023-04",
253+
"o1-mini": "2023-10",
254+
"o1-preview": "2023-10",
253255
// After improvements,
254256
// it's now easier to add "KnowledgeCutOffDate" instead of stupid hardcoding it, as was done previously.
255257
"gemini-pro": "2023-12",
@@ -276,6 +278,8 @@ const openaiModels = [
276278
"gpt-4-turbo-2024-04-09",
277279
"gpt-4-1106-preview",
278280
"dall-e-3",
281+
"o1-mini",
282+
"o1-preview"
279283
];
280284

281285
const googleModels = [

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"package": {
1111
"productName": "NextChat",
12-
"version": "2.15.1"
12+
"version": "2.15.2"
1313
},
1414
"tauri": {
1515
"allowlist": {

0 commit comments

Comments
 (0)