Skip to content

Commit

Permalink
Add Setting to imageModel
Browse files Browse the repository at this point in the history
  • Loading branch information
SPWwj committed May 13, 2023
1 parent 09feeea commit e2be9ae
Show file tree
Hide file tree
Showing 22 changed files with 323 additions and 77 deletions.
3 changes: 2 additions & 1 deletion app/api/openai/typing.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type {
CreateChatCompletionRequest,
CreateChatCompletionResponse,
CreateImageRequestSizeEnum,
} from "openai";

export type ChatRequest = CreateChatCompletionRequest;
export type ChatResponse = CreateChatCompletionResponse;

export type ImageRequestSizeEnum = CreateImageRequestSizeEnum;
export type Updater<T> = (updater: (value: T) => void) => void;
2 changes: 1 addition & 1 deletion app/components/ImageList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ImagesResponseDataInner } from "openai";
import React, { FC } from "react";
import styles from "./ImageList.module.scss";
import styles from "./imageList.module.scss";

interface ImageListProps {
images?: ImagesResponseDataInner[];
Expand Down
5 changes: 2 additions & 3 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
Message,
SubmitKey,
useChatStore,
BOT_HELLO,
createMessage,
useAccessStore,
Theme,
Expand Down Expand Up @@ -560,9 +559,9 @@ export function Chat() {

if (
context.length === 0 &&
session.messages.at(0)?.content !== BOT_HELLO.content
session.messages.at(0)?.content !== session.botHello.content
) {
const copiedHello = Object.assign({}, BOT_HELLO);
const copiedHello = Object.assign({}, session.botHello);
if (!accessStore.isAuthorized()) {
copiedHello.content = Locale.Error.Unauthorized;
}
Expand Down
74 changes: 74 additions & 0 deletions app/components/image-model-config.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {
ALL_MODELS,
ImageModalConfigValidator,
ImageModelConfig,
ModalConfigValidator,
ModelConfig,
} from "../store";

import Locale from "../locales";
import { InputRange } from "./input-range";
import { Input, List, ListItem, Select } from "./ui-lib";
import { ImageRequestSizeEnum } from "../api/openai/typing";
import { CreateImageRequestSizeEnum } from "openai";

export function ImageModelConfigList(props: {
imageModelConfig: ImageModelConfig;
updateConfig: (updater: (config: ImageModelConfig) => void) => void;
}) {
return (
<>
<ListItem title={Locale.Settings.ImageModel.Title}>
<input value={Locale.Settings.ImageModel.Model} disabled={true} />
</ListItem>
<ListItem title={Locale.Settings.ImageModel.Command}>
<input
value={props.imageModelConfig.command}
onChange={(e) => {
props.updateConfig((config) => {
config.command = e.currentTarget.value; // Assign the parsed value
return config;
});
}}
/>
</ListItem>
<ListItem title={Locale.Settings.ImageModel.CountLimit}>
<InputRange
value={props.imageModelConfig.imageLimit.toString()} // Keep the value as a string
onChange={(e) => {
const newValue = parseInt(e.currentTarget.value, 10); // Parse the value as an integer
if (!isNaN(newValue)) {
props.updateConfig((config) => {
config.imageLimit = newValue; // Assign the parsed value
return config;
});
}
}}
min={"1"} // Convert the min value to a string
max={"10"} // Convert the max value to a string
step={"1"} // Convert the step value to a string
/>
</ListItem>
<ListItem title={Locale.Settings.ImageModel.Size}>
<Select
value={props.imageModelConfig.size}
onChange={(e) => {
const newSize = ImageModalConfigValidator.size(
e.currentTarget.value,
);
props.updateConfig((config) => {
config.size = newSize;
return config;
});
}}
>
{Object.values(CreateImageRequestSizeEnum).map((v) => (
<option value={v} key={v}>
{v}
</option>
))}
</Select>
</ListItem>
</>
);
}
13 changes: 13 additions & 0 deletions app/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { ErrorBoundary } from "./error";
import { InputRange } from "./input-range";
import { useNavigate } from "react-router-dom";
import { Avatar, AvatarPicker } from "./emoji";
import { ImageModelConfigList } from "./image-model-config";

function EditPromptModal(props: { id: number; onClose: () => void }) {
const promptStore = usePromptStore();
Expand Down Expand Up @@ -580,6 +581,18 @@ export function Settings() {
}}
/>
</List>
<List>
<ImageModelConfigList
imageModelConfig={config.imageModelConfig}
updateConfig={(upater) => {
const imageModelConfig = { ...config.imageModelConfig };
upater(imageModelConfig);
config.update(
(config) => (config.imageModelConfig = imageModelConfig),
);
}}
/>
</List>

{shouldShowPromptModal && (
<UserPromptModal onClose={() => setShowPromptModal(false)} />
Expand Down
1 change: 1 addition & 0 deletions app/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ export const ACCESS_CODE_PREFIX = "ak-";
export const LAST_INPUT_KEY = "last-input";
export const IMAGE_PLACEHOLDER = "Loading your image...";
export const IMAGE_ERROR = "IMAGE_ERROR";
export const COMMAND_IMAGE = "/image";
14 changes: 12 additions & 2 deletions app/locales/cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ const cn = {
Placeholder: "请输入访问密码",
},
Model: "模型 (model)",
ImageModel: {
Title: "图片模型",
Model: "DALL-E模型",
Command: "生成图片指令",
CountLimit: "图片生成次数限制",
Size: "图片生成尺寸",
},
Temperature: {
Title: "随机性 (temperature)",
SubTitle: "值越大,回复越随机",
Expand All @@ -170,8 +177,11 @@ const cn = {
},
Store: {
DefaultTopic: "新的聊天",
BotHello:
"您好!今天我能为您做些什么呢?\n 要生成图片,请使用 `/Image {关键词}。`",
BotHello: "您好!今天我能为您做些什么呢?",
BotHelloWithCommand: (command: string) =>
"您好!今天我能为您做些什么呢?\n 要生成图片,请使用 `" +
command +
" {关键词}。`",
Error: "出错了,稍后重试吧",
Prompt: {
History: (content: string) =>
Expand Down
24 changes: 17 additions & 7 deletions app/locales/cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ const cs: LocaleType = {
},
Lang: {
Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language`
All: "Všechny jazyky",
Options: {
All: "Všechny jazyky",
Options: {
cn: "简体中文",
en: "English",
tw: "繁體中文",
Expand Down Expand Up @@ -156,6 +156,13 @@ const cs: LocaleType = {
Placeholder: "Potřebujete přístupový kód",
},
Model: "Model",
ImageModel: {
Title: "Obrázkový model",
Model: "Model DALL-E",
Command: "Příkaz pro generování obrázků",
CountLimit: "Limit počtu generovaných obrázků",
Size: "Velikost generovaného obrázku",
},
Temperature: {
Title: "Teplota",
SubTitle: "Větší hodnota činí výstup náhodnějším",
Expand All @@ -166,13 +173,16 @@ const cs: LocaleType = {
},
PresencePenlty: {
Title: "Přítomnostní korekce",
SubTitle:
"Větší hodnota zvyšuje pravděpodobnost nových témat.",
SubTitle: "Větší hodnota zvyšuje pravděpodobnost nových témat.",
},
},
Store: {
DefaultTopic: "Nová konverzace",
BotHello: "Ahoj! Jak mohu dnes pomoci?",
BotHelloWithCommand: (command: string) =>
"Ahoj! Jak mohu dnes pomoci?\n Pro generování obrázků použijte `" +
command +
" {klíčové slovo}.`",
Error: "Něco se pokazilo, zkuste to prosím později.",
Prompt: {
History: (content: string) =>
Expand All @@ -182,7 +192,7 @@ const cs: LocaleType = {
"Vytvořte prosím název o čtyřech až pěti slovech vystihující průběh našeho rozhovoru bez jakýchkoli úvodních slov, interpunkčních znamének, uvozovek, teček, symbolů nebo dalšího textu. Odstraňte uvozovky.",
Summarize:
"Krátce shrň naši diskusi v rozsahu do 200 slov a použij ji jako podnět pro budoucí kontext.",
},
},
},
Copy: {
Success: "Zkopírováno do schránky",
Expand Down Expand Up @@ -231,15 +241,15 @@ const cs: LocaleType = {
More: "Najít více",
NotShow: "Nezobrazovat znovu",
ConfirmNoShow: "Potvrdit zakázání?Můžete jej povolit později v nastavení.",
},
},

UI: {
Confirm: "Potvrdit",
Cancel: "Zrušit",
Close: "Zavřít",
Create: "Vytvořit",
Edit: "Upravit",
}
},
};

export default cs;
11 changes: 11 additions & 0 deletions app/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ const de: LocaleType = {
Placeholder: "Zugangscode erforderlich",
},
Model: "Modell",
ImageModel: {
Title: "Bildmodell",
Model: "DALL-E Modell",
Command: "Bildgenerierungsbefehl",
CountLimit: "Bildgenerierungslimit",
Size: "Bildgenerierungsgröße",
},
Temperature: {
Title: "Temperature", //Temperatur
SubTitle: "Ein größerer Wert führt zu zufälligeren Antworten",
Expand All @@ -175,6 +182,10 @@ const de: LocaleType = {
Store: {
DefaultTopic: "Neues Gespräch",
BotHello: "Hallo! Wie kann ich Ihnen heute helfen?",
BotHelloWithCommand: (command: string) =>
"Hallo! Wie kann ich Ihnen heute helfen?\n Um Bilder zu generieren, verwenden Sie `" +
command +
" {Schlüsselwort}.`",
Error:
"Etwas ist schief gelaufen, bitte versuchen Sie es später noch einmal.",
Prompt: {
Expand Down
14 changes: 12 additions & 2 deletions app/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ const en: LocaleType = {
Placeholder: "Need Access Code",
},
Model: "Model",
ImageModel: {
Title: "Image Model",
Model: "DALL-E Model",
Command: "Generate Image Command",
CountLimit: "Image Generation Limit",
Size: "Image Generation Size",
},
Temperature: {
Title: "Temperature",
SubTitle: "A larger value makes the more random output",
Expand All @@ -172,8 +179,11 @@ const en: LocaleType = {
},
Store: {
DefaultTopic: "New Conversation",
BotHello:
"Hello! How can I assist you today?\n To generate images, use `/Image {keyword}.`",
BotHello: "Hello! How can I assist you today?",
BotHelloWithCommand: (command: string) =>
"Hello! How can I assist you today?\n To generate images, use `" +
command +
" {keyword}.`",
Error: "Something went wrong, please try again later.",
Prompt: {
History: (content: string) =>
Expand Down
11 changes: 11 additions & 0 deletions app/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ const es: LocaleType = {
Placeholder: "Necesita código de acceso",
},
Model: "Modelo",
ImageModel: {
Title: "Modelo de imagen",
Model: "Modelo DALL-E",
Command: "Comando de generación de imágenes",
CountLimit: "Límite de generación de imágenes",
Size: "Tamaño de generación de imagen",
},
Temperature: {
Title: "Temperatura",
SubTitle: "Un valor mayor genera una salida más aleatoria",
Expand All @@ -173,6 +180,10 @@ const es: LocaleType = {
Store: {
DefaultTopic: "Nueva conversación",
BotHello: "¡Hola! ¿Cómo puedo ayudarte hoy?",
BotHelloWithCommand: (command: string) =>
"¡Hola! ¿Cómo puedo ayudarte hoy?\n Para generar imágenes, usa `" +
command +
" {palabra clave}.`",
Error: "Algo salió mal, por favor intenta nuevamente más tarde.",
Prompt: {
History: (content: string) =>
Expand Down
11 changes: 11 additions & 0 deletions app/locales/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ const it: LocaleType = {
Placeholder: "Inserisci il codice d'accesso",
},
Model: "Modello GPT",
ImageModel: {
Title: "Modello di immagine",
Model: "Modello DALL-E",
Command: "Comando di generazione immagine",
CountLimit: "Limite di generazione immagine",
Size: "Dimensione di generazione immagine",
},
Temperature: {
Title: "Temperature",
SubTitle: "Un valore maggiore rende l'output più casuale",
Expand All @@ -174,6 +181,10 @@ const it: LocaleType = {
Store: {
DefaultTopic: "Nuova conversazione",
BotHello: "Ciao, come posso aiutarti oggi?",
BotHelloWithCommand: (command: string) =>
"Ciao, come posso aiutarti oggi?\n Per generare immagini, usa `" +
command +
" {parola chiave}.`",
Error: "Qualcosa è andato storto, riprova più tardi.",
Prompt: {
History: (content: string) =>
Expand Down
11 changes: 11 additions & 0 deletions app/locales/jp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ const jp: LocaleType = {
Placeholder: "アクセスパスワードを入力してください",
},
Model: "モデル (model)",
ImageModel: {
Title: "画像モデル",
Model: "DALL-Eモデル",
Command: "画像生成コマンド",
CountLimit: "画像生成回数制限",
Size: "画像生成サイズ",
},
Temperature: {
Title: "ランダム性 (temperature)",
SubTitle:
Expand All @@ -175,6 +182,10 @@ const jp: LocaleType = {
Store: {
DefaultTopic: "新しいチャット",
BotHello: "何かお手伝いできることはありますか",
BotHelloWithCommand: (command: string) =>
"何かお手伝いできることはありますか\n 画像を生成するには、`" +
command +
" {キーワード}.`を使用してください",
Error: "エラーが発生しました。しばらくしてからやり直してください。",
Prompt: {
History: (content: string) =>
Expand Down
Loading

0 comments on commit e2be9ae

Please sign in to comment.