forked from open-webui/open-webui
		
	feat: rag apis added to frontend
This commit is contained in:
		
							parent
							
								
									cd86c36953
								
							
						
					
					
						commit
						3229ec116c
					
				
					 2 changed files with 109 additions and 0 deletions
				
			
		
							
								
								
									
										108
									
								
								src/lib/apis/rag/index.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										108
									
								
								src/lib/apis/rag/index.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,108 @@ | |||
| import { RAG_API_BASE_URL } from '$lib/constants'; | ||||
| 
 | ||||
| export const uploadDocToVectorDB = async (token: string, collection_name: string, file: File) => { | ||||
| 	const data = new FormData(); | ||||
| 	data.append('file', file); | ||||
| 	data.append('collection_name', collection_name); | ||||
| 
 | ||||
| 	let error = null; | ||||
| 
 | ||||
| 	const res = await fetch(`${RAG_API_BASE_URL}/doc`, { | ||||
| 		method: 'POST', | ||||
| 		headers: { | ||||
| 			Accept: 'application/json', | ||||
| 			'Content-Type': 'application/json', | ||||
| 			authorization: `Bearer ${token}` | ||||
| 		}, | ||||
| 		body: data | ||||
| 	}) | ||||
| 		.then(async (res) => { | ||||
| 			if (!res.ok) throw await res.json(); | ||||
| 			return res.json(); | ||||
| 		}) | ||||
| 		.catch((err) => { | ||||
| 			error = err.detail; | ||||
| 			console.log(err); | ||||
| 			return null; | ||||
| 		}); | ||||
| 
 | ||||
| 	if (error) { | ||||
| 		throw error; | ||||
| 	} | ||||
| 
 | ||||
| 	return res; | ||||
| }; | ||||
| 
 | ||||
| export const uploadWebToVectorDB = async (token: string, collection_name: string, url: string) => { | ||||
| 	let error = null; | ||||
| 
 | ||||
| 	const res = await fetch(`${RAG_API_BASE_URL}/web`, { | ||||
| 		method: 'POST', | ||||
| 		headers: { | ||||
| 			Accept: 'application/json', | ||||
| 			'Content-Type': 'application/json', | ||||
| 			authorization: `Bearer ${token}` | ||||
| 		}, | ||||
| 		body: JSON.stringify({ | ||||
| 			url: url, | ||||
| 			collection_name: collection_name | ||||
| 		}) | ||||
| 	}) | ||||
| 		.then(async (res) => { | ||||
| 			if (!res.ok) throw await res.json(); | ||||
| 			return res.json(); | ||||
| 		}) | ||||
| 		.catch((err) => { | ||||
| 			error = err.detail; | ||||
| 			console.log(err); | ||||
| 			return null; | ||||
| 		}); | ||||
| 
 | ||||
| 	if (error) { | ||||
| 		throw error; | ||||
| 	} | ||||
| 
 | ||||
| 	return res; | ||||
| }; | ||||
| 
 | ||||
| export const queryVectorDB = async ( | ||||
| 	token: string, | ||||
| 	collection_name: string, | ||||
| 	query: string, | ||||
| 	k: number | ||||
| ) => { | ||||
| 	let error = null; | ||||
| 	const searchParams = new URLSearchParams(); | ||||
| 
 | ||||
| 	searchParams.set('query', query); | ||||
| 	if (k) { | ||||
| 		searchParams.set('k', k.toString()); | ||||
| 	} | ||||
| 
 | ||||
| 	const res = await fetch( | ||||
| 		`${RAG_API_BASE_URL}/query/${collection_name}/?${searchParams.toString()}`, | ||||
| 		{ | ||||
| 			method: 'GET', | ||||
| 			headers: { | ||||
| 				Accept: 'application/json', | ||||
| 				'Content-Type': 'application/json', | ||||
| 				authorization: `Bearer ${token}` | ||||
| 			} | ||||
| 		} | ||||
| 	) | ||||
| 		.then(async (res) => { | ||||
| 			if (!res.ok) throw await res.json(); | ||||
| 			return res.json(); | ||||
| 		}) | ||||
| 		.catch((err) => { | ||||
| 			error = err.detail; | ||||
| 			console.log(err); | ||||
| 			return null; | ||||
| 		}); | ||||
| 
 | ||||
| 	if (error) { | ||||
| 		throw error; | ||||
| 	} | ||||
| 
 | ||||
| 	return res; | ||||
| }; | ||||
|  | @ -5,6 +5,7 @@ export const WEBUI_BASE_URL = dev ? `http://${location.hostname}:8080` : ``; | |||
| export const WEBUI_API_BASE_URL = `${WEBUI_BASE_URL}/api/v1`; | ||||
| export const OLLAMA_API_BASE_URL = `${WEBUI_BASE_URL}/ollama/api`; | ||||
| export const OPENAI_API_BASE_URL = `${WEBUI_BASE_URL}/openai/api`; | ||||
| export const RAG_API_BASE_URL = `${WEBUI_BASE_URL}/rag/api/v1`; | ||||
| 
 | ||||
| export const WEB_UI_VERSION = 'v1.0.0-alpha-static'; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy J. Baek
						Timothy J. Baek