Skip to content

Commit

Permalink
Merge branch 'ztjhz:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzt committed May 5, 2023
2 parents 9d6a2c3 + f0a0156 commit ab4ed74
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 144 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"title": "${productName} ${version}",
"icon": "dist/icon-rounded.png"
},
"mac": {
"icon": "dist/icon-rounded.png"
},
"linux": {
"target": [
"tar.gz",
Expand Down
1 change: 1 addition & 0 deletions public/locales/da/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"resetCost": "Nulstil Omkostninger",
"countTotalTokens": "Tæl totale tokens",
"morePrompts": "Du kan finde flere opgaver her: ",
"clearPrompts": "Ryd prompter",
"postOnShareGPT": {
"title": "Indlæg på ShareGPT",
"warning": "Vær opmærksom på, at ved at poste din samtale på ShareGPT, vil den blive offentligt tilgængelig og synlig for alle. Når den er postet, kan samtalen ikke skjules eller slettes og kan blive arkiveret eller delt af andre. Vi råder dig til at overveje nøje og undgå at dele følsomme eller private oplysninger på denne platform."
Expand Down
1 change: 1 addition & 0 deletions public/locales/en-US/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"resetCost": "Reset Costs",
"countTotalTokens": "Count total tokens",
"morePrompts": "You can find more prompts here: ",
"clearPrompts": "Clear prompts",
"postOnShareGPT": {
"title": "Post on ShareGPT",
"warning": "Please be aware that by posting your conversation on ShareGPT, it will become publicly accessible and viewable to anyone. Once posted, the conversation cannot be hidden or deleted, and may be archived or shared by others. We advise you to consider carefully and avoid sharing sensitive or private information on this platform."
Expand Down
1 change: 1 addition & 0 deletions public/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"resetCost": "Reset Costs",
"countTotalTokens": "Count total tokens",
"morePrompts": "You can find more prompts here: ",
"clearPrompts": "Clear prompts",
"postOnShareGPT": {
"title": "Post on ShareGPT",
"warning": "Please be aware that by posting your conversation on ShareGPT, it will become publicly accessible and viewable to anyone. Once posted, the conversation cannot be hidden or deleted, and may be archived or shared by others. We advise you to consider carefully and avoid sharing sensitive or private information on this platform."
Expand Down
1 change: 1 addition & 0 deletions public/locales/es/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"resetCost": "Reiniciar costos",
"countTotalTokens": "Contar tokens totales",
"morePrompts": "Puedes encontrar más prompts aquí: ",
"clearPrompts": "Prompts claras",
"postOnShareGPT": {
"title": "Publicar en ShareGPT",
"warning": "Por favor, tenga en cuenta que al publicar su conversación en ShareGPT, esta será accesible y visible para cualquiera. Una vez publicada, la conversación no se podrá ocultar ni eliminar, y puede ser archivada o compartida por otros. Le aconsejamos que lo considere detenidamente y evite compartir información sensible o privada en esta plataforma."
Expand Down
1 change: 1 addition & 0 deletions public/locales/fr/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"resetCost": "Réinitialiser les coûts",
"countTotalTokens": "Compter le nombre total de jetons",
"morePrompts": "Vous pouvez trouver plus de prompts ici : ",
"clearPrompts": "Effacer les prompts",
"postOnShareGPT": {
"title": "Publier sur ShareGPT",
"warning": "Veuillez noter que si vous publiez votre conversation sur ShareGPT, elle deviendra accessible au public et visible par tous. Une fois publiée, la conversation ne peut pas être cachée ou supprimée, et peut être archivée ou partagée par d'autres. Nous vous conseillons de considérer attentivement et d'éviter de partager des informations sensibles ou privées sur cette plateforme."
Expand Down
1 change: 1 addition & 0 deletions public/locales/it/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"resetCost": "Ripristina costi",
"countTotalTokens": "Conteggio totale dei token",
"morePrompts": "Puoi trovare altri prompt qui:",
"clearPrompts": "Cancella prompts",
"postOnShareGPT": {
"title": "Pubblica su ShareGPT",
"warning": "Ti ricordiamo che pubblicando la tua conversazione su ShareGPT, questa diventerà pubblicamente accessibile e visualizzabile da chiunque. Una volta pubblicata, la conversazione non può essere nascosta o cancellata e può essere archiviata o condivisa da altri. Ti consigliamo di valutare attentamente e di evitare di condividere informazioni sensibili o private su questa piattaforma."
Expand Down
1 change: 1 addition & 0 deletions public/locales/ja/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"resetCost": "コストをリセットする",
"countTotalTokens": "トークンの合計数をカウント",
"morePrompts": "ここでさらにプロンプトを見つけることができます:",
"clearPrompts": "プロンプトをクリア",
"postOnShareGPT": {
"title": "ShareGPTに投稿",
"warning": "ShareGPTに会話を投稿すると、誰でもアクセスして閲覧できるようになることに注意してください。一度投稿すると、会話は非表示にできず、削除もできません。また、他の人がアーカイブや共有する可能性があります。このプラットフォームで機密性のある情報や個人情報を共有しないように注意してください。"
Expand Down
1 change: 1 addition & 0 deletions public/locales/ms/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"resetCost": "Reset Kos",
"countTotalTokens": "Kira jumlah token keseluruhan",
"morePrompts": "Anda boleh mencari lebih banyak arahan di sini: ",
"clearPrompts": "Kosongkan arahan",
"postOnShareGPT": {
"title": "Siarkan di ShareGPT",
"warning": "Sila ambil perhatian bahawa dengan menyiarkan perbualan anda di ShareGPT, ia akan menjadi boleh diakses dan dilihat oleh sesiapa sahaja. Setelah disiarkan, perbualan tidak boleh disembunyikan atau dipadam, dan mungkin diarkibkan atau dikongsi oleh orang lain. Kami menasihatkan anda untuk mempertimbangkan dengan teliti dan mengelakkan berkongsi maklumat sensitif atau peribadi di platform ini."
Expand Down
1 change: 1 addition & 0 deletions public/locales/nb/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"resetCost": "Tilbakestill kostnader",
"countTotalTokens": "Tell totale token",
"morePrompts": "Du kan finne flere oppgaver her: ",
"clearPrompts": "Tøm oppgave",
"postOnShareGPT": {
"title": "Innlegg på ShareGPT",
"warning": "Vær oppmerksom på at ved å poste samtalen din på ShareGPT, vil den bli offentlig tilgjengelig og synlig for alle. Når den er postet, kan samtalen ikke skjules eller slettes, og den kan bli arkivert eller delt av andre. Vi anbefaler deg å tenke nøye gjennom og unngå å dele sensitiv eller privat informasjon på denne plattformen."
Expand Down
1 change: 1 addition & 0 deletions public/locales/sv/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"resetCost": "Återställ kostnader",
"countTotalTokens": "Räkna totala token",
"morePrompts": "Du kan hitta fler uppmaningar här: ",
"clearPrompts": "Rensa uppmaningar",
"postOnShareGPT": {
"title": "Inlägg på ShareGPT",
"warning": "Var medveten om att genom att posta din konversation på ShareGPT kommer den att bli offentligt tillgänglig och synlig för alla. När den väl är postad kan konversationen varken döljas eller raderas och kan arkiveras eller delas av andra. Vi rekommenderar dig att tänka noggrant igenom och undvika att dela känslig eller privat information på denna plattform."
Expand Down
1 change: 1 addition & 0 deletions public/locales/zh-CN/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"resetCost": "重置费用",
"countTotalTokens": "计算总 Token 数",
"morePrompts": "更多提示词请点击:",
"clearPrompts": "清除提示词",
"postOnShareGPT": {
"title": "发布至 ShareGPT",
"warning": "请注意,把您的对话发布到 ShareGPT 后,任何人都可以公开访问和查看。发布后,对话不能被隐藏或删除,且可能被其他人存档或分享。建议您慎重考虑,在这个平台上避免分享敏感或私密信息。"
Expand Down
1 change: 1 addition & 0 deletions public/locales/zh-HK/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"resetCost": "重置費用",
"countTotalTokens": "計算總 Token 數",
"morePrompts": "如果你想揾更多 prompt,撳呢度:",
"clearPrompts": "清空 prompts",
"postOnShareGPT": {
"title": "po 上 ShareGPT",
"warning": "請注意,你將呢個傾偈 po 上 ShareGPT 之後,佢會係公開嘅,所有人都可以見到你寫嘅嘢。一旦 po 咗,呢個傾偈將冇得被隱藏或刪除,亦都可能畀人存檔同分享。我哋建議你仔細諗下,唔好喺嗰度分享敏感或私人資料。"
Expand Down
1 change: 1 addition & 0 deletions public/locales/zh-TW/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"resetCost": "重置費用",
"countTotalTokens": "計算總 Token 數",
"morePrompts": "更多提示詞請點選:",
"clearPrompts": "清除提示詞",
"postOnShareGPT": {
"title": "發佈至 ShareGPT",
"warning": "請注意,將您的對話發佈至 ShareGPT 後,任何人都可以公開訪問和查看。一旦發佈,對話將無法隱藏或刪除,並且可能被他人存檔或分享。我們建議您慎重考慮,並避免在此平台上分享敏感或私人信息。"
Expand Down
4 changes: 2 additions & 2 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const getChatCompletion = async (
body: JSON.stringify({
messages,
...config,
max_tokens: null,
max_tokens: undefined,
}),
});
if (!response.ok) throw new Error(await response.text());
Expand Down Expand Up @@ -51,7 +51,7 @@ export const getChatCompletionStream = async (
body: JSON.stringify({
messages,
...config,
max_tokens: null,
max_tokens: undefined,
stream: true,
}),
});
Expand Down
67 changes: 0 additions & 67 deletions src/api/customApi.ts

This file was deleted.

57 changes: 0 additions & 57 deletions src/api/freeApi.ts

This file was deleted.

17 changes: 11 additions & 6 deletions src/components/ApiMenu/ApiMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import React, { useEffect, useState } from 'react';
import { useTranslation, Trans } from 'react-i18next';
import useStore from '@store/store';

import useHideOnOutsideClick from '@hooks/useHideOnOutsideClick';

import PopupModal from '@components/PopupModal';

import { availableEndpoints, defaultAPIEndpoint } from '@constants/auth';

import DownChevronArrow from '@icon/DownChevronArrow';

const ApiMenu = ({
Expand Down Expand Up @@ -53,7 +57,7 @@ const ApiMenu = ({
{t('customEndpoint', { ns: 'api' })}
</label>

<div className='flex gap-2 items-center justify-center mb-6'>
<div className='flex gap-2 items-center mb-6'>
<div className='min-w-fit text-gray-900 dark:text-gray-300 text-sm'>
{t('apiEndpoint.inputLabel', { ns: 'api' })}
</div>
Expand Down Expand Up @@ -128,20 +132,21 @@ const ApiEndpointSelector = ({
_apiEndpoint: string;
_setApiEndpoint: React.Dispatch<React.SetStateAction<string>>;
}) => {
const [dropDown, setDropDown] = useState<boolean>(false);
const [dropDown, setDropDown, dropDownRef] = useHideOnOutsideClick();

return (
<div className='w-full relative'>
<div className='w-[40vw] relative flex-1'>
<button
className='btn btn-neutral btn-small flex w-32 flex justify-between w-full'
className='btn btn-neutral btn-small flex justify-between w-full'
type='button'
onClick={() => setDropDown((prev) => !prev)}
>
{_apiEndpoint}
<span className='truncate'>{_apiEndpoint}</span>
<DownChevronArrow />
</button>
<div
id='dropdown'
ref={dropDownRef}
className={`${
dropDown ? '' : 'hidden'
} absolute top-100 bottom-100 z-10 bg-white rounded-lg shadow-xl border-b border-black/10 dark:border-gray-900/50 text-gray-800 dark:text-gray-100 group dark:bg-gray-800 opacity-90 w-32 w-full`}
Expand All @@ -152,7 +157,7 @@ const ApiEndpointSelector = ({
>
{availableEndpoints.map((endpoint) => (
<li
className='px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white cursor-pointer'
className='px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white cursor-pointer truncate'
onClick={() => {
_setApiEndpoint(endpoint);
setDropDown(false);
Expand Down
12 changes: 12 additions & 0 deletions src/components/PromptLibraryMenu/PromptLibraryMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ const PromptLibraryMenuPopUp = ({
_setPrompts(updatedPrompts);
};

const clearPrompts = () => {
_setPrompts([]);
};

const handleOnFocus = (e: React.FocusEvent<HTMLTextAreaElement, Element>) => {
e.target.style.height = 'auto';
e.target.style.height = `${e.target.scrollHeight}px`;
Expand Down Expand Up @@ -149,6 +153,14 @@ const PromptLibraryMenuPopUp = ({
<div className='flex justify-center cursor-pointer' onClick={addPrompt}>
<PlusIcon />
</div>
<div className='flex justify-center mt-2'>
<div
className='btn btn-neutral cursor-pointer text-xs'
onClick={clearPrompts}
>
{t('clearPrompts')}
</div>
</div>
<div className='mt-6 px-2'>
{t('morePrompts')}
<a
Expand Down
7 changes: 4 additions & 3 deletions src/components/SettingsMenu/TotalTokenCost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ const tokenCostToCost = (
model: ModelOptions
) => {
if (!tokenCost) return 0;
const { price, unit } = modelCost[model as keyof typeof modelCost];
const completionCost = (price / unit) * tokenCost.completionTokens;
const promptCost = (price / unit) * tokenCost.promptTokens;
const { prompt, completion } = modelCost[model as keyof typeof modelCost];
const completionCost =
(completion.price / completion.unit) * tokenCost.completionTokens;
const promptCost = (prompt.price / prompt.unit) * tokenCost.promptTokens;
return completionCost + promptCost;
};

Expand Down
4 changes: 3 additions & 1 deletion src/components/TokenCount/TokenCount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ const TokenCount = React.memo(() => {
);

const cost = useMemo(() => {
const price = modelCost[model].price * (tokenCount / modelCost[model].unit);
const price =
modelCost[model].prompt.price *
(tokenCount / modelCost[model].prompt.unit);
return price.toPrecision(3);
}, [model, tokenCount]);

Expand Down

0 comments on commit ab4ed74

Please sign in to comment.