🐛 fix: Fix ssr

This commit is contained in:
canisminor1990
2023-07-17 13:04:36 +08:00
parent a834e76104
commit 9a13ec0a78
15 changed files with 39 additions and 444 deletions

View File

@@ -6,7 +6,7 @@ module.exports = defineConfig({
entry: 'public/locales/zh_CN',
entryLocale: 'zh_CN',
output: 'public/locales',
outputLocales: ['zh_HK', 'en_US', 'ja_JP', 'ko_KR'],
outputLocales: ['en_US'],
splitToken: 2500,
temperature: 0,
modelName: 'gpt-3.5-turbo',

View File

@@ -2,7 +2,7 @@ const i18n = require('./.i18nrc');
/** @type {import('next-i18next').UserConfig} */
module.exports = {
debug: process.env.NODE_ENV === 'development',
//debug: process.env.NODE_ENV === 'development',
fallbackLng: {
default: ['zh_CN'],
zh_TW: ['zh_CN'],
@@ -11,9 +11,5 @@ module.exports = {
defaultLocale: i18n.entryLocale,
locales: [i18n.entryLocale, ...i18n.outputLocales],
},
localePath:
typeof window === 'undefined' ? require('node:path').resolve('./', i18n.output) : '/locales',
react: { useSuspense: false },
reloadOnPrerender: process.env.NODE_ENV === 'development',
strictMode: true,
};

View File

@@ -1,40 +0,0 @@
{
"advanceSettings": "高度な設定",
"agentAvatar": "エージェントのアバター",
"agentDescription": "説明",
"agentDescriptionPlaceholder": "説明を入力してください",
"agentModel": "モデル",
"agentName": "名前",
"agentNamePlaceholder": "名前を入力してください",
"agentProfile": "エージェントプロファイル",
"agentPrompt": "プロンプト",
"agentPromptPlaceholder": "AIのプロンプトを入力してください",
"agentTag": "タグ",
"agentTagPlaceholder": "タグを入力してください",
"archive": "アーカイブ",
"autoGenerate": "自動生成",
"cancel": "キャンセル",
"close": "閉じる",
"confirmRemoveSessionItemAlert": "このエージェントを削除します。削除後は元に戻すことはできません。操作を確認してください",
"defaultAgent": "デフォルトエージェント",
"edit": "編集",
"editAgentProfile": "エージェントのプロフィールを編集する",
"export": "エクスポート",
"gpt-3.5-turbo": "GPT 3.5 Turbo",
"gpt-3.5-turbo-16k": "GPT 3.5 Turbo (16K)",
"gpt-4": "GPT 4",
"gpt-4-32k": "GPT 4 (32K)",
"modelConfig": "モデルの設定",
"modelTemperature": "モデルの温度",
"newAgent": "新しいエージェント",
"noDescription": "説明はありません",
"ok": "OK",
"profile": "プロフィール",
"reset": "リセット",
"searchAgentPlaceholder": "エージェントと会話を検索...",
"sessionSetting": "セッション設定",
"setting": "設定",
"share": "共有する",
"updateAgent": "エージェント情報を更新する",
"updatePrompt": "プロンプトを更新する"
}

View File

@@ -1,97 +0,0 @@
{
"danger": {
"reset": {
"title": "すべての設定をリセットする",
"desc": "すべての設定をデフォルト値にリセットする",
"action": "すぐにリセットする",
"confirm": "すべての設定をリセットしますか?",
"currentVersion": "現在のバージョン"
},
"clear": {
"title": "すべてのデータをクリアする",
"desc": "すべてのチャットと設定データをクリアする",
"action": "すぐにクリアする",
"confirm": "すべてのチャットと設定データをクリアしますか?"
}
},
"header": "設定",
"settingChat": {
"title": "チャット設定",
"inputTemplate": {
"title": "ユーザー入力のプリプロセス",
"desc": "最新のメッセージがこのテンプレートに入力されます"
},
"compressThreshold": {
"title": "履歴メッセージの圧縮閾値",
"desc": "非圧縮の履歴メッセージがこの値を超えると、圧縮されます"
},
"historyCount": {
"title": "履歴メッセージの数",
"desc": "リクエストごとに送信される履歴メッセージの数"
},
"maxTokens": {
"title": "1回の応答制限 (max_tokens)",
"desc": "1回の対話で使用される最大トークン数"
},
"sendKey": {
"title": "送信キー"
}
},
"settingModel": {
"title": "モデル設定",
"model": {
"title": "モデル"
},
"temperature": {
"title": "ランダム性 (temperature)",
"desc": "値が大きいほど、応答がランダムになります"
},
"topP": {
"title": "トップPサンプリング (top_p)",
"desc": "ランダム性に似ていますが、ランダム性とは別に変更しないでください"
},
"presencePenalty": {
"title": "トピックの新鮮さ (presence_penalty)",
"desc": "値が大きいほど、新しいトピックに拡張される可能性が高くなります"
},
"frequencyPenalty": {
"title": "頻度ペナルティ (frequency_penalty)",
"desc": "値が大きいほど、重複する単語を減らす可能性が高くなります"
}
},
"settingOpenAI": {
"title": "OpenAI設定",
"token": {
"title": "APIキー",
"desc": "独自のキーを使用すると、パスワード制限を回避できます",
"placeholder": "OpenAI APIキー"
},
"endpoint": {
"title": "エンドポイントアドレス",
"desc": "デフォルトのアドレス以外に、http(s)://を含める必要があります"
}
},
"settingSystem": {
"title": "システム設定",
"accessCode": {
"title": "アクセスコード",
"desc": "管理者によって暗号化アクセスが有効にされています",
"placeholder": "アクセスコードを入力してください"
}
},
"settingTheme": {
"title": "テーマ設定",
"avatar": {
"title": "アバター",
"desc": "URL / Base64 / 絵文字をサポートしています"
},
"fontSize": {
"title": "フォントサイズ",
"desc": "チャットコンテンツのフォントサイズ"
},
"lang": {
"name": "言語設定",
"all": "すべての言語"
}
}
}

View File

@@ -1,40 +0,0 @@
{
"advanceSettings": "고급 설정",
"agentAvatar": "아바타",
"agentDescription": "설명",
"agentDescriptionPlaceholder": "설명을 입력하세요",
"agentModel": "모델",
"agentName": "이름",
"agentNamePlaceholder": "이름을 입력하세요",
"agentProfile": "도우미 프로필",
"agentPrompt": "프롬프트",
"agentPromptPlaceholder": "AI 프롬프트를 입력하세요",
"agentTag": "태그",
"agentTagPlaceholder": "태그를 입력하세요",
"archive": "보관",
"autoGenerate": "자동 생성",
"cancel": "취소",
"close": "닫기",
"confirmRemoveSessionItemAlert": "이 도우미를 삭제하려고 합니다. 삭제 후에는 복구할 수 없으므로 작업을 확인하십시오.",
"defaultAgent": "기본 도우미",
"edit": "편집",
"editAgentProfile": "에이전트 프로필 편집",
"export": "내보내기",
"gpt-3.5-turbo": "GPT 3.5",
"gpt-3.5-turbo-16k": "GPT 3.5 (16K)",
"gpt-4": "GPT 4",
"gpt-4-32k": "GPT 4 (32K)",
"modelConfig": "모델 설정",
"modelTemperature": "모델 온도",
"newAgent": "새 도우미",
"noDescription": "설명 없음",
"ok": "확인",
"profile": "프로필",
"reset": "재설정",
"searchAgentPlaceholder": "도우미 및 대화 검색...",
"sessionSetting": "세션 설정",
"setting": "설정",
"share": "공유",
"updateAgent": "에이전트 업데이트",
"updatePrompt": "프롬프트 업데이트"
}

View File

@@ -1,97 +0,0 @@
{
"danger": {
"reset": {
"title": "모든 설정 초기화",
"desc": "모든 설정을 기본값으로 초기화합니다.",
"action": "지금 초기화",
"confirm": "모든 설정을 초기화하시겠습니까?",
"currentVersion": "현재 버전"
},
"clear": {
"title": "모든 데이터 지우기",
"desc": "모든 채팅 및 설정 데이터를 지웁니다.",
"action": "지금 지우기",
"confirm": "모든 채팅 및 설정 데이터를 지우시겠습니까?"
}
},
"header": "설정",
"settingChat": {
"title": "채팅 설정",
"inputTemplate": {
"title": "사용자 입력 전처리",
"desc": "최신 메시지가 이 템플릿에 채워집니다."
},
"compressThreshold": {
"title": "히스토리 메시지 길이 압축 임계값",
"desc": "압축되지 않은 히스토리 메시지가이 값보다 큰 경우 압축됩니다."
},
"historyCount": {
"title": "포함된 히스토리 메시지 수",
"desc": "요청당 포함되는 히스토리 메시지 수"
},
"maxTokens": {
"title": "단일 응답 제한 (max_tokens)",
"desc": "한 번의 상호 작용에 사용되는 최대 토큰 수"
},
"sendKey": {
"title": "전송 키"
}
},
"settingModel": {
"title": "모델 설정",
"model": {
"title": "모델"
},
"temperature": {
"title": "랜덤성 (temperature)",
"desc": "값이 클수록 응답이 더 랜덤해집니다."
},
"topP": {
"title": "상위 P 샘플링 (top_p)",
"desc": "랜덤성과 유사하지만 랜덤성과 함께 변경하지 마십시오."
},
"presencePenalty": {
"title": "주제 신선도 (presence_penalty)",
"desc": "값이 클수록 새로운 주제로 확장될 가능성이 높아집니다."
},
"frequencyPenalty": {
"title": "빈도 벌칙 (frequency_penalty)",
"desc": "값이 클수록 반복 단어를 줄일 가능성이 높아집니다."
}
},
"settingOpenAI": {
"title": "OpenAI 설정",
"token": {
"title": "API 키",
"desc": "자체 키를 사용하여 암호 제한을 우회할 수 있습니다.",
"placeholder": "OpenAI API 키"
},
"endpoint": {
"title": "엔드포인트 주소",
"desc": "기본 주소 외에도 반드시 http(s)://를 포함해야 합니다."
}
},
"settingSystem": {
"title": "시스템 설정",
"accessCode": {
"title": "액세스 코드",
"desc": "관리자가 암호 액세스를 활성화했습니다.",
"placeholder": "액세스 코드를 입력하세요."
}
},
"settingTheme": {
"title": "테마 설정",
"avatar": {
"title": "아바타",
"desc": "URL / Base64 / 이모지 표현을 지원합니다."
},
"fontSize": {
"title": "글꼴 크기",
"desc": "채팅 내용의 글꼴 크기"
},
"lang": {
"name": "언어 설정",
"all": "모든 언어"
}
}
}

View File

@@ -1,40 +0,0 @@
{
"advanceSettings": "高級設置",
"agentAvatar": "頭像",
"agentDescription": "描述",
"agentDescriptionPlaceholder": "請輸入描述",
"agentModel": "模型",
"agentName": "名稱",
"agentNamePlaceholder": "請輸入名稱",
"agentProfile": "助手資訊",
"agentPrompt": "提示詞",
"agentPromptPlaceholder": "請輸入 AI 提示詞",
"agentTag": "標籤",
"agentTagPlaceholder": "請輸入標籤",
"archive": "歸檔",
"autoGenerate": "自動生成",
"cancel": "取消",
"close": "關閉",
"confirmRemoveSessionItemAlert": "即將刪除該助手,刪除後將無法找回,請確認你的操作",
"defaultAgent": "默認助手",
"edit": "編輯",
"editAgentProfile": "編輯助手資訊",
"export": "導出",
"gpt-3.5-turbo": "GPT 3.5",
"gpt-3.5-turbo-16k": "GPT 3.5 (16K)",
"gpt-4": "GPT 4",
"gpt-4-32k": "GPT 4 (32K)",
"modelConfig": "模型配置",
"modelTemperature": "發散度",
"newAgent": "新建助手",
"noDescription": "暫無描述",
"ok": "確定",
"profile": "身份卡",
"reset": "重置",
"searchAgentPlaceholder": "搜索助手和對話...",
"sessionSetting": "會話設置",
"setting": "設置",
"share": "分享",
"updateAgent": "更新助理資訊",
"updatePrompt": "更新提示詞"
}

View File

@@ -1,97 +0,0 @@
{
"danger": {
"reset": {
"title": "重置所有設置",
"desc": "重置所有設置項回默認值",
"action": "立即重置",
"confirm": "確認重置所有設置?",
"currentVersion": "當前版本"
},
"clear": {
"title": "清除所有數據",
"desc": "清除所有聊天、設置數據",
"action": "立即清除",
"confirm": "確認清除所有聊天、設置數據?"
}
},
"header": "設置",
"settingChat": {
"title": "聊天設置",
"inputTemplate": {
"title": "用戶輸入預處理",
"desc": "用戶最新的一條消息會填充到此模板"
},
"compressThreshold": {
"title": "歷史消息長度壓縮閾值",
"desc": "當未壓縮的歷史消息超過該值時,將進行壓縮"
},
"historyCount": {
"title": "附帶歷史消息數",
"desc": "每次請求攜帶的歷史消息數"
},
"maxTokens": {
"title": "單次回復限制 (max_tokens)",
"desc": "單次交互所用的最大 Token 數"
},
"sendKey": {
"title": "發送鍵"
}
},
"settingModel": {
"title": "模型設置",
"model": {
"title": "模型"
},
"temperature": {
"title": "隨機性 (temperature)",
"desc": "值越大,回復越隨機"
},
"topP": {
"title": "核採樣 (top_p)",
"desc": "與隨機性類似,但不要和隨機性一起更改"
},
"presencePenalty": {
"title": "話題新鮮度 (presence_penalty)",
"desc": "值越大,越有可能擴展到新話題"
},
"frequencyPenalty": {
"title": "頻率懲罰度 (frequency_penalty)",
"desc": "值越大,越有可能降低重複字詞"
}
},
"settingOpenAI": {
"title": "OpenAI 設置",
"token": {
"title": "API Key",
"desc": "使用自己的 Key 可繞過密碼訪問限制",
"placeholder": "OpenAI API Key"
},
"endpoint": {
"title": "接口地址",
"desc": "除默認地址外,必須包含 http(s)://"
}
},
"settingSystem": {
"title": "系統設置",
"accessCode": {
"title": "訪問密碼",
"desc": "管理員已開啟加密訪問",
"placeholder": "請輸入訪問密碼"
}
},
"settingTheme": {
"title": "主題設置",
"avatar": {
"title": "頭像",
"desc": "支持 URL / Base64 / Emoji 表情符號"
},
"fontSize": {
"title": "字體大小",
"desc": "聊天內容的字體大小"
},
"lang": {
"name": "語言設置",
"all": "所有語言"
}
}
}

View File

@@ -1,10 +1,11 @@
import isEqual from 'fast-deep-equal';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { useTranslation } from 'next-i18next';
import Head from 'next/head';
import { memo } from 'react';
import { Flexbox } from 'react-layout-kit';
import { sessionSelectors, useSessionStore } from '@/store/session';
import { makeI18nProps } from '@/utils/makeI18nProps';
import Layout from '../layout';
import Config from './Config';
@@ -12,6 +13,7 @@ import Conversation from './Conversation';
import Header from './Header';
const Chat = memo(() => {
useTranslation('common');
const [title] = useSessionStore((s) => {
const context = sessionSelectors.currentSession(s);
return [context?.meta.title];
@@ -38,13 +40,4 @@ const Chat = memo(() => {
});
export default Chat;
// export const getStaticPaths = async () => {
// return {
// fallback: 'blocking',
// paths: [],
// };
// };
export const getServerSideProps = async (context: any) => ({
props: await serverSideTranslations(context.locale),
});
export const getServerSideProps = makeI18nProps(['common']);

View File

@@ -1,7 +1,5 @@
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { makeI18nProps } from '@/utils/makeI18nProps';
export { default } from './[id]/index.page';
export const getStaticProps = async (context: any) => ({
props: await serverSideTranslations(context.locale),
});
export const getStaticProps = makeI18nProps(['common']);

View File

@@ -1,6 +1,4 @@
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { makeI18nProps } from '@/utils/makeI18nProps';
export { default } from './chat/index.page';
export const getStaticProps = async (context: any) => ({
props: await serverSideTranslations(context.locale, ['common', 'setting']),
});
export const getStaticProps = makeI18nProps(['common']);

View File

@@ -1,10 +1,10 @@
import { useTranslation } from 'next-i18next';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import Head from 'next/head';
import { memo } from 'react';
import { Flexbox } from 'react-layout-kit';
import { Sessions } from '@/pages/chat/SessionList';
import { makeI18nProps } from '@/utils/makeI18nProps';
import Sidebar from '../Sidebar';
import Header from './Header';
@@ -31,8 +31,6 @@ const SettingLayout = memo(() => {
);
});
export const getStaticProps = async (context: any) => ({
props: await serverSideTranslations(context.locale, ['common', 'setting']),
});
export const getStaticProps = makeI18nProps(['common', 'setting']);
export default SettingLayout;

View File

@@ -5,8 +5,10 @@ import { SessionStore, createStore } from './store';
type SessionPersist = Pick<SessionStore, 'sessions'>;
export const LOBE_CHAT = 'LOBE_CHAT';
const persistOptions: PersistOptions<SessionStore, SessionPersist> = {
name: 'LOBE_CHAT',
name: LOBE_CHAT,
partialize: (s) => ({
sessions: s.sessions,
@@ -21,7 +23,7 @@ const persistOptions: PersistOptions<SessionStore, SessionPersist> = {
export const useSessionStore = create<SessionStore>()(
persist(
devtools(createStore, {
name: 'LOBE_CHATS',
name: LOBE_CHAT,
}),
persistOptions,
),

View File

@@ -3,15 +3,17 @@ import { type PersistOptions, devtools, persist } from 'zustand/middleware';
import { type SettingsStore, createStore } from './store';
export const LOBE_SETTINGS = 'LOBE_SETTINGS';
const persistOptions: PersistOptions<SettingsStore> = {
name: 'LOBE_SETTINGS',
name: LOBE_SETTINGS,
skipHydration: true,
};
export const useSettings = create<SettingsStore>()(
persist(
devtools(createStore, {
name: 'LOBE_SETTINGS',
name: LOBE_SETTINGS,
}),
persistOptions,
),

View File

@@ -0,0 +1,19 @@
import type { GetServerSideProps, GetStaticProps } from 'next';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import i18nextConfig from '@/../next-i18next.config';
import { NS } from '@/types/resources';
export const getI18nProps = async (ctx: any, ns: NS[] = ['common']) => {
const locale = ctx?.params?.locale || ctx?.locale || i18nextConfig.i18n.defaultLocale;
let props = {
...(await serverSideTranslations(locale, ns)),
};
return props;
};
export const makeI18nProps =
(ns: NS[] = []): GetStaticProps | GetServerSideProps =>
async (ctx: any) => ({
props: await getI18nProps(ctx, ns),
});