feat: duplicate tag name prevention

This commit is contained in:
Timothy J. Baek 2023-12-03 22:21:17 -08:00
parent ab5e7abffd
commit 6df1b197aa
2 changed files with 23 additions and 3 deletions

View File

@ -3,7 +3,7 @@
import { toast } from 'svelte-french-toast'; import { toast } from 'svelte-french-toast';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { OLLAMA_API_BASE_URL } from '$lib/constants'; import { OLLAMA_API_BASE_URL } from '$lib/constants';
import { settings, db, user, config, modelfiles } from '$lib/stores'; import { settings, db, user, config, modelfiles, models } from '$lib/stores';
import Advanced from '$lib/components/chat/Settings/Advanced.svelte'; import Advanced from '$lib/components/chat/Settings/Advanced.svelte';
import { splitStream } from '$lib/utils'; import { splitStream } from '$lib/utils';
@ -101,13 +101,26 @@ SYSTEM """${system}"""`.replace(/^\s*\n/gm, '');
toast.error( toast.error(
'Uh-oh! It looks like you missed selecting a category. Please choose one to complete your modelfile.' 'Uh-oh! It looks like you missed selecting a category. Please choose one to complete your modelfile.'
); );
loading = false;
success = false;
return success;
}
if ($models.includes(tagName)) {
toast.error(
`Uh-oh! It looks like you already have a model named '${tagName}'. Please choose a different name to complete your modelfile.`
);
loading = false;
success = false;
return success;
} }
if ( if (
title !== '' && title !== '' &&
desc !== '' && desc !== '' &&
content !== '' && content !== '' &&
Object.keys(categories).filter((category) => categories[category]).length > 0 Object.keys(categories).filter((category) => categories[category]).length > 0 &&
!$models.includes(tagName)
) { ) {
const res = await fetch(`${$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL}/create`, { const res = await fetch(`${$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL}/create`, {
method: 'POST', method: 'POST',

View File

@ -60,7 +60,14 @@
title = modelfile.title; title = modelfile.title;
desc = modelfile.desc; desc = modelfile.desc;
content = modelfile.content; content = modelfile.content;
suggestions = modelfile.suggestionPrompts; suggestions =
modelfile.suggestionPrompts.length != 0
? modelfile.suggestionPrompts
: [
{
content: ''
}
];
for (const category of modelfile.categories) { for (const category of modelfile.categories) {
categories[category.toLowerCase()] = true; categories[category.toLowerCase()] = true;