yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
model_registry.cc
Go to the documentation of this file.
2
3#include <algorithm>
4
5namespace yaze {
6namespace cli {
7
9 static ModelRegistry instance;
10 return instance;
11}
12
13void ModelRegistry::RegisterService(std::shared_ptr<AIService> service) {
14 std::lock_guard<std::mutex> lock(mutex_);
15 services_.push_back(service);
16}
17
19 std::lock_guard<std::mutex> lock(mutex_);
20 services_.clear();
21}
22
23absl::StatusOr<std::vector<ModelInfo>> ModelRegistry::ListAllModels() {
24 std::lock_guard<std::mutex> lock(mutex_);
25 std::vector<ModelInfo> all_models;
26
27 for (const auto& service : services_) {
28 auto models_or = service->ListAvailableModels();
29 if (models_or.ok()) {
30 auto& models = *models_or;
31 all_models.insert(all_models.end(),
32 std::make_move_iterator(models.begin()),
33 std::make_move_iterator(models.end()));
34 }
35 }
36
37 // Sort by name
38 std::sort(
39 all_models.begin(), all_models.end(),
40 [](const ModelInfo& a, const ModelInfo& b) { return a.name < b.name; });
41
42 return all_models;
43}
44
45} // namespace cli
46} // namespace yaze
static ModelRegistry & GetInstance()
void RegisterService(std::shared_ptr< AIService > service)
absl::StatusOr< std::vector< ModelInfo > > ListAllModels()
std::vector< std::shared_ptr< AIService > > services_