Tog bort en onödig nästling av dictionary för "models"
This commit is contained in:
@@ -73,26 +73,27 @@ def configure():
|
|||||||
for endpoint in global_state.get_endpoints():
|
for endpoint in global_state.get_endpoints():
|
||||||
if endpoint["provider"] == "ollama":
|
if endpoint["provider"] == "ollama":
|
||||||
if "requestOptions" in endpoint: # Check if authentication is needed
|
if "requestOptions" in endpoint: # Check if authentication is needed
|
||||||
# headers = {
|
|
||||||
# "Content-Type": "application/json",
|
|
||||||
# "Authorization": endpoint["requestOptions"]["headers"]["Authorization"]
|
|
||||||
# }
|
|
||||||
headers = {
|
headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
"Authorization": endpoint["requestOptions"]["headers"]["Authorization"]
|
"Authorization": endpoint["requestOptions"]["headers"]["Authorization"]
|
||||||
}
|
}
|
||||||
|
# headers = {
|
||||||
|
# "Authorization": endpoint["requestOptions"]["headers"]["Authorization"]
|
||||||
|
# }
|
||||||
else: # otherwise proceed without authentication
|
else: # otherwise proceed without authentication
|
||||||
# headers = {"Content-Type": "application/json"}
|
headers = {"Content-Type": "application/json"}
|
||||||
headers = None
|
# headers = None
|
||||||
# models = tag(url = endpoint["url"], headers = headers) # Ask for models (LLMs) available at endpoint
|
# models = tag(url = endpoint["url"], headers = headers) # Ask for models (LLMs) available at endpoint
|
||||||
try:
|
try:
|
||||||
models = requests.get(endpoint["url"] + "/api/tags", headers=headers).json()
|
models = requests.get(endpoint["url"] + "/api/tags", headers=headers).json()
|
||||||
|
# models = requests.get(endpoint["url"] + "/api/tags", headers=headers)
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
print(f"Error: {e}")
|
print(f"Error: {e}")
|
||||||
|
|
||||||
if isinstance(models, dict) and 'error' in models:
|
if isinstance(models, dict) and 'error' in models:
|
||||||
logger.error('Error fetching models from backend: %s', models['error'])
|
logger.error('Error fetching models from backend: %s', models['error'])
|
||||||
else:
|
else:
|
||||||
endpoint["models"] = models # Update endpoint with detected models
|
endpoint["models"] = models.get("models", []) # get the list of models directly
|
||||||
logger.debug("models = \n{}".format(json.dumps(models, indent=4)))
|
logger.debug("models = \n{}".format(json.dumps(models, indent=4)))
|
||||||
if endpoint["model"] is not "AUTODETECT": # Check if specified model is available
|
if endpoint["model"] is not "AUTODETECT": # Check if specified model is available
|
||||||
# do something
|
# do something
|
||||||
|
|||||||
Reference in New Issue
Block a user