fetchInstalledOllamaModels static method
Implementation
static Future<List<Model>?> fetchInstalledOllamaModels({
String? ollamaUrl,
}) async {
// All available models
// final url = "${ollamaUrl ?? kBaseOllamaUrl}/api/tags";
// All loaded models
final url = "${ollamaUrl ?? kBaseOllamaUrl}/api/ps";
try {
final (resp, _, msg) = await sendHttpRequest(
'OLLAMA_FETCH',
APIType.rest,
HttpRequestModel(url: url, method: HTTPVerb.get),
noSSL: true,
);
// debugPrint("fetchInstalledOllamaModels -> $url -> ${resp?.body} -> $msg");
if (resp == null) {
return null;
}
final output = jsonDecode(resp.body);
final models = output['models'];
if (models == null) return [];
List<Model> ollamaModels = [];
for (final m in models) {
ollamaModels.add(Model(id: m['model'], name: m['name']));
}
return ollamaModels;
} catch (e) {
debugPrint('fetchInstalledOllamaModels -> ${e.toString()}');
return null;
}
}