fetchDialModelsInfo function
fetchDialModels plus the DIAL-specific deployment features: the second
component carries the ids whose features.cache flag is on (manual
cache_breakpoint markers are honored). features.auto_caching models
cache on their own and need no markers; they are NOT in the set.
Implementation
Future<DialModelsInfo> fetchDialModelsInfo(
String baseUrl,
String apiKey, {
http.Client? client,
}) async {
final httpClient = client ?? http.Client();
final ownsClient = client == null;
try {
final normalized = baseUrl.replaceAll(RegExp(r'/+$'), '');
final response = await httpClient
.get(
Uri.parse('$normalized/openai/models'),
headers: {
'Accept': 'application/json',
if (apiKey.isNotEmpty) 'Api-Key': apiKey,
},
)
.timeout(const Duration(seconds: 15));
if (response.statusCode != 200) {
return (
const <String>[],
const <String>{},
const <String, int>{},
const <String, int>{},
);
}
final (ids, windows, maxTokens) = parseModelsResponse(response.body);
final cacheSupported = _dialCacheSupportedIds(response.body);
return (ids, cacheSupported, windows, maxTokens);
} on Object {
return (
const <String>[],
const <String>{},
const <String, int>{},
const <String, int>{},
);
} finally {
if (ownsClient) httpClient.close();
}
}