Skip to content

Commit

Permalink
Add settings for llm
Browse files Browse the repository at this point in the history
  • Loading branch information
derneuere committed Dec 30, 2023
1 parent 5287003 commit 029c22b
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/actions/photosActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ export function fetchNoTimestampPhotoPaginated(dispatch: AppDispatch, page: numb
export function generatePhotoIm2txtCaption(image_hash: string) {
return function cb(dispatch: Dispatch<any>) {
dispatch({ type: "GENERATE_PHOTO_CAPTION" });
Server.post("photosedit/generateim2txt", { image_hash })
Server.post("photosedit/generateim2txt", { image_hash }, { timeout: 200000 })
.then(() => {
dispatch({ type: "GENERATE_PHOTO_CAPTION_FULFILLED" });
// @ts-ignore
Expand Down
1 change: 1 addition & 0 deletions src/api_client/site-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const SiteSettingsSchema = z.object({
map_api_key: z.string(),
map_api_provider: z.string(),
captioning_model: z.string(),
llm_model: z.string(),
});

export type SiteSettings = z.infer<typeof SiteSettingsSchema>;
Expand Down
48 changes: 48 additions & 0 deletions src/layouts/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,54 @@ export function Settings() {
}}
/>
</Card>
<Card shadow="md">
<Stack>
<Title order={4} sx={{ marginBottom: 16 }}>
<Trans i18nKey="settings.llm">Large Language Model Settings</Trans>
</Title>
<Switch
label={t("settings.enablellm")}
checked={userSelfDetails.llm_settings?.enabled}
onChange={event => {
setUserSelfDetails({
...userSelfDetails,
llm_settings: {
...userSelfDetails.llm_settings,
enabled: event.currentTarget.checked,
},
});
}}
/>
<Switch
label={t("settings.addperson")}
checked={userSelfDetails.llm_settings?.add_person}
disabled={!userSelfDetails.llm_settings?.enabled}
onChange={event => {
setUserSelfDetails({
...userSelfDetails,
llm_settings: {
...userSelfDetails.llm_settings,
add_person: event.currentTarget.checked,
},
});
}}
/>
<Switch
label={t("settings.addlocation")}
checked={userSelfDetails.llm_settings?.add_location}
disabled={!userSelfDetails.llm_settings?.enabled}
onChange={event => {
setUserSelfDetails({
...userSelfDetails,
llm_settings: {
...userSelfDetails.llm_settings,
add_location: event.currentTarget.checked,
},
});
}}
/>
</Stack>
</Card>
<Space h="xl" />
</Stack>
<Dialog
Expand Down
30 changes: 29 additions & 1 deletion src/layouts/settings/SiteSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ const CAPTIONING_MODELS = [
{ value: "none", label: "None" },
];

const LLM_MODELS = [
{ value: "mistral-7b-v0.1.Q5_K_M", label: "Mistral 7B v0.1 Q5 K M" },
{ value: "none", label: "None" },
];

export function SiteSettings() {
const [skipPatterns, setSkipPatterns] = useState("");
const [mapApiKey, setMapApiKey] = useState("");
Expand All @@ -51,14 +56,14 @@ export function SiteSettings() {
const [allowRegistration, setAllowRegistration] = useState(false);
const [allowUpload, setAllowUpload] = useState(false);
const [captioningModel, setCaptioningModel] = useState("im2txt");
const [llmModel, setLlmModel] = useState("none");
const [warning, setWarning] = useState("none");
const { t } = useTranslation();
const { data: settings, isLoading } = useGetSettingsQuery();
const [saveSettings] = useUpdateSettingsMutation();
const [opened, { open, close }] = useDisclosure(false);

const saveSettingsWithValidation = (input: any) => {
console.log(input);
if (input.heavyweight_process && input.heavyweight_process > 3) {
setWarning("heavyweight");
open();
Expand All @@ -81,6 +86,7 @@ export function SiteSettings() {
setAllowRegistration(settings.allow_registration);
setAllowUpload(settings.allow_upload);
setCaptioningModel(settings.captioning_model);
setLlmModel(settings.llm_model);
}
}, [settings, isLoading]);

Expand Down Expand Up @@ -249,6 +255,28 @@ export function SiteSettings() {
}}
/>
</Grid.Col>
<Grid.Col span={8}>
<Stack spacing={0}>
<Text>{t("sitesettings.llm_model_header")}</Text>
<Text fz="sm" color="dimmed">
{t("sitesettings.llm_model_description")}
</Text>
</Stack>
</Grid.Col>
<Grid.Col span={4}>
<Select
searchable
withinPortal
data={LLM_MODELS}
dropdownPosition="bottom"
value={llmModel}
onChange={model => {
const value = model ?? "";
saveSettingsWithValidation({ llm_model: value });
setLlmModel(value);
}}
/>
</Grid.Col>
<Grid.Col span={8}>
<Stack spacing={0}>
<Text>{t("sitesettings.headerheavyweight")}</Text>
Expand Down
8 changes: 7 additions & 1 deletion src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@
"min_samples": "Minimum Samples",
"min_samples_help": "Changes how conservative clusters are. A smaller value means less conservative.",
"cluster_selection_epsilon": "Cluster Selection Epsilon",
"cluster_selection_epsilon_help": "Determines which clusters get merged. A higher value means more clusters will be merged."
"cluster_selection_epsilon_help": "Determines which clusters get merged. A higher value means more clusters will be merged.",
"llm": "Large Language Model Settings",
"enablellm": "Enable Large Language Model For Captions",
"addperson": "Add Persons to the Captions",
"addlocation": "Add Locations to the Captions"
},
"modalalbum": {
"title": "Add to Album",
Expand Down Expand Up @@ -453,6 +457,8 @@
"heavyweight": "Increase the number of picture-scanning workers beyond 1, but be prepared to use 800 MB memory for each additional one.",
"captioning_model_header": "Captioning Model",
"captioning_model_description": "Select a model for generating image captions.",
"llm_model_header": "Large Language Model",
"llm_model_description": "Select a model for postprocessing a caption with an large language model.",
"ram_warning_header": "Large RAM Size possible",
"heavyweight_process_warning": "Setting the number of heavyweight processes to more than 3 will likely require more than 16GB of RAM. Please consider this before proceeding.",
"blip_warning": "This feature needs an additional 3GBs of RAM to work properly. Please consider this before proceeding."
Expand Down
1 change: 1 addition & 0 deletions src/store/user/user.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const UserSchema = z.object({
min_cluster_size: z.number(),
min_samples: z.number(),
cluster_selection_epsilon: z.number(),
llm_settings: z.any().nullable(),
});

export const ManageUser = z.object({
Expand Down

0 comments on commit 029c22b

Please sign in to comment.