forked from open-webui/open-webui
		
	fix: multiple openai issue
This commit is contained in:
		
							parent
							
								
									e414b9ea6d
								
							
						
					
					
						commit
						1bfcd801b7
					
				
					 3 changed files with 31 additions and 23 deletions
				
			
		|  | @ -168,14 +168,15 @@ def merge_models_lists(model_lists): | |||
|     merged_list = [] | ||||
| 
 | ||||
|     for idx, models in enumerate(model_lists): | ||||
|         merged_list.extend( | ||||
|             [ | ||||
|                 {**model, "urlIdx": idx} | ||||
|                 for model in models | ||||
|                 if "api.openai.com" not in app.state.OPENAI_API_BASE_URLS[idx] | ||||
|                 or "gpt" in model["id"] | ||||
|             ] | ||||
|         ) | ||||
|         if models is not None and "error" not in models: | ||||
|             merged_list.extend( | ||||
|                 [ | ||||
|                     {**model, "urlIdx": idx} | ||||
|                     for model in models | ||||
|                     if "api.openai.com" not in app.state.OPENAI_API_BASE_URLS[idx] | ||||
|                     or "gpt" in model["id"] | ||||
|                 ] | ||||
|             ) | ||||
| 
 | ||||
|     return merged_list | ||||
| 
 | ||||
|  | @ -190,15 +191,20 @@ async def get_all_models(): | |||
|             fetch_url(f"{url}/models", app.state.OPENAI_API_KEYS[idx]) | ||||
|             for idx, url in enumerate(app.state.OPENAI_API_BASE_URLS) | ||||
|         ] | ||||
| 
 | ||||
|         responses = await asyncio.gather(*tasks) | ||||
|         responses = list( | ||||
|             filter(lambda x: x is not None and "error" not in x, responses) | ||||
|         ) | ||||
|         models = { | ||||
|             "data": merge_models_lists( | ||||
|                 list(map(lambda response: response["data"], responses)) | ||||
|                 list( | ||||
|                     map( | ||||
|                         lambda response: response["data"] if response else None, | ||||
|                         responses, | ||||
|                     ) | ||||
|                 ) | ||||
|             ) | ||||
|         } | ||||
| 
 | ||||
|         print(models) | ||||
|         app.state.MODELS = {model["id"]: model for model in models["data"]} | ||||
| 
 | ||||
|         return models | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy J. Baek
						Timothy J. Baek