forked from open-webui/open-webui
		
	Merge branch 'main' into multimodal
This commit is contained in:
		
						commit
						fb1f8b167c
					
				
					 3 changed files with 190 additions and 115 deletions
				
			
		|  | @ -158,82 +158,107 @@ | |||
| 				}, | ||||
| 				format: $settings.requestFormat ?? undefined | ||||
| 			}) | ||||
| 		}).catch((err) => { | ||||
| 			console.log(err); | ||||
| 			return null; | ||||
| 		}); | ||||
| 
 | ||||
| 		const reader = res.body | ||||
| 			.pipeThrough(new TextDecoderStream()) | ||||
| 			.pipeThrough(splitStream('\n')) | ||||
| 			.getReader(); | ||||
| 		if (res && res.ok) { | ||||
| 			const reader = res.body | ||||
| 				.pipeThrough(new TextDecoderStream()) | ||||
| 				.pipeThrough(splitStream('\n')) | ||||
| 				.getReader(); | ||||
| 
 | ||||
| 		while (true) { | ||||
| 			const { value, done } = await reader.read(); | ||||
| 			if (done || stopResponseFlag || _chatId !== $chatId) { | ||||
| 				responseMessage.done = true; | ||||
| 				messages = messages; | ||||
| 				break; | ||||
| 			} | ||||
| 			while (true) { | ||||
| 				const { value, done } = await reader.read(); | ||||
| 				if (done || stopResponseFlag || _chatId !== $chatId) { | ||||
| 					responseMessage.done = true; | ||||
| 					messages = messages; | ||||
| 					break; | ||||
| 				} | ||||
| 
 | ||||
| 			try { | ||||
| 				let lines = value.split('\n'); | ||||
| 				try { | ||||
| 					let lines = value.split('\n'); | ||||
| 
 | ||||
| 				for (const line of lines) { | ||||
| 					if (line !== '') { | ||||
| 						console.log(line); | ||||
| 						let data = JSON.parse(line); | ||||
| 					for (const line of lines) { | ||||
| 						if (line !== '') { | ||||
| 							console.log(line); | ||||
| 							let data = JSON.parse(line); | ||||
| 
 | ||||
| 						if ('detail' in data) { | ||||
| 							throw data; | ||||
| 						} | ||||
| 							if ('detail' in data) { | ||||
| 								throw data; | ||||
| 							} | ||||
| 
 | ||||
| 						if (data.done == false) { | ||||
| 							if (responseMessage.content == '' && data.message.content == '\n') { | ||||
| 								continue; | ||||
| 							if (data.done == false) { | ||||
| 								if (responseMessage.content == '' && data.message.content == '\n') { | ||||
| 									continue; | ||||
| 								} else { | ||||
| 									responseMessage.content += data.message.content; | ||||
| 									messages = messages; | ||||
| 								} | ||||
| 							} else { | ||||
| 								responseMessage.content += data.message.content; | ||||
| 								responseMessage.done = true; | ||||
| 								responseMessage.context = data.context ?? null; | ||||
| 								responseMessage.info = { | ||||
| 									total_duration: data.total_duration, | ||||
| 									prompt_eval_count: data.prompt_eval_count, | ||||
| 									prompt_eval_duration: data.prompt_eval_duration, | ||||
| 									eval_count: data.eval_count, | ||||
| 									eval_duration: data.eval_duration | ||||
| 								}; | ||||
| 								messages = messages; | ||||
| 							} | ||||
| 						} else { | ||||
| 							responseMessage.done = true; | ||||
| 							responseMessage.context = data.context ?? null; | ||||
| 							responseMessage.info = { | ||||
| 								total_duration: data.total_duration, | ||||
| 								prompt_eval_count: data.prompt_eval_count, | ||||
| 								prompt_eval_duration: data.prompt_eval_duration, | ||||
| 								eval_count: data.eval_count, | ||||
| 								eval_duration: data.eval_duration | ||||
| 							}; | ||||
| 							messages = messages; | ||||
| 						} | ||||
| 					} | ||||
| 				} catch (error) { | ||||
| 					console.log(error); | ||||
| 					if ('detail' in error) { | ||||
| 						toast.error(error.detail); | ||||
| 					} | ||||
| 					break; | ||||
| 				} | ||||
| 			} catch (error) { | ||||
| 
 | ||||
| 				if (autoScroll) { | ||||
| 					window.scrollTo({ top: document.body.scrollHeight }); | ||||
| 				} | ||||
| 
 | ||||
| 				await $db.updateChatById(_chatId, { | ||||
| 					title: title === '' ? 'New Chat' : title, | ||||
| 					models: selectedModels, | ||||
| 					system: $settings.system ?? undefined, | ||||
| 					options: { | ||||
| 						seed: $settings.seed ?? undefined, | ||||
| 						temperature: $settings.temperature ?? undefined, | ||||
| 						repeat_penalty: $settings.repeat_penalty ?? undefined, | ||||
| 						top_k: $settings.top_k ?? undefined, | ||||
| 						top_p: $settings.top_p ?? undefined, | ||||
| 						num_ctx: $settings.num_ctx ?? undefined, | ||||
| 						...($settings.options ?? {}) | ||||
| 					}, | ||||
| 					messages: messages, | ||||
| 					history: history | ||||
| 				}); | ||||
| 			} | ||||
| 		} else { | ||||
| 			if (res !== null) { | ||||
| 				const error = await res.json(); | ||||
| 				console.log(error); | ||||
| 				if ('detail' in error) { | ||||
| 					toast.error(error.detail); | ||||
| 					responseMessage.content = error.detail; | ||||
| 				} else { | ||||
| 					toast.error(error.error); | ||||
| 					responseMessage.content = error.error; | ||||
| 				} | ||||
| 				break; | ||||
| 			} else { | ||||
| 				toast.error(`Uh-oh! There was an issue connecting to Ollama.`); | ||||
| 				responseMessage.content = `Uh-oh! There was an issue connecting to Ollama.`; | ||||
| 			} | ||||
| 
 | ||||
| 			if (autoScroll) { | ||||
| 				window.scrollTo({ top: document.body.scrollHeight }); | ||||
| 			} | ||||
| 
 | ||||
| 			await $db.updateChatById(_chatId, { | ||||
| 				title: title === '' ? 'New Chat' : title, | ||||
| 				models: selectedModels, | ||||
| 				system: $settings.system ?? undefined, | ||||
| 				options: { | ||||
| 					seed: $settings.seed ?? undefined, | ||||
| 					temperature: $settings.temperature ?? undefined, | ||||
| 					repeat_penalty: $settings.repeat_penalty ?? undefined, | ||||
| 					top_k: $settings.top_k ?? undefined, | ||||
| 					top_p: $settings.top_p ?? undefined, | ||||
| 					num_ctx: $settings.num_ctx ?? undefined, | ||||
| 					...($settings.options ?? {}) | ||||
| 				}, | ||||
| 				messages: messages, | ||||
| 				history: history | ||||
| 			}); | ||||
| 			responseMessage.error = true; | ||||
| 			responseMessage.content = `Uh-oh! There was an issue connecting to Ollama.`; | ||||
| 			responseMessage.done = true; | ||||
| 			messages = messages; | ||||
| 		} | ||||
| 
 | ||||
| 		stopResponseFlag = false; | ||||
|  |  | |||
|  | @ -185,82 +185,107 @@ | |||
| 				}, | ||||
| 				format: $settings.requestFormat ?? undefined | ||||
| 			}) | ||||
| 		}).catch((err) => { | ||||
| 			console.log(err); | ||||
| 			return null; | ||||
| 		}); | ||||
| 
 | ||||
| 		const reader = res.body | ||||
| 			.pipeThrough(new TextDecoderStream()) | ||||
| 			.pipeThrough(splitStream('\n')) | ||||
| 			.getReader(); | ||||
| 		if (res && res.ok) { | ||||
| 			const reader = res.body | ||||
| 				.pipeThrough(new TextDecoderStream()) | ||||
| 				.pipeThrough(splitStream('\n')) | ||||
| 				.getReader(); | ||||
| 
 | ||||
| 		while (true) { | ||||
| 			const { value, done } = await reader.read(); | ||||
| 			if (done || stopResponseFlag || _chatId !== $chatId) { | ||||
| 				responseMessage.done = true; | ||||
| 				messages = messages; | ||||
| 				break; | ||||
| 			} | ||||
| 			while (true) { | ||||
| 				const { value, done } = await reader.read(); | ||||
| 				if (done || stopResponseFlag || _chatId !== $chatId) { | ||||
| 					responseMessage.done = true; | ||||
| 					messages = messages; | ||||
| 					break; | ||||
| 				} | ||||
| 
 | ||||
| 			try { | ||||
| 				let lines = value.split('\n'); | ||||
| 				try { | ||||
| 					let lines = value.split('\n'); | ||||
| 
 | ||||
| 				for (const line of lines) { | ||||
| 					if (line !== '') { | ||||
| 						console.log(line); | ||||
| 						let data = JSON.parse(line); | ||||
| 					for (const line of lines) { | ||||
| 						if (line !== '') { | ||||
| 							console.log(line); | ||||
| 							let data = JSON.parse(line); | ||||
| 
 | ||||
| 						if ('detail' in data) { | ||||
| 							throw data; | ||||
| 						} | ||||
| 							if ('detail' in data) { | ||||
| 								throw data; | ||||
| 							} | ||||
| 
 | ||||
| 						if (data.done == false) { | ||||
| 							if (responseMessage.content == '' && data.message.content == '\n') { | ||||
| 								continue; | ||||
| 							if (data.done == false) { | ||||
| 								if (responseMessage.content == '' && data.message.content == '\n') { | ||||
| 									continue; | ||||
| 								} else { | ||||
| 									responseMessage.content += data.message.content; | ||||
| 									messages = messages; | ||||
| 								} | ||||
| 							} else { | ||||
| 								responseMessage.content += data.message.content; | ||||
| 								responseMessage.done = true; | ||||
| 								responseMessage.context = data.context ?? null; | ||||
| 								responseMessage.info = { | ||||
| 									total_duration: data.total_duration, | ||||
| 									prompt_eval_count: data.prompt_eval_count, | ||||
| 									prompt_eval_duration: data.prompt_eval_duration, | ||||
| 									eval_count: data.eval_count, | ||||
| 									eval_duration: data.eval_duration | ||||
| 								}; | ||||
| 								messages = messages; | ||||
| 							} | ||||
| 						} else { | ||||
| 							responseMessage.done = true; | ||||
| 							responseMessage.context = data.context ?? null; | ||||
| 							responseMessage.info = { | ||||
| 								total_duration: data.total_duration, | ||||
| 								prompt_eval_count: data.prompt_eval_count, | ||||
| 								prompt_eval_duration: data.prompt_eval_duration, | ||||
| 								eval_count: data.eval_count, | ||||
| 								eval_duration: data.eval_duration | ||||
| 							}; | ||||
| 							messages = messages; | ||||
| 						} | ||||
| 					} | ||||
| 				} catch (error) { | ||||
| 					console.log(error); | ||||
| 					if ('detail' in error) { | ||||
| 						toast.error(error.detail); | ||||
| 					} | ||||
| 					break; | ||||
| 				} | ||||
| 			} catch (error) { | ||||
| 
 | ||||
| 				if (autoScroll) { | ||||
| 					window.scrollTo({ top: document.body.scrollHeight }); | ||||
| 				} | ||||
| 
 | ||||
| 				await $db.updateChatById(_chatId, { | ||||
| 					title: title === '' ? 'New Chat' : title, | ||||
| 					models: selectedModels, | ||||
| 					system: $settings.system ?? undefined, | ||||
| 					options: { | ||||
| 						seed: $settings.seed ?? undefined, | ||||
| 						temperature: $settings.temperature ?? undefined, | ||||
| 						repeat_penalty: $settings.repeat_penalty ?? undefined, | ||||
| 						top_k: $settings.top_k ?? undefined, | ||||
| 						top_p: $settings.top_p ?? undefined, | ||||
| 						num_ctx: $settings.num_ctx ?? undefined, | ||||
| 						...($settings.options ?? {}) | ||||
| 					}, | ||||
| 					messages: messages, | ||||
| 					history: history | ||||
| 				}); | ||||
| 			} | ||||
| 		} else { | ||||
| 			if (res !== null) { | ||||
| 				const error = await res.json(); | ||||
| 				console.log(error); | ||||
| 				if ('detail' in error) { | ||||
| 					toast.error(error.detail); | ||||
| 					responseMessage.content = error.detail; | ||||
| 				} else { | ||||
| 					toast.error(error.error); | ||||
| 					responseMessage.content = error.error; | ||||
| 				} | ||||
| 				break; | ||||
| 			} else { | ||||
| 				toast.error(`Uh-oh! There was an issue connecting to Ollama.`); | ||||
| 				responseMessage.content = `Uh-oh! There was an issue connecting to Ollama.`; | ||||
| 			} | ||||
| 
 | ||||
| 			if (autoScroll) { | ||||
| 				window.scrollTo({ top: document.body.scrollHeight }); | ||||
| 			} | ||||
| 
 | ||||
| 			await $db.updateChatById(_chatId, { | ||||
| 				title: title === '' ? 'New Chat' : title, | ||||
| 				models: selectedModels, | ||||
| 				system: $settings.system ?? undefined, | ||||
| 				options: { | ||||
| 					seed: $settings.seed ?? undefined, | ||||
| 					temperature: $settings.temperature ?? undefined, | ||||
| 					repeat_penalty: $settings.repeat_penalty ?? undefined, | ||||
| 					top_k: $settings.top_k ?? undefined, | ||||
| 					top_p: $settings.top_p ?? undefined, | ||||
| 					num_ctx: $settings.num_ctx ?? undefined, | ||||
| 					...($settings.options ?? {}) | ||||
| 				}, | ||||
| 				messages: messages, | ||||
| 				history: history | ||||
| 			}); | ||||
| 			responseMessage.error = true; | ||||
| 			responseMessage.content = `Uh-oh! There was an issue connecting to Ollama.`; | ||||
| 			responseMessage.done = true; | ||||
| 			messages = messages; | ||||
| 		} | ||||
| 
 | ||||
| 		stopResponseFlag = false; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy Jaeryang Baek
						Timothy Jaeryang Baek