forked from open-webui/open-webui
		
	Merge pull request #70 from ollama-webui/dev
fix: ollama custom url support
This commit is contained in:
		
						commit
						9a6919331a
					
				
					 2 changed files with 38 additions and 33 deletions
				
			
		|  | @ -65,7 +65,7 @@ | ||||||
| 		if (API_BASE_URL === '') { | 		if (API_BASE_URL === '') { | ||||||
| 			API_BASE_URL = BUILD_TIME_API_BASE_URL; | 			API_BASE_URL = BUILD_TIME_API_BASE_URL; | ||||||
| 		} | 		} | ||||||
| 		const res = await getModelTags(API_BASE_URL); | 		const res = await getModelTags(API_BASE_URL, 'ollama'); | ||||||
| 
 | 
 | ||||||
| 		if (res) { | 		if (res) { | ||||||
| 			toast.success('Server connection verified'); | 			toast.success('Server connection verified'); | ||||||
|  | @ -774,7 +774,7 @@ | ||||||
| 							<div> | 							<div> | ||||||
| 								<a href="https://github.com/ollama-webui/ollama-webui"> | 								<a href="https://github.com/ollama-webui/ollama-webui"> | ||||||
| 									<img | 									<img | ||||||
| 										alt="followers" | 										alt="Github Repo" | ||||||
| 										src="https://img.shields.io/github/stars/ollama-webui/ollama-webui?style=social&label=Star us on Github" | 										src="https://img.shields.io/github/stars/ollama-webui/ollama-webui?style=social&label=Star us on Github" | ||||||
| 									/> | 									/> | ||||||
| 								</a> | 								</a> | ||||||
|  |  | ||||||
|  | @ -236,6 +236,7 @@ | ||||||
| 		console.log(updated); | 		console.log(updated); | ||||||
| 		settings = { ...settings, ...updated }; | 		settings = { ...settings, ...updated }; | ||||||
| 		localStorage.setItem('settings', JSON.stringify(settings)); | 		localStorage.setItem('settings', JSON.stringify(settings)); | ||||||
|  | 		API_BASE_URL = updated?.API_BASE_URL ?? API_BASE_URL; | ||||||
| 		await getModelTags(); | 		await getModelTags(); | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
|  | @ -374,7 +375,7 @@ | ||||||
| 	// Ollama functions | 	// Ollama functions | ||||||
| 	////////////////////////// | 	////////////////////////// | ||||||
| 
 | 
 | ||||||
| 	const getModelTags = async (url = null) => { | 	const getModelTags = async (url = null, type = 'all') => { | ||||||
| 		const res = await fetch(`${url === null ? API_BASE_URL : url}/tags`, { | 		const res = await fetch(`${url === null ? API_BASE_URL : url}/tags`, { | ||||||
| 			method: 'GET', | 			method: 'GET', | ||||||
| 			headers: { | 			headers: { | ||||||
|  | @ -394,43 +395,47 @@ | ||||||
| 
 | 
 | ||||||
| 		console.log(res); | 		console.log(res); | ||||||
| 
 | 
 | ||||||
| 		if (settings.OPENAI_API_KEY) { | 		if (type === 'all') { | ||||||
| 			// Validate OPENAI_API_KEY | 			if (settings.OPENAI_API_KEY) { | ||||||
| 			const openaiModelRes = await fetch(`https://api.openai.com/v1/models`, { | 				// Validate OPENAI_API_KEY | ||||||
| 				method: 'GET', | 				const openaiModelRes = await fetch(`https://api.openai.com/v1/models`, { | ||||||
| 				headers: { | 					method: 'GET', | ||||||
| 					'Content-Type': 'application/json', | 					headers: { | ||||||
| 					Authorization: `Bearer ${settings.OPENAI_API_KEY}` | 						'Content-Type': 'application/json', | ||||||
| 				} | 						Authorization: `Bearer ${settings.OPENAI_API_KEY}` | ||||||
| 			}) | 					} | ||||||
| 				.then(async (res) => { |  | ||||||
| 					if (!res.ok) throw await res.json(); |  | ||||||
| 					return res.json(); |  | ||||||
| 				}) | 				}) | ||||||
| 				.catch((error) => { | 					.then(async (res) => { | ||||||
| 					console.log(error); | 						if (!res.ok) throw await res.json(); | ||||||
| 					toast.error(`OpenAI: ${error?.error?.message ?? 'Network Problem'}`); | 						return res.json(); | ||||||
| 					return null; | 					}) | ||||||
| 				}); | 					.catch((error) => { | ||||||
| 			const openaiModels = openaiModelRes?.data ?? null; | 						console.log(error); | ||||||
|  | 						toast.error(`OpenAI: ${error?.error?.message ?? 'Network Problem'}`); | ||||||
|  | 						return null; | ||||||
|  | 					}); | ||||||
|  | 				const openaiModels = openaiModelRes?.data ?? null; | ||||||
| 
 | 
 | ||||||
| 			if (openaiModels) { | 				if (openaiModels) { | ||||||
| 				models = [ | 					models = [ | ||||||
| 					...(res?.models ?? []), | 						...(res?.models ?? []), | ||||||
| 					{ name: 'hr' }, | 						{ name: 'hr' }, | ||||||
| 
 | 
 | ||||||
| 					...openaiModels | 						...openaiModels | ||||||
| 						.map((model) => ({ name: model.id, label: 'OpenAI' })) | 							.map((model) => ({ name: model.id, label: 'OpenAI' })) | ||||||
| 						.filter((model) => model.name.includes('gpt')) | 							.filter((model) => model.name.includes('gpt')) | ||||||
| 				]; | 					]; | ||||||
|  | 				} else { | ||||||
|  | 					models = res?.models ?? []; | ||||||
|  | 				} | ||||||
| 			} else { | 			} else { | ||||||
| 				models = res?.models ?? []; | 				models = res?.models ?? []; | ||||||
| 			} | 			} | ||||||
| 		} else { |  | ||||||
| 			models = res?.models ?? []; |  | ||||||
| 		} |  | ||||||
| 
 | 
 | ||||||
| 		return models; | 			return models; | ||||||
|  | 		} else { | ||||||
|  | 			return res?.models ?? null; | ||||||
|  | 		} | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
| 	const sendPrompt = async (userPrompt) => { | 	const sendPrompt = async (userPrompt) => { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy Jaeryang Baek
						Timothy Jaeryang Baek