forked from open-webui/open-webui
		
	feat: chat export
This commit is contained in:
		
							parent
							
								
									a2b1e3756b
								
							
						
					
					
						commit
						4221594778
					
				
					 5 changed files with 81 additions and 11 deletions
				
			
		|  | @ -62,6 +62,37 @@ export const getChatList = async (token: string = '') => { | |||
| 	return res; | ||||
| }; | ||||
| 
 | ||||
| export const getAllChats = async (token: string) => { | ||||
| 	let error = null; | ||||
| 
 | ||||
| 	const res = await fetch(`${WEBUI_API_BASE_URL}/chats/all`, { | ||||
| 		method: 'GET', | ||||
| 		headers: { | ||||
| 			Accept: 'application/json', | ||||
| 			'Content-Type': 'application/json', | ||||
| 			...(token && { authorization: `Bearer ${token}` }) | ||||
| 		} | ||||
| 	}) | ||||
| 		.then(async (res) => { | ||||
| 			if (!res.ok) throw await res.json(); | ||||
| 			return res.json(); | ||||
| 		}) | ||||
| 		.then((json) => { | ||||
| 			return json; | ||||
| 		}) | ||||
| 		.catch((err) => { | ||||
| 			error = err; | ||||
| 			console.log(err); | ||||
| 			return null; | ||||
| 		}); | ||||
| 
 | ||||
| 	if (error) { | ||||
| 		throw error; | ||||
| 	} | ||||
| 
 | ||||
| 	return res; | ||||
| }; | ||||
| 
 | ||||
| export const getChatById = async (token: string, id: string) => { | ||||
| 	let error = null; | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,20 +1,23 @@ | |||
| <script lang="ts"> | ||||
| 	import Modal from '../common/Modal.svelte'; | ||||
| 	import toast from 'svelte-french-toast'; | ||||
| 	import fileSaver from 'file-saver'; | ||||
| 	const { saveAs } = fileSaver; | ||||
| 
 | ||||
| 	import { onMount } from 'svelte'; | ||||
| 	import { config, models, settings, user, chats } from '$lib/stores'; | ||||
| 	import { splitStream, getGravatarURL } from '$lib/utils'; | ||||
| 
 | ||||
| 	import { getOllamaVersion } from '$lib/apis/ollama'; | ||||
| 	import { createNewChat, getAllChats, getChatList } from '$lib/apis/chats'; | ||||
| 	import { | ||||
| 		WEB_UI_VERSION, | ||||
| 		OLLAMA_API_BASE_URL, | ||||
| 		WEBUI_API_BASE_URL, | ||||
| 		WEBUI_BASE_URL | ||||
| 	} from '$lib/constants'; | ||||
| 	import toast from 'svelte-french-toast'; | ||||
| 	import { onMount } from 'svelte'; | ||||
| 	import { config, models, settings, user, chats } from '$lib/stores'; | ||||
| 	import { splitStream, getGravatarURL } from '$lib/utils'; | ||||
| 
 | ||||
| 	import Advanced from './Settings/Advanced.svelte'; | ||||
| 	import { stringify } from 'postcss'; | ||||
| 	import { getOllamaVersion } from '$lib/apis/ollama'; | ||||
| 	import { createNewChat, getChatList } from '$lib/apis/chats'; | ||||
| 	import Modal from '../common/Modal.svelte'; | ||||
| 
 | ||||
| 	export let show = false; | ||||
| 
 | ||||
|  | @ -91,7 +94,10 @@ | |||
| 	}; | ||||
| 
 | ||||
| 	const exportChats = async () => { | ||||
| 		console.log('TODO: export all chats'); | ||||
| 		let blob = new Blob([JSON.stringify(await getAllChats(localStorage.token))], { | ||||
| 			type: 'application/json' | ||||
| 		}); | ||||
| 		saveAs(blob, `chat-export-${Date.now()}.json`); | ||||
| 	}; | ||||
| 
 | ||||
| 	$: if (importFiles) { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy J. Baek
						Timothy J. Baek