Skip to content

Commit

Permalink
use @ import alias
Browse files Browse the repository at this point in the history
  • Loading branch information
heimoshuiyu committed Oct 14, 2024
1 parent 1c3c94b commit f0f040c
Show file tree
Hide file tree
Showing 25 changed files with 208 additions and 179 deletions.
6 changes: 3 additions & 3 deletions src/addImage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from "preact/hooks";
import { ChatStore } from "./app";
import { MessageDetail } from "./chatgpt";
import { Tr } from "./translate";
import { ChatStore } from "@/app";
import { MessageDetail } from "@/chatgpt";
import { Tr } from "@/translate";

interface Props {
chatStore: ChatStore;
Expand Down
44 changes: 22 additions & 22 deletions src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { IDBPDatabase, openDB } from "idb";
import { useEffect, useState } from "preact/hooks";
import "./global.css";
import "@/global.css";

import { calculate_token_length, Logprobs, Message } from "./chatgpt";
import getDefaultParams from "./getDefaultParam";
import ChatBOX from "./chatbox";
import models, { defaultModel } from "./models";
import { Tr, langCodeContext, LANG_OPTIONS } from "./translate";
import { calculate_token_length, Logprobs, Message } from "@/chatgpt";
import getDefaultParams from "@/getDefaultParam";
import ChatBOX from "@/chatbox";
import models, { defaultModel } from "@/models";
import { Tr, langCodeContext, LANG_OPTIONS } from "@/translate";

import CHATGPT_API_WEB_VERSION from "./CHATGPT_API_WEB_VERSION";
import CHATGPT_API_WEB_VERSION from "@/CHATGPT_API_WEB_VERSION";

export interface ChatStoreMessage extends Message {
hide: boolean;
Expand Down Expand Up @@ -88,7 +88,7 @@ export const newChatStore = (
image_gen_api = "https://api.openai.com/v1/images/generations",
image_gen_key = "",
json_mode = false,
logprobs = false
logprobs = false,
): ChatStore => {
return {
chatgpt_api_web_version: CHATGPT_API_WEB_VERSION,
Expand All @@ -100,7 +100,7 @@ export const newChatStore = (
totalTokens: 0,
maxTokens: getDefaultParams(
"max",
models[getDefaultParams("model", model)]?.maxToken ?? 2048
models[getDefaultParams("model", model)]?.maxToken ?? 2048,
),
maxGenTokens: 2048,
maxGenTokens_enabled: false,
Expand Down Expand Up @@ -152,7 +152,7 @@ export function addTotalCost(cost: number) {

export function getTotalCost(): number {
let totalCost = parseFloat(
localStorage.getItem(STORAGE_NAME_TOTALCOST) ?? "0"
localStorage.getItem(STORAGE_NAME_TOTALCOST) ?? "0",
);
return totalCost;
}
Expand Down Expand Up @@ -190,7 +190,7 @@ export function BuildFiledForSearch(chatStore: ChatStore): string[] {
export function App() {
// init selected index
const [selectedChatIndex, setSelectedChatIndex] = useState(
parseInt(localStorage.getItem(STORAGE_NAME_SELECTED) ?? "1")
parseInt(localStorage.getItem(STORAGE_NAME_SELECTED) ?? "1"),
);
console.log("selectedChatIndex", selectedChatIndex);
useEffect(() => {
Expand All @@ -207,7 +207,7 @@ export function App() {

// copy from localStorage to indexedDB
const allChatStoreIndexes: number[] = JSON.parse(
localStorage.getItem(STORAGE_NAME_INDEXES) ?? "[]"
localStorage.getItem(STORAGE_NAME_INDEXES) ?? "[]",
);
let keyCount = 0;
for (const i of allChatStoreIndexes) {
Expand All @@ -221,15 +221,15 @@ export function App() {
setSelectedChatIndex(keyCount);
if (keyCount > 0) {
alert(
"v2.0.0 Update: Imported chat history from localStorage to indexedDB. 🎉"
"v2.0.0 Update: Imported chat history from localStorage to indexedDB. 🎉",
);
}
}

if (oldVersion < 11) {
if (oldVersion < 11 && oldVersion >= 1) {
alert(
"Start upgrading storage, just a sec... (Click OK to continue)"
"Start upgrading storage, just a sec... (Click OK to continue)",
);
}
if (
Expand All @@ -247,7 +247,7 @@ export function App() {
{
multiEntry: true,
unique: false,
}
},
);

// iter through all chatStore and update contents_for_index
Expand Down Expand Up @@ -294,7 +294,7 @@ export function App() {
const max = chatStore.maxTokens - chatStore.tokenMargin;
let sum = 0;
chatStore.postBeginIndex = chatStore.history.filter(
({ hide }) => !hide
({ hide }) => !hide,
).length;
for (const msg of chatStore.history
.filter(({ hide }) => !hide)
Expand All @@ -309,7 +309,7 @@ export function App() {

// manually estimate token
chatStore.totalTokens = calculate_token_length(
chatStore.systemMessageContent
chatStore.systemMessageContent,
);
for (const msg of chatStore.history
.filter(({ hide }) => !hide)
Expand All @@ -331,7 +331,7 @@ export function App() {

// all chat store indexes
const [allChatStoreIndexes, setAllChatStoreIndexes] = useState<IDBValidKey>(
[]
[],
);

const handleNewChatStoreWithOldOne = async (chatStore: ChatStore) => {
Expand All @@ -358,8 +358,8 @@ export function App() {
chatStore.image_gen_api,
chatStore.image_gen_key,
chatStore.json_mode,
false // logprobs default to false
)
false, // logprobs default to false
),
);
setSelectedChatIndex(newKey as number);
setAllChatStoreIndexes(await (await db).getAllKeys(STORAGE_NAME));
Expand Down Expand Up @@ -445,7 +445,7 @@ export function App() {
return;
console.log(
"remove item",
`${STORAGE_NAME}-${selectedChatIndex}`
`${STORAGE_NAME}-${selectedChatIndex}`,
);
(await db).delete(STORAGE_NAME, selectedChatIndex);
const newAllChatStoreIndexes = await (
Expand Down Expand Up @@ -473,7 +473,7 @@ export function App() {
onClick={async () => {
if (
!confirm(
"Are you sure you want to delete **ALL** chat history?"
"Are you sure you want to delete **ALL** chat history?",
)
)
return;
Expand Down
Loading

0 comments on commit f0f040c

Please sign in to comment.