This commit is contained in:
Athanasios Oikonomou 2025-12-09 08:56:54 +01:00 committed by GitHub
commit 4c23243ace
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 4 deletions

View file

@ -1550,10 +1550,15 @@ async def process_chat_payload(request, form_data, user, metadata, model):
if prompt is None: if prompt is None:
raise Exception("No user message found") raise Exception("No user message found")
model_rag_template = (
model.get("info", {}).get("params", {}).get("rag_template", "")
or request.app.state.config.RAG_TEMPLATE
)
if context_string != "": if context_string != "":
form_data["messages"] = add_or_update_user_message( form_data["messages"] = add_or_update_user_message(
rag_template( rag_template(
request.app.state.config.RAG_TEMPLATE, model_rag_template,
context_string, context_string,
prompt, prompt,
), ),

View file

@ -67,6 +67,7 @@
} }
let system = ''; let system = '';
let rag_template = '';
let info = { let info = {
id: '', id: '',
base_model_id: null, base_model_id: null,
@ -78,12 +79,14 @@
tags: [] tags: []
}, },
params: { params: {
system: '' system: '',
rag_template: ''
} }
}; };
let params = { let params: {
system: '' system: '';
rag_template: '';
}; };
let knowledge = []; let knowledge = [];
@ -207,6 +210,7 @@
} }
info.params.system = system.trim() === '' ? null : system; info.params.system = system.trim() === '' ? null : system;
info.params.rag_template = rag_template.trim() === '' ? null : rag_template;
info.params.stop = params.stop ? params.stop.split(',').filter((s) => s.trim()) : null; info.params.stop = params.stop ? params.stop.split(',').filter((s) => s.trim()) : null;
Object.keys(info.params).forEach((key) => { Object.keys(info.params).forEach((key) => {
if (info.params[key] === '' || info.params[key] === null) { if (info.params[key] === '' || info.params[key] === null) {
@ -254,6 +258,7 @@
} }
system = model?.params?.system ?? ''; system = model?.params?.system ?? '';
rag_template = model?.params?.rag_template ?? '';
params = { ...params, ...model?.params }; params = { ...params, ...model?.params };
params.stop = params?.stop params.stop = params?.stop
@ -644,6 +649,18 @@
</div> </div>
</div> </div>
<div class="my-1">
<div class=" text-xs font-semibold mb-2">{$i18n.t('RAG Template')}</div>
<div>
<Textarea
placeholder={$i18n.t(
'Leave empty to use the default prompt, or enter a custom prompt'
)}
bind:value={rag_template}
/>
</div>
</div>
<div class="flex w-full justify-between"> <div class="flex w-full justify-between">
<div class=" self-center text-xs font-medium"> <div class=" self-center text-xs font-medium">
{$i18n.t('Advanced Params')} {$i18n.t('Advanced Params')}