forked from XiaoMo/ChatGPT-Next-Web
Merge pull request #3163 from Yidadaa/bugfix-1107
This commit is contained in:
commit
3407b57a51
@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useRef, useCallback } from "react";
|
import { useEffect, useRef, useCallback, useMemo } from "react";
|
||||||
|
|
||||||
import styles from "./home.module.scss";
|
import styles from "./home.module.scss";
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ import {
|
|||||||
} from "../constant";
|
} from "../constant";
|
||||||
|
|
||||||
import { Link, useNavigate } from "react-router-dom";
|
import { Link, useNavigate } from "react-router-dom";
|
||||||
import { useMobileScreen } from "../utils";
|
import { isIOS, useMobileScreen } from "../utils";
|
||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
import { showConfirm, showToast } from "./ui-lib";
|
import { showConfirm, showToast } from "./ui-lib";
|
||||||
|
|
||||||
@ -134,6 +134,11 @@ export function SideBar(props: { className?: string }) {
|
|||||||
const { onDragStart, shouldNarrow } = useDragSideBar();
|
const { onDragStart, shouldNarrow } = useDragSideBar();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const config = useAppConfig();
|
const config = useAppConfig();
|
||||||
|
const isMobileScreen = useMobileScreen();
|
||||||
|
const isIOSMobile = useMemo(
|
||||||
|
() => isIOS() && isMobileScreen,
|
||||||
|
[isMobileScreen],
|
||||||
|
);
|
||||||
|
|
||||||
useHotKey();
|
useHotKey();
|
||||||
|
|
||||||
@ -142,6 +147,10 @@ export function SideBar(props: { className?: string }) {
|
|||||||
className={`${styles.sidebar} ${props.className} ${
|
className={`${styles.sidebar} ${props.className} ${
|
||||||
shouldNarrow && styles["narrow-sidebar"]
|
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-header"]} data-tauri-drag-region>
|
||||||
<div className={styles["sidebar-title"]} data-tauri-drag-region>
|
<div className={styles["sidebar-title"]} data-tauri-drag-region>
|
||||||
|
@ -69,13 +69,20 @@ export const OpenaiPath = {
|
|||||||
export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang
|
export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang
|
||||||
export const DEFAULT_SYSTEM_TEMPLATE = `
|
export const DEFAULT_SYSTEM_TEMPLATE = `
|
||||||
You are ChatGPT, a large language model trained by OpenAI.
|
You are ChatGPT, a large language model trained by OpenAI.
|
||||||
Knowledge cutoff: {{knowledgeCutoff}}
|
Knowledge cutoff: {{cutoff}}
|
||||||
Current model: {{model}}
|
Current model: {{model}}
|
||||||
Current time: {{time}}
|
Current time: {{time}}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const SUMMARIZE_MODEL = "gpt-3.5-turbo";
|
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 = [
|
export const DEFAULT_MODELS = [
|
||||||
{
|
{
|
||||||
name: "gpt-4",
|
name: "gpt-4",
|
||||||
|
@ -7,6 +7,7 @@ import { createEmptyMask, Mask } from "./mask";
|
|||||||
import {
|
import {
|
||||||
DEFAULT_INPUT_TEMPLATE,
|
DEFAULT_INPUT_TEMPLATE,
|
||||||
DEFAULT_SYSTEM_TEMPLATE,
|
DEFAULT_SYSTEM_TEMPLATE,
|
||||||
|
KnowledgeCutOffDate,
|
||||||
StoreKey,
|
StoreKey,
|
||||||
SUMMARIZE_MODEL,
|
SUMMARIZE_MODEL,
|
||||||
} from "../constant";
|
} from "../constant";
|
||||||
@ -116,7 +117,11 @@ function countMessages(msgs: ChatMessage[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fillTemplateWith(input: string, modelConfig: ModelConfig) {
|
function fillTemplateWith(input: string, modelConfig: ModelConfig) {
|
||||||
|
let cutoff =
|
||||||
|
KnowledgeCutOffDate[modelConfig.model] ?? KnowledgeCutOffDate.default;
|
||||||
|
|
||||||
const vars = {
|
const vars = {
|
||||||
|
cutoff,
|
||||||
model: modelConfig.model,
|
model: modelConfig.model,
|
||||||
time: new Date().toLocaleString(),
|
time: new Date().toLocaleString(),
|
||||||
lang: getLang(),
|
lang: getLang(),
|
||||||
@ -401,26 +406,22 @@ export const useChatStore = createPersistStore(
|
|||||||
|
|
||||||
// system prompts, to get close to OpenAI Web ChatGPT
|
// system prompts, to get close to OpenAI Web ChatGPT
|
||||||
const shouldInjectSystemPrompts = modelConfig.enableInjectSystemPrompts;
|
const shouldInjectSystemPrompts = modelConfig.enableInjectSystemPrompts;
|
||||||
let systemPrompts = shouldInjectSystemPrompts ? [] : [];
|
const systemPrompts = shouldInjectSystemPrompts
|
||||||
|
? [
|
||||||
|
createMessage({
|
||||||
|
role: "system",
|
||||||
|
content: fillTemplateWith("", {
|
||||||
|
...modelConfig,
|
||||||
|
template: DEFAULT_SYSTEM_TEMPLATE,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
: [];
|
||||||
if (shouldInjectSystemPrompts) {
|
if (shouldInjectSystemPrompts) {
|
||||||
const model = modelConfig.model;
|
console.log(
|
||||||
let systemTemplate = DEFAULT_SYSTEM_TEMPLATE;
|
"[Global System Prompt] ",
|
||||||
|
systemPrompts.at(0)?.content ?? "empty",
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// long term memory
|
// long term memory
|
||||||
|
Loading…
x
Reference in New Issue
Block a user