Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
Another Fix (#62)
Browse files Browse the repository at this point in the history
* fix: ChatGPTNextWeb#3016 disable sidebar transition on ios

* fix: ChatGPTNextWeb#3152 system prompt should be injected

---------

Co-authored-by: Yidadaa <yidadaa@qq.com>
  • Loading branch information
H0llyW00dzZ and Yidadaa authored Nov 7, 2023
1 parent 7dc61de commit 5c74792
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
13 changes: 11 additions & 2 deletions app/components/sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef, useCallback } from "react";
import { useEffect, useRef, useCallback, useMemo } from "react";

import styles from "./home.module.scss";

Expand Down Expand Up @@ -28,7 +28,7 @@ import {
} from "../constant";

import { Link, useNavigate } from "react-router-dom";
import { useMobileScreen } from "../utils";
import { isIOS, useMobileScreen } from "../utils";
import dynamic from "next/dynamic";
import { showConfirm, showToast } from "./ui-lib";

Expand Down Expand Up @@ -136,6 +136,11 @@ export function SideBar(props: { className?: string }) {
const { onDragStart, shouldNarrow } = useDragSideBar();
const navigate = useNavigate();
const config = useAppConfig();
const isMobileScreen = useMobileScreen();
const isIOSMobile = useMemo(
() => isIOS() && isMobileScreen,
[isMobileScreen],
);

useHotKey();

Expand All @@ -144,6 +149,10 @@ export function SideBar(props: { className?: string }) {
className={`${styles.sidebar} ${props.className} ${
shouldNarrow && styles["narrow-sidebar"]
}`}
style={{
// #3016 disable transition on ios mobile screen
transition: isMobileScreen && isIOSMobile ? "none" : undefined,
}}
>
<div className={styles["sidebar-header"]} data-tauri-drag-region>
<div className={styles["sidebar-title"]} data-tauri-drag-region>
Expand Down
9 changes: 8 additions & 1 deletion app/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,20 @@ export const OpenaiPath = {
export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang
export const DEFAULT_SYSTEM_TEMPLATE = `
You are ChatGPT, a large language model trained by OpenAI.
Knowledge cutoff: {{knowledgeCutoff}}
Knowledge cutoff: {{cutoff}}
Current model: {{model}}
Current time: {{time}}
`;

export const SUMMARIZE_MODEL = "gpt-3.5-turbo";

export const KnowledgeCutOffDate: Record<string, string> = {
default: "2021-09",
"gpt-3.5-turbo-1106": "2023-04",
"gpt-4-1106-preview": "2023-04",
"gpt-4-vision-preview": "2023-04",
};

export const DEFAULT_MODELS = [
{
name: "gpt-4",
Expand Down
42 changes: 21 additions & 21 deletions app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createEmptyMask, Mask } from "./mask";
import {
DEFAULT_INPUT_TEMPLATE,
DEFAULT_SYSTEM_TEMPLATE,
KnowledgeCutOffDate,
StoreKey,
SUMMARIZE_MODEL,
} from "../constant";
Expand Down Expand Up @@ -116,7 +117,11 @@ function countMessages(msgs: ChatMessage[]) {
}

function fillTemplateWith(input: string, modelConfig: ModelConfig) {
let cutoff =
KnowledgeCutOffDate[modelConfig.model] ?? KnowledgeCutOffDate.default;

const vars = {
cutoff,
model: modelConfig.model,
time: new Date().toLocaleString(),
lang: getLang(),
Expand Down Expand Up @@ -402,28 +407,23 @@ export const useChatStore = createPersistStore(

// system prompts, to get close to OpenAI Web ChatGPT
const shouldInjectSystemPrompts = modelConfig.enableInjectSystemPrompts;
let systemPrompts: ChatMessage[] = shouldInjectSystemPrompts ? [] : [];

const systemPrompts = shouldInjectSystemPrompts
? [
createMessage({
role: "system",
content: fillTemplateWith("", {
...modelConfig,
template: DEFAULT_SYSTEM_TEMPLATE,
}),
}),
]
: [];
if (shouldInjectSystemPrompts) {
const model = modelConfig.model;
let systemTemplate = DEFAULT_SYSTEM_TEMPLATE;

if (model === "gpt-4-1106-preview" || model === "gpt-4-vision-preview") {
systemTemplate = systemTemplate.replace("{{knowledgeCutoff}}", "2023-04");
} else {
systemTemplate = systemTemplate.replace("{{knowledgeCutoff}}", "2021-09");
}

const systemPrompt = createMessage({
role: "system",
content: fillTemplateWith("", {
...modelConfig,
template: systemTemplate,
}),
});
console.log("[Global System Prompt] ", systemPrompt.content);
systemPrompts.push(systemPrompt);
}
console.log(
"[Global System Prompt] ",
systemPrompts.at(0)?.content ?? "empty",
);
}

// long term memory
const shouldSendLongTermMemory =
Expand Down

0 comments on commit 5c74792

Please sign in to comment.