Fix: adjusted that only admin can download embedding/reranking models and user can select from already downloaded models

This commit is contained in:
weberm1 2025-05-21 12:25:44 +02:00
parent d1ed648680
commit d26c1f553b
2 changed files with 421 additions and 277 deletions

View File

@ -548,7 +548,7 @@
<div class=" mb-2.5 flex flex-col w-full">
<div class=" mb-1 text-xs font-medium">{$i18n.t('Embedding Model')}</div>
{#if $user?.role === 'admin'}
<div class="">
{#if embeddingEngine === 'ollama'}
<div class="flex w-full">
@ -631,7 +631,38 @@
</div>
{/if}
</div>
{/if}
<div class="flex w-full">
<div class="flex-1 mr-2">
<select
class="flex-1 w-full rounded-lg text-sm bg-transparent outline-hidden p-2 border border-gray-300"
bind:value={embeddingModel}
required
>
<option value="" disabled selected>{$i18n.t('Select embedding model')}</option>
<!-- Always show the current value first if it's not empty -->
{#if embeddingModel && embeddingModel.trim() !== ''}
<option value={embeddingModel} class="py-1 font-semibold">
{embeddingModel}
{#if embeddingEngine &&
RAGConfig.DOWNLOADED_EMBEDDING_MODELS[embeddingEngine] &&
!localRAGConfig.DOWNLOADED_EMBEDDING_MODELS[embeddingEngine]?.includes(embeddingModel)}
(custom)
{/if}
</option>
{/if}
<!-- Then show all downloaded models from the selected engine -->
{#if embeddingEngine && RAGConfig.DOWNLOADED_EMBEDDING_MODELS[embeddingEngine]}
{#each RAGConfig.DOWNLOADED_EMBEDDING_MODELS[embeddingEngine] as model}
{#if model !== embeddingModel} <!-- Skip the current model as it's already shown -->
<option value={model} class="py-1">{model}</option>
{/if}
{/each}
{/if}
</select>
</div>
</div>
<div class="mt-1 mb-1 text-xs text-gray-400 dark:text-gray-500">
{$i18n.t(
'Warning: If you update or change your embedding model, you will need to re-import all documents.'
@ -694,7 +725,7 @@
{#if RAGConfig.ENABLE_RAG_HYBRID_SEARCH === true}
<div class=" mb-2.5 flex flex-col w-full">
<div class=" mb-1 text-xs font-medium">{$i18n.t('Reranking Model')}</div>
{#if $user?.role === 'admin'}
<div class="">
<div class="flex w-full">
<div class="flex-1 mr-2">
@ -759,6 +790,37 @@
</svg>
{/if}
</button>
</div>
</div>
{/if}
<div class="flex w-full">
<div class="flex-1 mr-2">
<select
class="flex-1 w-full rounded-lg text-sm bg-transparent outline-hidden p-2 border border-gray-300"
bind:value={rerankingModel}
required
>
<option value="" disabled selected>{$i18n.t('Select reranking model')}</option>
<!-- Always show the current value first if it's not empty -->
{#if rerankingModel && rerankingModel.trim() !== ''}
<option value={rerankingModel} class="py-1 font-semibold">
{rerankingModel}
{#if !RAGConfig.DOWNLOADED_RERANKING_MODELS?.includes(embeddingModel)}
(custom)
{/if}
</option>
{/if}
<!-- Then show all downloaded models from the selected engine -->
{#if RAGConfig.DOWNLOADED_RERANKING_MODELS}
{#each RAGConfig.DOWNLOADED_RERANKING_MODELS as model}
{#if model !== rerankingModel} <!-- Skip the current model as it's already shown -->
<option value={model} class="py-1">{model}</option>
{/if}
{/each}
{/if}
</select>
</div>
</div>
</div>

View File

@ -232,6 +232,10 @@
openai_config,
ollama_config,
reranking_model,
LOADED_EMBEDDING_MODELS,
DOWNLOADED_EMBEDDING_MODELS,
LOADED_RERANKING_MODELS,
DOWNLOADED_RERANKING_MODELS,
...filteredRAGConfig
} = localRAGConfig;
@ -247,6 +251,16 @@
await rerankingModelUpdateHandler();
}
}
// Update embedding and reranking to show updates in UI
localRAGConfig.embedding_engine = embeddingEngine
localRAGConfig.embedding_model = embeddingModel
localRAGConfig.embedding_batch_size = embeddingBatchSize
localRAGConfig.openai_config = {"key": OpenAIKey, "url": OpenAIUrl}
localRAGConfig.ollama_config = {"key": OllamaKey, "url": OllamaUrl}
localRAGConfig.reranking_model = rerankingModel
console.log('RAGConfig:', localRAGConfig);
dispatch('update', localRAGConfig)
loading = false;
@ -489,7 +503,7 @@
<div class=" mb-2.5 flex flex-col w-full">
<div class=" mb-1 text-xs font-medium">{$i18n.t('Embedding Model')}</div>
{#if $user?.role === 'admin'}
<div class="">
{#if embeddingEngine === 'ollama'}
<div class="flex w-full">
@ -499,6 +513,8 @@
bind:value={embeddingModel}
placeholder={$i18n.t('Set embedding model')}
required
on:input={() => {
}}
/>
</div>
</div>
@ -511,6 +527,8 @@
model: embeddingModel.slice(-40)
})}
bind:value={embeddingModel}
on:input={() => {
}}
/>
</div>
@ -572,6 +590,39 @@
</div>
{/if}
</div>
{/if}
<div class="flex w-full">
<div class="flex-1 mr-2">
<select
class="flex-1 w-full rounded-lg text-sm bg-transparent outline-hidden p-2 border border-gray-300"
bind:value={embeddingModel}
required
>
<option value="" disabled selected>{$i18n.t('Select embedding model')}</option>
<!-- Always show the current value first if it's not empty -->
{#if embeddingModel && embeddingModel.trim() !== ''}
<option value={embeddingModel} class="py-1 font-semibold">
{embeddingModel}
{#if embeddingEngine &&
localRAGConfig.DOWNLOADED_EMBEDDING_MODELS[embeddingEngine] &&
!localRAGConfig.DOWNLOADED_EMBEDDING_MODELS[embeddingEngine]?.includes(embeddingModel)}
(custom)
{/if}
</option>
{/if}
<!-- Then show all downloaded models from the selected engine -->
{#if embeddingEngine && localRAGConfig.DOWNLOADED_EMBEDDING_MODELS[embeddingEngine]}
{#each localRAGConfig.DOWNLOADED_EMBEDDING_MODELS[embeddingEngine] as model}
{#if model !== embeddingModel} <!-- Skip the current model as it's already shown -->
<option value={model} class="py-1">{model}</option>
{/if}
{/each}
{/if}
</select>
</div>
</div>
<div class="mt-1 mb-1 text-xs text-gray-400 dark:text-gray-500">
{$i18n.t(
@ -580,6 +631,7 @@
</div>
</div>
{#if embeddingEngine === 'ollama' || embeddingEngine === 'openai'}
<div class=" mb-2.5 flex w-full justify-between">
<div class=" self-center text-xs font-medium">
@ -635,7 +687,7 @@
{#if localRAGConfig.ENABLE_RAG_HYBRID_SEARCH === true}
<div class=" mb-2.5 flex flex-col w-full">
<div class=" mb-1 text-xs font-medium">{$i18n.t('Reranking Model')}</div>
{#if $user?.role === 'admin'}
<div class="">
<div class="flex w-full">
<div class="flex-1 mr-2">
@ -702,6 +754,36 @@
</button>
</div>
</div>
{/if}
<div class="flex w-full">
<div class="flex-1 mr-2">
<select
class="flex-1 w-full rounded-lg text-sm bg-transparent outline-hidden p-2 border border-gray-300"
bind:value={rerankingModel}
required
>
<option value="" disabled selected>{$i18n.t('Select reranking model')}</option>
<!-- Always show the current value first if it's not empty -->
{#if rerankingModel && rerankingModel.trim() !== ''}
<option value={rerankingModel} class="py-1 font-semibold">
{rerankingModel}
{#if !localRAGConfig.DOWNLOADED_RERANKING_MODELS?.includes(embeddingModel)}
(custom)
{/if}
</option>
{/if}
<!-- Then show all downloaded models from the selected engine -->
{#if localRAGConfig.DOWNLOADED_RERANKING_MODELS}
{#each localRAGConfig.DOWNLOADED_RERANKING_MODELS as model}
{#if model !== rerankingModel} <!-- Skip the current model as it's already shown -->
<option value={model} class="py-1">{model}</option>
{/if}
{/each}
{/if}
</select>
</div>
</div>
</div>
{/if}