-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmodels.py
38 lines (33 loc) · 1.22 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
import os
from pathlib import Path
from typing_extensions import List
import flet as ft
import re
from ollamaOpenAIClient import OllamaOpenAPIClient
from mlxClient import MlxClient
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')
models = OllamaOpenAPIClient().list()
return models
def returnMlxModels() -> List[str]:
print('entering retModels')
models = MlxClient().list()
return models
def retModelOptions(isMlx=False):
options = []
for m in returnMlxModels() if isMlx else returnModels():
options.append(ft.dropdown.Option(m))
return options