diff --git a/public/locales/da/api.json b/public/locales/da/api.json index eedcc43..1762f21 100644 --- a/public/locales/da/api.json +++ b/public/locales/da/api.json @@ -1,18 +1,15 @@ { "securityMessage": "Vi prioriterer sikkerheden af din API-nøgle og håndterer den med største omhu. Din nøgle opbevares udelukkende på din browser og deles aldrig med tredjeparts enheder. Den bruges udelukkende til det tilsigtede formål at få adgang til OpenAI API og ikke til nogen anden uautoriseret brug.", "apiEndpoint": { - "option": "Brug gratis", - "inputLabel": "API Endpoint", - "description": "Tak til <0>Ayaka for at levere det gratis API-endpoint: https://chatgpt-api.shn.hk/v1/", - "note": "Bemærk venligst, at tilgængeligheden af den gratis slutpunkt ikke er ubegrænset, da finansieringen er begrænset og vil blive udtømt. Brugere med deres egen API-nøgle kan fortsætte med at bruge Better ChatGPT uden afbrydelser." + "inputLabel": "API-endepunkt", + "description": "Når du vælger et uofficielt API-endepunkt, fungerer det som en proxy. En proxy fungerer ved at fungere som et mellemled mellem din enhed og destinationsserveren, i dette tilfælde OpenAI API. Ved at gøre dette, gør det det muligt for dig at få adgang til OpenAI API i regioner, hvor det ellers kan være begrænset.", + "warn": "Derudover, hvis du angiver et brugerdefineret API-endepunkt, der giver gratis adgang til OpenAI API, kan du bruge ChatGPT uden at skulle angive en API-nøgle ved blot at lade API-nøglefeltet være tomt. Det er dog afgørende at være forsigtig, når du bruger tredjeparts API-endepunkter, da utroværdige kan logge dine personlige oplysninger i samtalerne. Verificér altid pålideligheden af et API-endepunkt, før du bruger det for at beskytte dit privatliv og din sikkerhed." }, "apiKey": { - "option": "Brug din egen API-nøgle", - "howTo": "Få din personlige API-nøgle <0>her", + "howTo": "Få din personlige API-nøgle <0>her.", "inputLabel": "API-nøgle" }, - "customEndpoint": "Brug brugerdefineret API-endpoint", - "shareGPT": "Tjek <0>ShareGPT, et API-nøgle delingsværktøj, der driver https://sharegpt.churchless.tech/share/v1/chat", + "customEndpoint": "Brug brugerdefineret API-endepunkt", "advancedConfig": "Se avanceret API-konfiguration <0>her", "noApiKeyWarning": "Ingen API-nøgle angivet! Tjek venligst dine API-indstillinger." } diff --git a/public/locales/en/api.json b/public/locales/en/api.json index 30afe35..4bbf188 100644 --- a/public/locales/en/api.json +++ b/public/locales/en/api.json @@ -1,18 +1,15 @@ { "securityMessage": "We prioritise the security of your API key and handle it with utmost care. Your key is exclusively stored on your browser and never shared with any third-party entity. It is solely used for the intended purpose of accessing the OpenAI API and not for any other unauthorised use.", "apiEndpoint": { - "option": "Use for free", "inputLabel": "API Endpoint", - "description": "Thank you to <0>Ayaka for providing the free API endpoint: https://chatgpt-api.shn.hk/v1/", - "note": "Please note that the availability of the free endpoint is not indefinite, as its funding is limited and will eventually be depleted. Users with their own API key can continue using Better ChatGPT without any disruptions." + "description": "When you choose an unofficial API endpoint, it essentially functions as a proxy. A proxy works by acting as an intermediary between your device and the destination server, in this case, the OpenAI API. By doing so, it enables you to access the OpenAI API in regions where it might otherwise be restricted.", + "warn": "Additionally, if you provide a custom API endpoint that grants free access to the OpenAI API, you can use ChatGPT without the need to supply an API key by simply leaving the API key field blank. However, it's crucial to be cautious when using third-party API endpoints, as untrustworthy ones may log your personal information in the conversations. Always verify the reliability of an API endpoint before using it to protect your privacy and security." }, "apiKey": { - "option": "Use your own API key", - "howTo": "Get your personal API key <0>here", + "howTo": "Get your personal API key <0>here.", "inputLabel": "API Key" }, "customEndpoint": "Use custom API endpoint", - "shareGPT": "Checkout <0>ShareGPT, a API key sharing tool that powers https://sharegpt.churchless.tech/share/v1/chat", "advancedConfig": "View advanced API configuration <0>here", "noApiKeyWarning": "No API key supplied! Please check your API settings." } diff --git a/public/locales/es/api.json b/public/locales/es/api.json index 1092ac2..b1e9a60 100644 --- a/public/locales/es/api.json +++ b/public/locales/es/api.json @@ -1,18 +1,16 @@ { "securityMessage": "Prioritamos la seguridad de su clave API y la tratamos con sumo cuidado. Si utiliza su propia clave de API, ésta se almacena exclusivamente en su navegador y nunca se comparte con ninguna entidad de terceros. Se utiliza únicamente para el fin exclusivo de acceder a la API de OpenAI y no para ningún otro uso no autorizado.", "apiEndpoint": { - "option": "Uso gratuito", "inputLabel": "Punto final de acceso de la API", - "description": "Gracias a <0>Ayaka por proveer el punto final de acceso gratuito: https://chatgpt-api.shn.hk/v1/", - "note": "Tenga en cuenta que la disponibilidad del punto final gratuito no es indefinida, ya que su financiación es limitada y eventualmente se agotará. Los usuarios con su propia clave API pueden seguir utilizando Better ChatGPT sin interrupciones." + "description": "Cuando eliges un punto final de API no oficial, básicamente funciona como un proxy. Un proxy funciona actuando como intermediario entre tu dispositivo y el servidor de destino, en este caso, la API de OpenAI. Al hacerlo, te permite acceder a la API de OpenAI en regiones donde de otro modo podría estar restringida.", + "warn": "Además, si proporcionas un punto final de API personalizado que otorga acceso gratuito a la API de OpenAI, puedes usar ChatGPT sin la necesidad de proporcionar una clave de API simplemente dejando en blanco el campo de la clave de API. Sin embargo, es fundamental tener precaución al usar puntos finales de API de terceros, ya que los que no sean confiables pueden registrar tu información personal en las conversaciones. Siempre verifica la fiabilidad de un punto final de API antes de usarlo para proteger tu privacidad y seguridad." + }, "apiKey": { - "option": "Usa tu propia clave API", "howTo": "Obtén tu clave personal <0>aquí.", "inputLabel": "Clave API" }, "customEndpoint": "Usar un punto final de acceso personalizado", - "shareGPT": "Echa un vistazo a <0>ShareGPT, una herramienta que permite compartir claves API: https://sharegpt.churchless.tech/share/v1/chat", "advancedConfig": "Ver configuración avanzada de API <0>aquí", "noApiKeyWarning": "¡No se proporcionó clave de API! Por favor, revisa tus ajustes de API." } diff --git a/public/locales/ja/api.json b/public/locales/ja/api.json index 9ca0737..ccbbd7a 100644 --- a/public/locales/ja/api.json +++ b/public/locales/ja/api.json @@ -1,18 +1,15 @@ { "securityMessage": "APIキーのセキュリティを最優先し、細心の注意を払って取り扱っています。キーはお客様のブラウザにのみ保存され、第三者とは一切共有されません。OpenAI APIにアクセスする目的でのみ使用され、他の不正な目的で使用されることはありません。", "apiEndpoint": { - "option": "無料で利用する", "inputLabel": "APIエンドポイント", - "description": "<0>アヤカさんによって提供された無料のAPIエンドポイントに感謝します:https://chatgpt-api.shn.hk/v1/", - "note": "無料エンドポイントの利用可能期間は無期限ではないことにご注意ください。資金が限られているため、いずれ枯渇します。独自のAPIキーを持つユーザーは、BetterChatGPTを中断することなく引き続き利用できます。" + "description": "非公式のAPIエンドポイントを選択すると、プロキシとして機能します。プロキシは、あなたのデバイスと目的のサーバ(この場合はOpenAI API)の間に中継役として働くことによって、制限されている可能性のある地域でもOpenAI APIにアクセスできるようになります。", + "warn": "さらに、無料でOpenAI APIにアクセスできるカスタムAPIエンドポイントを提供する場合、APIキー欄を空白にするだけでAPIキーを提供せずにChatGPTを利用できます。ただし、第三者のAPIエンドポイントを利用する際は注意が必要で、信頼性の低いものは会話の中で個人情報を記録することがあります。プライバシーとセキュリティを保護するために、APIエンドポイントを使用する前に信頼性を確認してください。" }, "apiKey": { - "option": "独自のAPIキーを使用する", - "howTo": "個人用APIキーは<0>こちらで取得できます", + "howTo": "個人用APIキーは<0>こちらで取得できます。", "inputLabel": "APIキー" }, "customEndpoint": "カスタムAPIエンドポイントを使用する", - "shareGPT": "<0>ShareGPTをチェックしてください。これは、https://sharegpt.churchless.tech/share/v1/chat を駆動するAPIキーシェアリングツールです。", "advancedConfig": "詳細なAPI設定は<0>こちらで表示できます。", "noApiKeyWarning": "APIキーが入力されていません!API設定を確認してください。" } diff --git a/public/locales/ms/api.json b/public/locales/ms/api.json index 88eef36..764eacc 100644 --- a/public/locales/ms/api.json +++ b/public/locales/ms/api.json @@ -1,18 +1,15 @@ { "securityMessage": "Kami mengutamakan keselamatan kunci API anda dan mengendalikannya dengan penuh berhati-hati. Kunci anda disimpan secara eksklusif di pelayar anda dan tidak pernah dikongsi dengan mana-mana entiti pihak ketiga. Ia hanya digunakan untuk tujuan yang dimaksudkan untuk mengakses API OpenAI dan bukan untuk penggunaan yang tidak sah.", "apiEndpoint": { - "option": "Guna secara percuma", "inputLabel": "Hujung API", - "description": "Terima kasih kepada <0>Ayaka kerana menyediakan hujung API percuma: https://chatgpt-api.shn.hk/v1/", - "note": "Sila ambil perhatian bahawa ketersediaan hujung API percuma ini tidak kekal, kerana pembiayaannya terhad dan akhirnya akan habis. Pengguna dengan kunci API mereka sendiri boleh terus menggunakan BetterChatGPT tanpa gangguan." + "description": "Apabila anda memilih hujung nyawa API yang tidak rasmi, ia pada dasarnya berfungsi sebagai proksi. Proksi berfungsi dengan bertindak sebagai perantara di antara peranti anda dan pelayan destinasi, dalam kes ini, API OpenAI. Dengan berbuat demikian, ia membolehkan anda mengakses API OpenAI di kawasan di mana ia mungkin sebaliknya terhad.", + "warn": "Selain itu, jika anda menyediakan hujung nyawa API tersendiri yang memberikan akses percuma ke API OpenAI, anda boleh menggunakan ChatGPT tanpa perlu menyediakan kunci API dengan hanya meninggalkan medan kunci API kosong. Walau bagaimanapun, amat penting untuk berhati-hati semasa menggunakan hujung nyawa API pihak ketiga, kerana yang tidak boleh dipercayai mungkin merekodkan maklumat peribadi anda dalam perbualan. Sentiasa sahkan kebolehpercayaan hujung nyawa API sebelum menggunakannya untuk melindungi privasi dan keselamatan anda." }, "apiKey": { - "option": "Gunakan kunci API anda sendiri", - "howTo": "Dapatkan kunci API peribadi anda <0>di sini", + "howTo": "Dapatkan kunci API peribadi anda <0>di sini.", "inputLabel": "Kunci API" }, "customEndpoint": "Gunakan hujung API tersuai", - "shareGPT": "Lihat <0>ShareGPT, alat perkongsian kunci API yang membolehkan https://sharegpt.churchless.tech/share/v1/chat", "advancedConfig": "Lihat konfigurasi API lanjutan <0>di sini", "noApiKeyWarning": "Tiada kunci API yang dibekalkan! Sila periksa tetapan API anda." } diff --git a/public/locales/nb/api.json b/public/locales/nb/api.json index c6287e6..09c8cbe 100644 --- a/public/locales/nb/api.json +++ b/public/locales/nb/api.json @@ -1,18 +1,15 @@ { "securityMessage": "Vi prioriterer sikkerheten til API-nøkkelen din og behandler den med største forsiktighet. Nøkkelen din er kun lagret i nettleseren din og deles aldri med noen tredjeparts enhet. Den brukes utelukkende for det tiltenkte formålet med å få tilgang til OpenAI API og ikke for annen uautorisert bruk.", "apiEndpoint": { - "option": "Bruk gratis", - "inputLabel": "API-sluttpunkt", - "description": "Takk til <0>Ayaka for å tilby det gratis API-sluttpunktet: https://chatgpt-api.shn.hk/v1/", - "note": "Vennligst merk at tilgjengeligheten av den gratis sluttpunktet ikke er ubegrenset, da finansieringen er begrenset og vil til slutt bli uttømt. Brukere med egen API-nøkkel kan fortsette å bruke Better ChatGPT uten avbrudd." + "inputLabel": "API-endepunkt", + "description": "Når du velger et uoffisielt API-endepunkt, fungerer det som en proxy. En proxy fungerer ved å opptre som et mellomledd mellom enheten din og destinasjonsserveren, i dette tilfellet OpenAI API-et. Ved å gjøre dette, gjør det deg i stand til å få tilgang til OpenAI API-et i regioner hvor det ellers kunne være begrenset.", + "warn": "I tillegg, hvis du oppgir et egendefinert API-endepunkt som gir gratis tilgang til OpenAI API-et, kan du bruke ChatGPT uten behov for å oppgi en API-nøkkel ved å ganske enkelt la API-nøkkelfeltet stå tomt. Det er imidlertid viktig å være forsiktig når du bruker tredjeparts API-endepunkter, ettersom upålitelige kan logge personlig informasjon i samtaler. Bekreft alltid påliteligheten til et API-endepunkt før du bruker det for å beskytte personvernet og sikkerheten din." }, "apiKey": { - "option": "Bruk din egen API-nøkkel", - "howTo": "Få din personlige API-nøkkel <0>her", + "howTo": "Få din personlige API-nøkkel <0>her.", "inputLabel": "API-nøkkel" }, - "customEndpoint": "Bruk egendefinert API-sluttpunkt", - "shareGPT": "Sjekk ut <0>ShareGPT, et API-nøkkel delingsverktøy som driver https://sharegpt.churchless.tech/share/v1/chat", + "customEndpoint": "Bruk egendefinert API-endepunkt", "advancedConfig": "Vis avansert API-konfigurasjon <0>her", "noApiKeyWarning": "Ingen API-nøkkel angitt! Vennligst sjekk API-innstillingene dine." } diff --git a/public/locales/sv/api.json b/public/locales/sv/api.json index 89576f5..5592b0d 100644 --- a/public/locales/sv/api.json +++ b/public/locales/sv/api.json @@ -1,18 +1,15 @@ { "securityMessage": "Vi prioriterar säkerheten för din API-nyckel och hanterar den med största omsorg. Din nyckel lagras uteslutande på din webbläsare och delas aldrig med någon tredje part. Den används enbart för det avsedda ändamålet att få tillgång till OpenAI API och inte för någon annan obehörig användning.", "apiEndpoint": { - "option": "Använd gratis", - "inputLabel": "API Endpoint", - "description": "Tack till <0>Ayaka för att ha tillhandahållit den kostnadsfria API-endpointen: https://chatgpt-api.shn.hk/v1/", - "note": "Observera att tillgängligheten för den fria slutpunkten inte är obegränsad, eftersom dess finansiering är begränsad och kommer att ta slut. Användare med egen API-nyckel kan fortsätta använda Better ChatGPT utan avbrott." + "inputLabel": "API-slutpunkt", + "description": "När du väljer en inofficiell API-slutpunkt fungerar den som en proxy. En proxy fungerar genom att agera som mellanhand mellan din enhet och destinationsservern, i det här fallet OpenAI API. Genom att göra detta kan du få tillgång till OpenAI API i regioner där det annars kan vara begränsat.", + "warn": "Dessutom, om du anger en anpassad API-slutpunkt som ger gratis åtkomst till OpenAI API, kan du använda ChatGPT utan att behöva ange en API-nyckel genom att helt enkelt lämna API-nyckelfältet tomt. Det är dock viktigt att vara försiktig när du använder tredjeparts API-slutpunkter, eftersom opålitliga sådana kan logga din personliga information i konversationerna. Verifiera alltid tillförlitligheten hos en API-slutpunkt innan du använder den för att skydda din integritet och säkerhet." }, "apiKey": { - "option": "Använd din egen API-nyckel", - "howTo": "Få din personliga API-nyckel <0>här", + "howTo": "Få din personliga API-nyckel <0>här.", "inputLabel": "API-nyckel" }, - "customEndpoint": "Använd anpassad API-endpoint", - "shareGPT": "Kolla in <0>ShareGPT, ett API-nyckeldelningsverktyg som möjliggör https://sharegpt.churchless.tech/share/v1/chat", + "customEndpoint": "Använd anpassad API-slutpunkt", "advancedConfig": "Visa avancerad API-konfiguration <0>här", "noApiKeyWarning": "Ingen API-nyckel angiven! Vänligen kontrollera dina API-inställningar." } diff --git a/public/locales/zh-CN/api.json b/public/locales/zh-CN/api.json index 5e396cd..d435a56 100644 --- a/public/locales/zh-CN/api.json +++ b/public/locales/zh-CN/api.json @@ -1,18 +1,15 @@ { "securityMessage": "我们高度优先考虑您的 API 密钥的安全,并非常小心地处理它。您的密钥将专门存储在您的浏览器中,并且永远不会与任何第三方实体共享。它仅用于访问 OpenAI API 的预期用途,而不是用于任何其他未经授权的用途。", "apiEndpoint": { - "option": "使用免费的 API 端点", "inputLabel": "API 端点", - "description": "感谢 <0>Ayaka 提供免费的 API 端点: https://chatgpt-api.shn.hk/v1/。", - "note": "注意,免费端点的可用性并非无限期,因其资金有限,最终将耗尽。拥有自己 API 密钥的用户可以继续使用 Better ChatGPT 而不会有任何中断。" + "description": "选用非官方 API 端点时,它会作为代理运作。代理作用是在您的设备和目标服务器(在本例中为 OpenAI API)之间充当中介。通过这样做,您能够在被限制的地区访问 OpenAI API。", + "warn": "此外,如果您提供自定义 API 端点并授予免费访问 OpenAI API 的权限,您可以通过留空 API 密钥字段来使用 ChatGPT,而无需提供API密钥。但是,使用第三方 API 端点时务必谨慎,因为不可信的端点可能会在对话中记录您的个人信息。使用之前请始终验证 API 端点的可靠性以保护您的隐私和安全。" }, "apiKey": { - "option": "使用自己的 API 密钥", - "howTo": "在<0>此处获取您的个人 API 密钥", + "howTo": "在<0>此处获取您的个人 API 密钥。", "inputLabel": "API 密钥" }, "customEndpoint": "使用自定义 API 端点", - "shareGPT": "看看 <0>ShareGPT,一个 API key 共享工具,驱动 https://sharegpt.churchless.tech/share/v1/chat。", "advancedConfig": "在<0>此处查看高级 API 设置", "noApiKeyWarning": "缺少 API key,请检查 API 设置。" } diff --git a/public/locales/zh-HK/api.json b/public/locales/zh-HK/api.json index 560042a..9595ffe 100644 --- a/public/locales/zh-HK/api.json +++ b/public/locales/zh-HK/api.json @@ -1,18 +1,15 @@ { "securityMessage": "我哋將你嘅 API 金鑰嘅安全擺喺首位,非常小心噉處理佢。你嘅金鑰將專門儲存喺你嘅瀏覽器入面,並且永遠唔會共享畀任何第三方實體。佢僅用於訪問 OpenAI API 呢項預期用途,唔會用於任何其他未經授權嘅用途。", "apiEndpoint": { - "option": "使用免費嘅 API 端點", "inputLabel": "API 端點", - "description": "感謝 <0>Ayaka 提供免費嘅 API 端點: https://chatgpt-api.shn.hk/v1/。", - "note": "請注意,免費 API 端點嘅唔係永遠可用嘅,因為佢嘅資金有限,最終會被用盡。有自己 API 金鑰嘅用家可以繼續使用 Better ChatGPT 而唔會出現任何中斷。" + "description": "如果你選擇非官方嘅 API 終端,佢充當代理。代理係你嘅設備同目標伺服器(呢度即係 OpenAI API)之間嘅中介,噉你就可以喺用唔到 OpenAI API 嘅地區使用。", + "warn": "另外,如果你提供自訂嘅 API 端點,而且嗰個端點允許用户免費使用 OpenAI API,噉你唔使填寫 API 金鑰就可以用到 ChatGPT。但係,用第三方 API 端點嗰陣應該留心,因為唔可信嘅 API 端點可能會記低你喺傾偈入面嘅個人訊息。用第三方 API 端點之前請驗證佢是否可信,噉樣可以保護你嘅私隱同安全。" }, "apiKey": { - "option": "使用自己嘅 API 金鑰", - "howTo": "喺<0>呢度獲取你嘅個人 API 金鑰", + "howTo": "喺<0>呢度獲取你嘅個人 API 金鑰。", "inputLabel": "API 金鑰" }, "customEndpoint": "使用自訂 API 端點", - "shareGPT": "睇下 ShareGPT,一個 API key 共享工具,驅動 https://sharegpt.churchless.tech/share/v1/chat。", "advancedConfig": "喺<0>呢度睇下高級 API 設定", "noApiKeyWarning": "冇填寫 API key,請 check 返個 API 設定。" } diff --git a/public/locales/zh-TW/api.json b/public/locales/zh-TW/api.json index a802b22..80e5ed8 100644 --- a/public/locales/zh-TW/api.json +++ b/public/locales/zh-TW/api.json @@ -1,18 +1,15 @@ { "securityMessage": "我們高度優先考慮您的 API 金鑰的安全,並非常小心地處理它。您的金鑰將專門儲存在您的瀏覽器中,並且永遠不會與任何第三方實體共享。它僅用於訪問 OpenAI API 的預期用途,而不是用於任何其他未經授權的用途。", "apiEndpoint": { - "option": "使用免費的 API 端點", "inputLabel": "API 端點", - "description": "感謝 <0>Ayaka 提供免費的 API 端點: https://chatgpt-api.shn.hk/v1/。", - "note": "請注意,免費端點的可用性並非無限期,因其資金有限,最終將耗盡。擁有自己 API 金鑰的用戶可以繼續使用 Better ChatGPT 而不會有任何中斷。" + "description": "選擇非官方 API 端點時,它充當代理。代理是通過在您的設備和目標伺服器(在此例中為 OpenAI API)之間充當中介來工作的。透過這樣做,您能夠在其他可能受限制的地區訪問 OpenAI API。", + "warn": "此外,如果您提供了允許免費訪問 OpenAI API 的自定義 API 端點,您可以通過簡單地將 API 金鑰字段留空來使用 ChatGPT,而無需提供 API 金鑰。然而,在使用第三方 API 端點時必須保持警惕,因為不值得信任的端點可能會在對話中記錄個人信息。在使用 API 端點之前,始終確認其可靠性,以保護您的隱私和安全。" }, "apiKey": { - "option": "使用自己的 API 金鑰", - "howTo": "在<0>此處獲取您的個人 API 金鑰", + "howTo": "在<0>此處獲取您的個人 API 金鑰。", "inputLabel": "API 金鑰" }, "customEndpoint": "使用自定義 API 端點", - "shareGPT": "看看 <0>ShareGPT,一個 API key 共享工具,驅動 https://sharegpt.churchless.tech/share/v1/chat。", "advancedConfig": "在<0>此處查看高級 API 設定", "noApiKeyWarning": "未提供 API key,請檢查 API 設定。" } diff --git a/src/api/api.ts b/src/api/api.ts index 66ef1b2..5948796 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -67,7 +67,7 @@ export const getChatCompletionStream = async ( let error = text; if (text.includes('insufficient_quota')) { error += - '\nMessage from Better ChatGPT:\nToo many request! We recommend changing your API endpoint or API key'; + '\nMessage from Better ChatGPT:\nWe recommend changing your API endpoint or API key'; } else { error += '\nRate limited! Please try again later.'; } diff --git a/src/api/freeApi.ts b/src/api/freeApi.ts index 2ca4ea2..d8e9114 100644 --- a/src/api/freeApi.ts +++ b/src/api/freeApi.ts @@ -47,7 +47,7 @@ export const getChatCompletionStream = async ( let error = text; if (text.includes('insufficient_quota')) { error += - '\nMessage from Better ChatGPT:\nToo many request! We recommend changing your API endpoint or API key'; + '\nMessage from Better ChatGPT:\nWe recommend changing your API endpoint or API key'; } throw new Error(error); } diff --git a/src/components/ApiMenu/ApiMenu.tsx b/src/components/ApiMenu/ApiMenu.tsx index fc19e75..5ddc768 100644 --- a/src/components/ApiMenu/ApiMenu.tsx +++ b/src/components/ApiMenu/ApiMenu.tsx @@ -15,12 +15,9 @@ const ApiMenu = ({ const apiKey = useStore((state) => state.apiKey); const setApiKey = useStore((state) => state.setApiKey); - const apiFree = useStore((state) => state.apiFree); - const setApiFree = useStore((state) => state.setApiFree); const apiEndpoint = useStore((state) => state.apiEndpoint); const setApiEndpoint = useStore((state) => state.setApiEndpoint); - const [_apiFree, _setApiFree] = useState(apiFree); const [_apiKey, _setApiKey] = useState(apiKey || ''); const [_apiEndpoint, _setApiEndpoint] = useState(apiEndpoint); const [_customEndpoint, _setCustomEndpoint] = useState( @@ -28,7 +25,6 @@ const ApiMenu = ({ ); const handleSave = () => { - setApiFree(_apiFree); setApiKey(_apiKey); setApiEndpoint(_apiEndpoint); setIsModalOpen(false); @@ -79,91 +75,40 @@ const ApiMenu = ({ )} - - - {_apiFree && ( -
- {t('apiEndpoint.note', { ns: 'api' })} +
+
+ {t('apiKey.inputLabel', { ns: 'api' })}
- )} - - +
- {_apiFree === false && ( -
-
- {t('apiKey.inputLabel', { ns: 'api' })} -
- { - _setApiKey(e.target.value); - }} +
+

+ , + ]} /> -

- )} +

-
- , - ]} - /> -
+

{t('securityMessage', { ns: 'api' })}

-
- {t('securityMessage', { ns: 'api' })} -
+

{t('apiEndpoint.description', { ns: 'api' })}

-
- , - ]} - /> -
-
- , - ]} - /> +

{t('apiEndpoint.warn', { ns: 'api' })}

diff --git a/src/components/Menu/MenuOptions/Api.tsx b/src/components/Menu/MenuOptions/Api.tsx index dc517d5..767fa99 100644 --- a/src/components/Menu/MenuOptions/Api.tsx +++ b/src/components/Menu/MenuOptions/Api.tsx @@ -1,13 +1,11 @@ import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; -import useStore from '@store/store'; import PersonIcon from '@icon/PersonIcon'; import ApiMenu from '@components/ApiMenu'; const Config = () => { const { t } = useTranslation(); - const apiFree = useStore((state) => state.apiFree); const [isModalOpen, setIsModalOpen] = useState(false); return ( @@ -18,7 +16,7 @@ const Config = () => { onClick={() => setIsModalOpen(true)} > - {t('api')}: {apiFree ? t('free') : t('personal')} + {t('api')} {isModalOpen && } diff --git a/src/constants/auth.ts b/src/constants/auth.ts index 9909917..f960bdd 100644 --- a/src/constants/auth.ts +++ b/src/constants/auth.ts @@ -4,5 +4,4 @@ export const defaultAPIEndpoint = officialAPIEndpoint; export const availableEndpoints = [ officialAPIEndpoint, 'https://chatgpt-api.shn.hk/v1/', - 'https://sharegpt.churchless.tech/share/v1/chat', ]; diff --git a/src/hooks/useSubmit.ts b/src/hooks/useSubmit.ts index 0f952d8..2701fd9 100644 --- a/src/hooks/useSubmit.ts +++ b/src/hooks/useSubmit.ts @@ -6,12 +6,13 @@ import { getChatCompletion, getChatCompletionStream } from '@api/api'; import { parseEventSource } from '@api/helper'; import { limitMessageTokens } from '@utils/messageUtils'; import { _defaultChatConfig } from '@constants/chat'; +import { officialAPIEndpoint } from '@constants/auth'; const useSubmit = () => { const { t } = useTranslation('api'); const error = useStore((state) => state.error); const setError = useStore((state) => state.setError); - const apiFree = useStore((state) => state.apiFree); + const apiEndpoint = useStore((state) => state.apiEndpoint); const apiKey = useStore((state) => state.apiKey); const setGenerating = useStore((state) => state.setGenerating); const generating = useStore((state) => state.generating); @@ -22,13 +23,20 @@ const useSubmit = () => { message: MessageInterface[] ): Promise => { let data; - if (apiFree) { + if (!apiKey || apiKey.length === 0) { + // official endpoint + if (apiEndpoint === officialAPIEndpoint) { + throw new Error(t('noApiKeyWarning') as string); + } + + // other endpoints data = await getChatCompletion( useStore.getState().apiEndpoint, message, _defaultChatConfig ); } else if (apiKey) { + // own apikey data = await getChatCompletion( useStore.getState().apiEndpoint, message, @@ -65,21 +73,27 @@ const useSubmit = () => { ); if (messages.length === 0) throw new Error('Message exceed max token!'); - if (apiFree) { + // no api key (free) + if (!apiKey || apiKey.length === 0) { + // official endpoint + if (apiEndpoint === officialAPIEndpoint) { + throw new Error(t('noApiKeyWarning') as string); + } + + // other endpoints stream = await getChatCompletionStream( useStore.getState().apiEndpoint, messages, chats[currentChatIndex].config ); } else if (apiKey) { + // own apikey stream = await getChatCompletionStream( useStore.getState().apiEndpoint, messages, chats[currentChatIndex].config, apiKey ); - } else { - throw new Error(t('noApiKeyWarning') as string); } if (stream) { diff --git a/src/store/auth-slice.ts b/src/store/auth-slice.ts index 442983d..b11a6c8 100644 --- a/src/store/auth-slice.ts +++ b/src/store/auth-slice.ts @@ -3,17 +3,14 @@ import { StoreSlice } from './store'; export interface AuthSlice { apiKey?: string; - apiFree: boolean; apiEndpoint: string; firstVisit: boolean; setApiKey: (apiKey: string) => void; - setApiFree: (apiFree: boolean) => void; setApiEndpoint: (apiEndpoint: string) => void; setFirstVisit: (firstVisit: boolean) => void; } export const createAuthSlice: StoreSlice = (set, get) => ({ - apiFree: false, apiEndpoint: defaultAPIEndpoint, firstVisit: true, setApiKey: (apiKey: string) => { @@ -22,12 +19,6 @@ export const createAuthSlice: StoreSlice = (set, get) => ({ apiKey: apiKey, })); }, - setApiFree: (apiFree: boolean) => { - set((prev: AuthSlice) => ({ - ...prev, - apiFree: apiFree, - })); - }, setApiEndpoint: (apiEndpoint: string) => { set((prev: AuthSlice) => ({ ...prev, diff --git a/src/store/migrate.ts b/src/store/migrate.ts index c26b6c3..7094c47 100644 --- a/src/store/migrate.ts +++ b/src/store/migrate.ts @@ -5,6 +5,7 @@ import { LocalStorageInterfaceV3ToV4, LocalStorageInterfaceV4ToV5, LocalStorageInterfaceV5ToV6, + LocalStorageInterfaceV6ToV7, } from '@type/chat'; import { _defaultChatConfig, @@ -61,3 +62,14 @@ export const migrateV5 = (persistedState: LocalStorageInterfaceV5ToV6) => { }; }); }; + +export const migrateV6 = (persistedState: LocalStorageInterfaceV6ToV7) => { + if ( + persistedState.apiEndpoint === + 'https://sharegpt.churchless.tech/share/v1/chat' + ) { + persistedState.apiEndpoint = 'https://chatgpt-api.shn.hk/v1/'; + } + if (!persistedState.apiKey || persistedState.apiKey.length === 0) + persistedState.apiKey = ''; +}; diff --git a/src/store/store.ts b/src/store/store.ts index f5dfdf8..4af3822 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -12,6 +12,7 @@ import { LocalStorageInterfaceV3ToV4, LocalStorageInterfaceV4ToV5, LocalStorageInterfaceV5ToV6, + LocalStorageInterfaceV6ToV7, } from '@type/chat'; import { migrateV0, @@ -20,6 +21,7 @@ import { migrateV3, migrateV4, migrateV5, + migrateV6, } from './migrate'; export type StoreState = ChatSlice & @@ -48,7 +50,6 @@ const useStore = create()( chats: state.chats, currentChatIndex: state.currentChatIndex, apiKey: state.apiKey, - apiFree: state.apiFree, apiEndpoint: state.apiEndpoint, theme: state.theme, autoTitle: state.autoTitle, @@ -59,7 +60,7 @@ const useStore = create()( firstVisit: state.firstVisit, hideSideMenu: state.hideSideMenu, }), - version: 6, + version: 7, migrate: (persistedState, version) => { switch (version) { case 0: @@ -74,6 +75,8 @@ const useStore = create()( migrateV4(persistedState as LocalStorageInterfaceV4ToV5); case 5: migrateV5(persistedState as LocalStorageInterfaceV5ToV6); + case 6: + migrateV6(persistedState as LocalStorageInterfaceV6ToV7); break; } return persistedState as StoreState; diff --git a/src/types/chat.ts b/src/types/chat.ts index c74ea7b..c1d8125 100644 --- a/src/types/chat.ts +++ b/src/types/chat.ts @@ -94,3 +94,19 @@ export interface LocalStorageInterfaceV5ToV6 { autoTitle: boolean; prompts: Prompt[]; } + +export interface LocalStorageInterfaceV6ToV7 { + chats: ChatInterface[]; + currentChatIndex: number; + apiFree?: boolean; + apiKey: string; + apiEndpoint: string; + theme: Theme; + autoTitle: boolean; + prompts: Prompt[]; + defaultChatConfig: ConfigInterface; + defaultSystemMessage: string; + hideMenuOptions: boolean; + firstVisit: boolean; + hideSideMenu: boolean; +}