support import chat store
This commit is contained in:
3
src/CHATGPT_API_WEB_VERSION.ts
Normal file
3
src/CHATGPT_API_WEB_VERSION.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
const CHATGPT_API_WEB_VERSION = "v1.2.2";
|
||||||
|
|
||||||
|
export default CHATGPT_API_WEB_VERSION;
|
||||||
@@ -6,7 +6,10 @@ import getDefaultParams from "./getDefaultParam";
|
|||||||
import ChatBOX from "./chatbox";
|
import ChatBOX from "./chatbox";
|
||||||
import { options } from "./settings";
|
import { options } from "./settings";
|
||||||
|
|
||||||
|
import CHATGPT_API_WEB_VERSION from './CHATGPT_API_WEB_VERSION'
|
||||||
|
|
||||||
export interface ChatStore {
|
export interface ChatStore {
|
||||||
|
chatgpt_api_web_version: string;
|
||||||
systemMessageContent: string;
|
systemMessageContent: string;
|
||||||
history: Message[];
|
history: Message[];
|
||||||
postBeginIndex: number;
|
postBeginIndex: number;
|
||||||
@@ -29,6 +32,7 @@ const newChatStore = (
|
|||||||
model = "gpt-3.5-turbo"
|
model = "gpt-3.5-turbo"
|
||||||
): ChatStore => {
|
): ChatStore => {
|
||||||
return {
|
return {
|
||||||
|
chatgpt_api_web_version: CHATGPT_API_WEB_VERSION,
|
||||||
systemMessageContent: getDefaultParams("sys", systemMessageContent),
|
systemMessageContent: getDefaultParams("sys", systemMessageContent),
|
||||||
history: [],
|
history: [],
|
||||||
postBeginIndex: 0,
|
postBeginIndex: 0,
|
||||||
@@ -81,6 +85,8 @@ export function App() {
|
|||||||
// handle read from old version chatstore
|
// handle read from old version chatstore
|
||||||
if (ret.model === undefined) ret.model = "gpt-3.5-turbo";
|
if (ret.model === undefined) ret.model = "gpt-3.5-turbo";
|
||||||
if (ret.responseModelName === undefined) ret.responseModelName = "";
|
if (ret.responseModelName === undefined) ret.responseModelName = "";
|
||||||
|
if (ret.chatgpt_api_web_version === undefined)
|
||||||
|
ret.chatgpt_api_web_version = CHATGPT_API_WEB_VERSION;
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { createRef } from "preact";
|
||||||
import { StateUpdater } from "preact/hooks";
|
import { StateUpdater } from "preact/hooks";
|
||||||
import { ChatStore } from "./app";
|
import { ChatStore } from "./app";
|
||||||
|
|
||||||
@@ -141,6 +142,8 @@ export default (props: {
|
|||||||
}&model=${props.chatStore.model}&sys=${encodeURIComponent(
|
}&model=${props.chatStore.model}&sys=${encodeURIComponent(
|
||||||
props.chatStore.systemMessageContent
|
props.chatStore.systemMessageContent
|
||||||
)}`;
|
)}`;
|
||||||
|
|
||||||
|
const importFileRef = createRef();
|
||||||
return (
|
return (
|
||||||
<div className="left-0 top-0 overflow-scroll flex justify-center absolute w-screen h-full bg-black bg-opacity-50 z-10">
|
<div className="left-0 top-0 overflow-scroll flex justify-center absolute w-screen h-full bg-black bg-opacity-50 z-10">
|
||||||
<div className="m-2 p-2 bg-white rounded-lg h-fit">
|
<div className="m-2 p-2 bg-white rounded-lg h-fit">
|
||||||
@@ -225,12 +228,46 @@ export default (props: {
|
|||||||
"This will OVERWRITE the current chat history! Continue?"
|
"This will OVERWRITE the current chat history! Continue?"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
alert("Error: This function is currently unimplemented :)");
|
|
||||||
return;
|
return;
|
||||||
|
console.log("importFileRef", importFileRef);
|
||||||
|
importFileRef.current.click();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Import
|
Import
|
||||||
</button>
|
</button>
|
||||||
|
<input
|
||||||
|
className="hidden"
|
||||||
|
ref={importFileRef}
|
||||||
|
type="file"
|
||||||
|
onChange={() => {
|
||||||
|
const file = importFileRef.current.files[0];
|
||||||
|
console.log("file to import", file);
|
||||||
|
if (!file || file.type !== "application/json") {
|
||||||
|
alert("Please select a json file");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = () => {
|
||||||
|
console.log("import content", reader.result);
|
||||||
|
if (!reader) {
|
||||||
|
alert("Empty file");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const newChatStore: ChatStore = JSON.parse(
|
||||||
|
reader.result as string
|
||||||
|
);
|
||||||
|
if (!newChatStore.chatgpt_api_web_version) {
|
||||||
|
throw "This is not an exported chatgpt-api-web chatstore file. The key 'chatgpt_api_web_version' is missing!";
|
||||||
|
}
|
||||||
|
props.setChatStore({ ...newChatStore });
|
||||||
|
} catch (e) {
|
||||||
|
alert(`Import error on parsing json: ${e}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
reader.readAsText(file);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
|
|||||||
Reference in New Issue
Block a user