-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuiltin_model_catalog.cpp
More file actions
86 lines (73 loc) · 2.57 KB
/
Copy pathbuiltin_model_catalog.cpp
File metadata and controls
86 lines (73 loc) · 2.57 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "builtin_model_catalog.hpp"
#include <algorithm>
#include <cctype>
namespace acecode {
namespace {
constexpr int kAceModelFallbackContextWindow = 250000;
std::string lower_ascii(std::string value) {
std::transform(value.begin(), value.end(), value.begin(),
[](unsigned char ch) {
return static_cast<char>(std::tolower(ch));
});
return value;
}
std::string normalize_base_url(std::string value) {
std::size_t start = 0;
while (start < value.size() &&
std::isspace(static_cast<unsigned char>(value[start]))) {
++start;
}
std::size_t end = value.size();
while (end > start &&
std::isspace(static_cast<unsigned char>(value[end - 1]))) {
--end;
}
value = value.substr(start, end - start);
while (!value.empty() && value.back() == '/') value.pop_back();
return lower_ascii(value);
}
ModelEntry builtin_model(const std::string& id, const std::string& name) {
ModelEntry model;
model.id = id;
model.name = name;
model.context = kAceModelFallbackContextWindow;
model.tool_call = true;
model.attachment = true;
return model;
}
ProviderEntry build_acemodel_provider() {
ProviderEntry provider;
provider.id = "acemodel";
provider.name = "ACEModel";
provider.env = {"ACEMODEL_API_KEY"};
provider.base_url = "https://ge.bigjuan.xyz/aceapi/v1";
provider.openai_compatible = true;
provider.models = {
builtin_model("moonlight", "Moonlight"),
builtin_model("starrylight", "Starrylight"),
builtin_model("aurora", "Aurora"),
};
return provider;
}
} // namespace
const ProviderEntry& acemodel_catalog_provider() {
static const ProviderEntry provider = build_acemodel_provider();
return provider;
}
bool is_acemodel_provider_id(const std::string& provider_id) {
return lower_ascii(provider_id) == acemodel_catalog_provider().id;
}
const ModelEntry* find_acemodel_catalog_model(const std::string& model_id) {
const std::string normalized = lower_ascii(model_id);
const auto& models = acemodel_catalog_provider().models;
const auto it = std::find_if(models.begin(), models.end(), [&](const ModelEntry& model) {
return lower_ascii(model.id) == normalized;
});
return it == models.end() ? nullptr : &*it;
}
bool is_acemodel_base_url(const std::string& base_url) {
const auto& canonical = acemodel_catalog_provider().base_url;
return canonical.has_value() &&
normalize_base_url(base_url) == normalize_base_url(*canonical);
}
} // namespace acecode