-
Notifications
You must be signed in to change notification settings - Fork 5
/
models.py
48 lines (43 loc) · 1.56 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
from pathlib import Path
from typing_extensions import List
import flet as ft
import re
from ollama import list
DEFAULT_OLLAMA_MODEL_REGISTRY = Path("~/.ollama/models/manifests/registry.ollama.ai/library").expanduser()
DEFAULT_HF_MLX_MODEL_REGISTRY = Path("~/.cache/huggingface/hub/").expanduser()
# def returnModels() -> List[str]:
# #print(DEFAULT_OLLAMA_MODEL_REGISTRY)
# models = []
# for d in os.listdir(DEFAULT_OLLAMA_MODEL_REGISTRY):
# a_dir = os.path.join(DEFAULT_OLLAMA_MODEL_REGISTRY, d)
# if os.path.isdir(a_dir):
# for f in os.listdir(a_dir):
# if os.path.isfile(os.path.join(a_dir, f)):
# model = f'{d}:{f}'
# models.append(model)
# return models
def returnModels() -> List[str]:
print('entering retModels')
response = list()
raw_models = response['models']
models = []
for model in raw_models:
models.append(model['name'])
return models
def returnMlxModels() -> List[str]:
print(DEFAULT_HF_MLX_MODEL_REGISTRY)
models = []
for d in os.listdir(DEFAULT_HF_MLX_MODEL_REGISTRY):
a_dir = os.path.join(DEFAULT_HF_MLX_MODEL_REGISTRY, d)
if os.path.isdir(a_dir) and not d.startswith('.'):
#print(f'a_dir is {a_dir}')
model = re.split('--', d)[-1]
models.append(model)
#print(models)
return models
def retModelOptions(isMlx=False):
options = []
for m in returnMlxModels() if isMlx else returnModels():
options.append(ft.dropdown.Option(m))
return options