forked from open-webui/open-webui
		
	feat: chat import to backend added
This commit is contained in:
		
							parent
							
								
									cc9e299814
								
							
						
					
					
						commit
						a696698ac8
					
				
					 6 changed files with 248 additions and 176 deletions
				
			
		|  | @ -1,8 +1,12 @@ | |||
| <script lang="ts"> | ||||
| 	import toast from 'svelte-french-toast'; | ||||
| 	import { openDB } from 'idb'; | ||||
| 	import { onMount, tick } from 'svelte'; | ||||
| 	import { goto } from '$app/navigation'; | ||||
| 
 | ||||
| 	import fileSaver from 'file-saver'; | ||||
| 	const { saveAs } = fileSaver; | ||||
| 
 | ||||
| 	import { getOllamaModels, getOllamaVersion } from '$lib/apis/ollama'; | ||||
| 	import { getOpenAIModels } from '$lib/apis/openai'; | ||||
| 
 | ||||
|  | @ -65,6 +69,21 @@ | |||
| 		if ($user === undefined) { | ||||
| 			await goto('/auth'); | ||||
| 		} else if (['user', 'admin'].includes($user.role)) { | ||||
| 			const DB = await openDB('Chats', 1); | ||||
| 
 | ||||
| 			if (DB) { | ||||
| 				let chats = await DB.getAllFromIndex('chats', 'timestamp'); | ||||
| 				chats = chats.map((item, idx) => chats[chats.length - 1 - idx]); | ||||
| 
 | ||||
| 				if (chats.length > 0) { | ||||
| 					let blob = new Blob([JSON.stringify(chats)], { type: 'application/json' }); | ||||
| 					saveAs(blob, `chat-export-${Date.now()}.json`); | ||||
| 				} | ||||
| 			} | ||||
| 
 | ||||
| 			console.log(DB); | ||||
| 
 | ||||
| 			console.log(); | ||||
| 			await settings.set(JSON.parse(localStorage.getItem('settings') ?? '{}')); | ||||
| 			await models.set(await getModels()); | ||||
| 
 | ||||
|  |  | |||
|  | @ -2,18 +2,21 @@ | |||
| 	import { v4 as uuidv4 } from 'uuid'; | ||||
| 	import toast from 'svelte-french-toast'; | ||||
| 
 | ||||
| 	import { OLLAMA_API_BASE_URL } from '$lib/constants'; | ||||
| 	import { onMount, tick } from 'svelte'; | ||||
| 	import { convertMessagesToHistory, copyToClipboard, splitStream } from '$lib/utils'; | ||||
| 	import { goto } from '$app/navigation'; | ||||
| 	import { config, models, modelfiles, user, settings, db, chats, chatId } from '$lib/stores'; | ||||
| 	import { page } from '$app/stores'; | ||||
| 
 | ||||
| 	import { models, modelfiles, user, settings, db, chats, chatId } from '$lib/stores'; | ||||
| 	import { OLLAMA_API_BASE_URL } from '$lib/constants'; | ||||
| 
 | ||||
| 	import { generateChatCompletion, generateTitle } from '$lib/apis/ollama'; | ||||
| 	import { copyToClipboard, splitStream } from '$lib/utils'; | ||||
| 
 | ||||
| 	import MessageInput from '$lib/components/chat/MessageInput.svelte'; | ||||
| 	import Messages from '$lib/components/chat/Messages.svelte'; | ||||
| 	import ModelSelector from '$lib/components/chat/ModelSelector.svelte'; | ||||
| 	import Navbar from '$lib/components/layout/Navbar.svelte'; | ||||
| 	import { page } from '$app/stores'; | ||||
| 	import { createNewChat, getChatById, getChatList } from '$lib/apis/chats'; | ||||
| 	import { createNewChat, getChatById, getChatList, updateChatById } from '$lib/apis/chats'; | ||||
| 
 | ||||
| 	let loaded = false; | ||||
| 	let stopResponseFlag = false; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy J. Baek
						Timothy J. Baek