helper functions
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import httpx
|
||||
from nicegui import ui
|
||||
from typing import Tuple, Dict
|
||||
from typing import Tuple, Dict, List, Any
|
||||
|
||||
|
||||
async def status(url='http://127.0.0.1:11434') -> Tuple[bool, str]:
|
||||
@@ -24,6 +24,51 @@ async def available_models(url='http://127.0.0.1:11434'):
|
||||
return response.json()["models"]
|
||||
|
||||
|
||||
async def available_models_detailed(url='http://127.0.0.1:11434') -> List[Dict[str, Any]]:
|
||||
detailed_models = []
|
||||
models = await available_models(url)
|
||||
sorted_model_names = sorted([model['name'] for model in models], key=str.lower)
|
||||
for model_name in sorted_model_names:
|
||||
for model in models:
|
||||
if model['name'] == model_name:
|
||||
detailed_models.append(model | await model_info(model_name))
|
||||
continue
|
||||
return detailed_models
|
||||
|
||||
|
||||
def model_parameters(model: dict) -> Dict[str, float | int | List[str]]:
|
||||
modelfile = model.get('modelfile', '')
|
||||
parameters = {}
|
||||
# Parse the modelfile content to extract settings
|
||||
for line in modelfile.split('\n'):
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
|
||||
if line.startswith('PARAMETER '):
|
||||
# Parse parameter lines
|
||||
param_line = line[10:].strip()
|
||||
try:
|
||||
key, value = param_line.split(' ', 1)
|
||||
|
||||
# Set parameter values and enable toggles
|
||||
# floats
|
||||
if key in ['temperature', 'top_p', 'min_p', 'repeat_penalty']:
|
||||
parameters[key] = float(value)
|
||||
# integers
|
||||
elif key in ['top_k', 'num_ctx', 'num_predict', 'repeat_last_n', 'seed']:
|
||||
parameters[key] = int(value)
|
||||
# stops
|
||||
elif key == 'stop':
|
||||
if 'stop' not in parameters:
|
||||
parameters['stop'] = []
|
||||
parameters['stop'].append(value)
|
||||
except ValueError:
|
||||
# Skip invalid parameter lines
|
||||
continue
|
||||
return parameters
|
||||
|
||||
|
||||
async def active_models(url='http://127.0.0.1:11434'):
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.get(f"{url}/api/ps")
|
||||
|
||||
Reference in New Issue
Block a user