forked from open-webui/open-webui
		
	feat: editable rag template
This commit is contained in:
		
							parent
							
								
									ccf08fb91e
								
							
						
					
					
						commit
						5270efa9e5
					
				
					 6 changed files with 122 additions and 16 deletions
				
			
		|  | @ -58,6 +58,63 @@ export const updateChunkParams = async (token: string, size: number, overlap: nu | |||
| 	return res; | ||||
| }; | ||||
| 
 | ||||
| export const getRAGTemplate = async (token: string) => { | ||||
| 	let error = null; | ||||
| 
 | ||||
| 	const res = await fetch(`${RAG_API_BASE_URL}/template`, { | ||||
| 		method: 'GET', | ||||
| 		headers: { | ||||
| 			'Content-Type': 'application/json', | ||||
| 			Authorization: `Bearer ${token}` | ||||
| 		} | ||||
| 	}) | ||||
| 		.then(async (res) => { | ||||
| 			if (!res.ok) throw await res.json(); | ||||
| 			return res.json(); | ||||
| 		}) | ||||
| 		.catch((err) => { | ||||
| 			console.log(err); | ||||
| 			error = err.detail; | ||||
| 			return null; | ||||
| 		}); | ||||
| 
 | ||||
| 	if (error) { | ||||
| 		throw error; | ||||
| 	} | ||||
| 
 | ||||
| 	return res; | ||||
| }; | ||||
| 
 | ||||
| export const updateRAGTemplate = async (token: string, template: string) => { | ||||
| 	let error = null; | ||||
| 
 | ||||
| 	const res = await fetch(`${RAG_API_BASE_URL}/template/update`, { | ||||
| 		method: 'POST', | ||||
| 		headers: { | ||||
| 			'Content-Type': 'application/json', | ||||
| 			Authorization: `Bearer ${token}` | ||||
| 		}, | ||||
| 		body: JSON.stringify({ | ||||
| 			template: template | ||||
| 		}) | ||||
| 	}) | ||||
| 		.then(async (res) => { | ||||
| 			if (!res.ok) throw await res.json(); | ||||
| 			return res.json(); | ||||
| 		}) | ||||
| 		.catch((err) => { | ||||
| 			console.log(err); | ||||
| 			error = err.detail; | ||||
| 			return null; | ||||
| 		}); | ||||
| 
 | ||||
| 	if (error) { | ||||
| 		throw error; | ||||
| 	} | ||||
| 
 | ||||
| 	return res; | ||||
| }; | ||||
| 
 | ||||
| export const uploadDocToVectorDB = async (token: string, collection_name: string, file: File) => { | ||||
| 	const data = new FormData(); | ||||
| 	data.append('file', file); | ||||
|  |  | |||
|  | @ -1,17 +1,21 @@ | |||
| export const RAGTemplate = (context: string, query: string) => { | ||||
| 	let template = `Use the following context as your learned knowledge, inside <context></context> XML tags.
 | ||||
| 	<context> | ||||
| 	  [context] | ||||
| 	</context> | ||||
| 	 | ||||
| 	When answer to user: | ||||
| 	- If you don't know, just say that you don't know. | ||||
| 	- If you don't know when you are not sure, ask for clarification. | ||||
| 	Avoid mentioning that you obtained the information from the context. | ||||
| 	And answer according to the language of the user's question. | ||||
| 			 | ||||
| 	Given the context information, answer the query. | ||||
| 	Query: [query]`;
 | ||||
| import { getRAGTemplate } from '$lib/apis/rag'; | ||||
| 
 | ||||
| export const RAGTemplate = async (token: string, context: string, query: string) => { | ||||
| 	let template = await getRAGTemplate(token).catch(() => { | ||||
| 		return `Use the following context as your learned knowledge, inside <context></context> XML tags.
 | ||||
| 		<context> | ||||
| 		  [context] | ||||
| 		</context> | ||||
| 		 | ||||
| 		When answer to user: | ||||
| 		- If you don't know, just say that you don't know. | ||||
| 		- If you don't know when you are not sure, ask for clarification. | ||||
| 		Avoid mentioning that you obtained the information from the context. | ||||
| 		And answer according to the language of the user's question. | ||||
| 				 | ||||
| 		Given the context information, answer the query. | ||||
| 		Query: [query]`;
 | ||||
| 	}); | ||||
| 
 | ||||
| 	template = template.replace(/\[context\]/g, context); | ||||
| 	template = template.replace(/\[query\]/g, query); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy J. Baek
						Timothy J. Baek