Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ac72167ea | ||
|
|
3575bf7e60 | ||
|
|
96af5fca98 | ||
|
|
b867a6276e | ||
|
|
c18ddb5475 | ||
|
|
ef9b3738fd | ||
|
|
924ec403bd | ||
|
|
0c91f09113 | ||
|
|
45deb6645b | ||
|
|
243d8f4c7d | ||
|
|
4f72711a1e | ||
|
|
7855472499 | ||
|
|
a6ed974ece | ||
|
|
4c11b97197 | ||
|
|
87f00ee502 | ||
|
|
4fa1b8ea22 | ||
|
|
357441e0da | ||
|
|
9d2181e82b | ||
|
|
30378f7b6a | ||
|
|
b4f78bd192 | ||
|
|
3c90dad9b9 | ||
|
|
25f93d1a27 | ||
|
|
0f89cdaa07 | ||
|
|
d211eb6150 | ||
|
|
04580196ad | ||
|
|
7a3d6a7bb4 | ||
|
|
07d011263d | ||
|
|
0040efc948 | ||
|
|
16a3e209b6 | ||
|
|
c19edee7bb | ||
|
|
7af90a5eef | ||
|
|
8d7e5fe653 | ||
|
|
2605eccb64 | ||
|
|
1317b8024b | ||
|
|
9242806795 | ||
|
|
6714c4f556 | ||
|
|
a5966dd479 | ||
|
|
e015555dff | ||
|
|
f00bf8355a | ||
|
|
ddca3a8363 | ||
|
|
a67564bc24 | ||
|
|
7dbc39c6a6 | ||
|
|
b6fdf23aa6 | ||
|
|
220df29888 | ||
|
|
74d0295181 | ||
|
|
73a2bd7b42 | ||
|
|
e97fcddf87 | ||
|
|
51487e6329 |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cortiq-gateway"
|
name = "cortiq-gateway"
|
||||||
version = "0.2.33"
|
version = "0.2.32"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.75"
|
rust-version = "1.75"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
|
|||||||
+4
-58
@@ -467,70 +467,16 @@ async fn provider_models(
|
|||||||
}
|
}
|
||||||
// OpenAI + Anthropic both return { "data": [ { "id": ... } ] }.
|
// OpenAI + Anthropic both return { "data": [ { "id": ... } ] }.
|
||||||
let v: Value = serde_json::from_str(&body).unwrap_or(json!({}));
|
let v: Value = serde_json::from_str(&body).unwrap_or(json!({}));
|
||||||
let mut models: Vec<Value> = v["data"]
|
let mut models: Vec<String> = v["data"]
|
||||||
.as_array()
|
.as_array()
|
||||||
.map(|arr| {
|
.map(|arr| {
|
||||||
arr.iter()
|
arr.iter()
|
||||||
.filter_map(|m| {
|
.filter_map(|m| m["id"].as_str().map(|s| s.to_string()))
|
||||||
let id = m["id"].as_str()?.to_string();
|
|
||||||
let mut obj = json!({ "id": id });
|
|
||||||
let mut caps = vec![];
|
|
||||||
if let Some(pricing) = m.get("pricing").filter(|v| !v.is_null()) {
|
|
||||||
if let Some(prompt) = pricing.get("prompt").and_then(|s| s.as_str()).and_then(|s| s.parse::<f64>().ok()) {
|
|
||||||
obj["price_in"] = json!(prompt * 1_000_000.0);
|
|
||||||
}
|
|
||||||
if let Some(comp) = pricing.get("completion").and_then(|s| s.as_str()).and_then(|s| s.parse::<f64>().ok()) {
|
|
||||||
obj["price_out"] = json!(comp * 1_000_000.0);
|
|
||||||
}
|
|
||||||
if pricing.get("input_cache_read").filter(|v| !v.is_null()).is_some() || pricing.get("input_cache_write").filter(|v| !v.is_null()).is_some() {
|
|
||||||
caps.push("caching");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(params) = m.get("supported_parameters").and_then(|p| p.as_array()) {
|
|
||||||
let has_tools = params.iter().any(|p| p.as_str() == Some("tools") || p.as_str() == Some("tool_choice"));
|
|
||||||
if has_tools { caps.push("tools"); }
|
|
||||||
let has_json = params.iter().any(|p| p.as_str() == Some("response_format"));
|
|
||||||
if has_json { caps.push("json"); }
|
|
||||||
let has_reasoning = params.iter().any(|p| p.as_str() == Some("reasoning") || p.as_str() == Some("include_reasoning"));
|
|
||||||
if has_reasoning || m.get("reasoning").filter(|v| !v.is_null()).is_some() { caps.push("reasoning"); }
|
|
||||||
}
|
|
||||||
if let Some(arch) = m.get("architecture").filter(|v| !v.is_null()) {
|
|
||||||
if let Some(inputs) = arch.get("input_modalities").and_then(|i| i.as_array()) {
|
|
||||||
if inputs.iter().any(|i| i.as_str() == Some("image")) { caps.push("vision"); }
|
|
||||||
if inputs.iter().any(|i| i.as_str() == Some("audio")) { caps.push("audio"); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !caps.is_empty() {
|
|
||||||
obj["caps"] = json!(caps);
|
|
||||||
}
|
|
||||||
Some(obj)
|
|
||||||
})
|
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
models.sort_by(|a, b| a["id"].as_str().cmp(&b["id"].as_str()));
|
models.sort();
|
||||||
|
ok(json!({ "ok": true, "count": models.len(), "models": models }))
|
||||||
let mut resp = json!({ "ok": true, "count": models.len(), "models": models });
|
|
||||||
|
|
||||||
if b.provider == "openrouter" {
|
|
||||||
if let Some(k) = key {
|
|
||||||
if let Ok(cred_resp) = client.get("https://openrouter.ai/api/v1/credits")
|
|
||||||
.header("authorization", format!("Bearer {k}"))
|
|
||||||
.send().await
|
|
||||||
{
|
|
||||||
if let Ok(cred_body) = cred_resp.text().await {
|
|
||||||
let cred_v: Value = serde_json::from_str(&cred_body).unwrap_or(json!({}));
|
|
||||||
if let Some(data) = cred_v.get("data") {
|
|
||||||
let total = data.get("total_credits").and_then(|v| v.as_f64()).unwrap_or(0.0);
|
|
||||||
let usage = data.get("total_usage").and_then(|v| v.as_f64()).unwrap_or(0.0);
|
|
||||||
resp["balance"] = json!(total - usage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ok(resp)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn meta() -> ApiResult {
|
async fn meta() -> ApiResult {
|
||||||
|
|||||||
+4
-8
@@ -324,7 +324,7 @@ async fn download_cmf_repo(
|
|||||||
let cmf_path = match cmf_rel_path {
|
let cmf_path = match cmf_rel_path {
|
||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
None => {
|
None => {
|
||||||
let repo_name = repo.rsplit('/').next().unwrap_or(&repo);
|
let repo_name = repo.split('/').last().unwrap_or(&repo);
|
||||||
format!("{repo_name}.cmf")
|
format!("{repo_name}.cmf")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -491,13 +491,9 @@ pub fn start_import(store: Arc<JobStore>, cfg: &CmfCfg, p: ImportParams) -> Resu
|
|||||||
let r = p.repo.to_lowercase();
|
let r = p.repo.to_lowercase();
|
||||||
if r.contains("2bit") || r.contains("q1t") {
|
if r.contains("2bit") || r.contains("q1t") {
|
||||||
"Q1T".to_string()
|
"Q1T".to_string()
|
||||||
} else if r.contains("1.7bcmf")
|
} else if r.contains("1.7bcmf") || r.contains("27bcmf") || r.contains("cmf") {
|
||||||
|| r.contains("27bcmf")
|
"Q1".to_string()
|
||||||
|| r.contains("cmf")
|
} else if p.quant.is_empty() || p.quant == "auto" || p.quant == "Q8_2F" {
|
||||||
|| p.quant.is_empty()
|
|
||||||
|| p.quant == "auto"
|
|
||||||
|| p.quant == "Q8_2F"
|
|
||||||
{
|
|
||||||
"Q1".to_string()
|
"Q1".to_string()
|
||||||
} else {
|
} else {
|
||||||
p.quant.clone()
|
p.quant.clone()
|
||||||
|
|||||||
Vendored
+1
-1
@@ -19,6 +19,6 @@
|
|||||||
<noscript>This console requires JavaScript.</noscript>
|
<noscript>This console requires JavaScript.</noscript>
|
||||||
<div id="app"><div class="boot">Loading…</div></div>
|
<div id="app"><div class="boot">Loading…</div></div>
|
||||||
<div id="toasts" class="toasts"></div>
|
<div id="toasts" class="toasts"></div>
|
||||||
<script type="module" src="/admin/js/app.js?v=3"></script>
|
<script type="module" src="/admin/js/app.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Vendored
+1
-1
@@ -4,7 +4,7 @@ import { t, getLang, setLang, onLangChange, LANGS } from "./i18n.js";
|
|||||||
import { api, getToken, setToken, setUnauthorizedHandler } from "./api.js";
|
import { api, getToken, setToken, setUnauthorizedHandler } from "./api.js";
|
||||||
import { renderLogin } from "./views/login.js";
|
import { renderLogin } from "./views/login.js";
|
||||||
import { renderDashboard } from "./views/dashboard.js";
|
import { renderDashboard } from "./views/dashboard.js";
|
||||||
import { renderModels } from "./views/models.js?v=3";
|
import { renderModels } from "./views/models.js";
|
||||||
import { renderImport } from "./views/import.js";
|
import { renderImport } from "./views/import.js";
|
||||||
import { renderRouting } from "./views/routing.js";
|
import { renderRouting } from "./views/routing.js";
|
||||||
import { renderProtocols } from "./views/protocols.js";
|
import { renderProtocols } from "./views/protocols.js";
|
||||||
|
|||||||
Vendored
+18
-64
@@ -51,16 +51,7 @@ function modelForm(meta, existing) {
|
|||||||
const tierSel = h("select", {}, ...(meta.cost_tiers || ["cheap"]).map((c) => opt(c, c, c === m.cost_tier)));
|
const tierSel = h("select", {}, ...(meta.cost_tiers || ["cheap"]).map((c) => opt(c, c, c === m.cost_tier)));
|
||||||
const priceInIn = h("input", { type: "number", step: "0.01", value: m.price_in ?? 0 });
|
const priceInIn = h("input", { type: "number", step: "0.01", value: m.price_in ?? 0 });
|
||||||
const priceOutIn = h("input", { type: "number", step: "0.01", value: m.price_out ?? 0 });
|
const priceOutIn = h("input", { type: "number", step: "0.01", value: m.price_out ?? 0 });
|
||||||
const CAP_EMOJIS = {
|
const capInputs = (meta.caps || ["tools", "vision"]).map((c) => {
|
||||||
tools: "🔧 tools",
|
|
||||||
vision: "👁️ vision",
|
|
||||||
audio: "🎙️ audio",
|
|
||||||
reasoning: "🧠 reasoning",
|
|
||||||
json: "📄 json",
|
|
||||||
caching: "⚡ caching"
|
|
||||||
};
|
|
||||||
|
|
||||||
const capInputs = (meta.caps || Object.keys(CAP_EMOJIS)).map((c) => {
|
|
||||||
const cb = h("input", { type: "checkbox", checked: (m.caps || []).includes(c) ? true : null });
|
const cb = h("input", { type: "checkbox", checked: (m.caps || []).includes(c) ? true : null });
|
||||||
return { c, cb };
|
return { c, cb };
|
||||||
});
|
});
|
||||||
@@ -79,55 +70,25 @@ function modelForm(meta, existing) {
|
|||||||
capInputs.forEach(({ c, cb }) => { cb.checked = d.caps.includes(c); });
|
capInputs.forEach(({ c, cb }) => { cb.checked = d.caps.includes(c); });
|
||||||
keyIn.placeholder = d.needsKey ? t("models.form.apiKeyPlaceholder") : t("models.form.apiKeyNotNeeded");
|
keyIn.placeholder = d.needsKey ? t("models.form.apiKeyPlaceholder") : t("models.form.apiKeyNotNeeded");
|
||||||
mount(keyStatus, "");
|
mount(keyStatus, "");
|
||||||
// Automatically pre-fetch models (especially useful for OpenRouter which doesn't need a key)
|
|
||||||
testKey(true);
|
|
||||||
}
|
}
|
||||||
providerSel.addEventListener("change", applyDefaults);
|
providerSel.addEventListener("change", applyDefaults);
|
||||||
if (!existing) applyDefaults();
|
if (!existing) applyDefaults();
|
||||||
|
|
||||||
let cachedModels = [];
|
// Auto-fill the id from the model name (until the user edits id by hand).
|
||||||
|
|
||||||
const autofillData = () => {
|
|
||||||
console.log("autofillData triggered. modelIn.value:", modelIn.value);
|
|
||||||
console.log("cachedModels length:", cachedModels.length);
|
|
||||||
if (!existing && (!idIn.value || idIn._auto)) {
|
|
||||||
idIn.value = slugId(modelIn.value);
|
|
||||||
idIn._auto = true;
|
|
||||||
console.log("auto-filled idIn:", idIn.value);
|
|
||||||
}
|
|
||||||
const found = cachedModels.find((m) => (m.id || m) === modelIn.value);
|
|
||||||
console.log("found model:", found);
|
|
||||||
if (found) {
|
|
||||||
if (found.price_in !== undefined) {
|
|
||||||
priceInIn.value = parseFloat(Number(found.price_in).toFixed(4));
|
|
||||||
priceOutIn.value = parseFloat(Number(found.price_out).toFixed(4));
|
|
||||||
console.log("Updated prices:", priceInIn.value, priceOutIn.value);
|
|
||||||
}
|
|
||||||
if (found.caps && Array.isArray(found.caps)) {
|
|
||||||
capInputs.forEach(({ c, cb }) => {
|
|
||||||
cb.checked = found.caps.includes(c);
|
|
||||||
});
|
|
||||||
console.log("Updated caps:", found.caps);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
modelIn.addEventListener("input", autofillData);
|
|
||||||
modelIn.addEventListener("change", autofillData);
|
|
||||||
|
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
|
modelIn.addEventListener("input", () => {
|
||||||
|
if (!idIn.value || idIn._auto) {
|
||||||
|
idIn.value = slugId(modelIn.value);
|
||||||
|
idIn._auto = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
idIn.addEventListener("input", () => { idIn._auto = false; });
|
idIn.addEventListener("input", () => { idIn._auto = false; });
|
||||||
} else {
|
|
||||||
console.log("Editing existing model, fetching testKey(true)");
|
|
||||||
testKey(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function testKey(silent = false) {
|
async function testKey() {
|
||||||
if (!baseUrlIn.value.trim()) {
|
if (!baseUrlIn.value.trim()) { mount(keyStatus, h("span", { style: "color:var(--bad)" }, t("models.form.baseUrl") + "?")); return; }
|
||||||
if (!silent) mount(keyStatus, h("span", { style: "color:var(--bad)" }, t("models.form.baseUrl") + "?"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
testBtn.disabled = true;
|
testBtn.disabled = true;
|
||||||
if (!silent) mount(keyStatus, t("models.form.testing"));
|
mount(keyStatus, t("models.form.testing"));
|
||||||
try {
|
try {
|
||||||
const r = await api.providerModels({
|
const r = await api.providerModels({
|
||||||
provider: providerSel.value,
|
provider: providerSel.value,
|
||||||
@@ -136,25 +97,18 @@ function modelForm(meta, existing) {
|
|||||||
api_key_env: envFor(),
|
api_key_env: envFor(),
|
||||||
});
|
});
|
||||||
if (r.ok) {
|
if (r.ok) {
|
||||||
cachedModels = r.models || [];
|
dl.replaceChildren(...(r.models || []).map((mm) => h("option", { value: mm })));
|
||||||
dl.replaceChildren(...cachedModels.map((mm) => h("option", { value: mm.id || mm })));
|
mount(keyStatus, h("span", { style: "color:var(--good)" }, "✓ " + t("models.form.foundModels", { n: r.count })));
|
||||||
|
modelIn.focus();
|
||||||
let msg = "✓ " + t("models.form.foundModels", { n: r.count });
|
|
||||||
if (r.balance !== undefined) {
|
|
||||||
msg += ` (Balance: $${r.balance.toFixed(4)})`;
|
|
||||||
}
|
|
||||||
mount(keyStatus, h("span", { style: "color:var(--good)" }, msg));
|
|
||||||
if (!silent) modelIn.focus();
|
|
||||||
} else {
|
} else {
|
||||||
if (!silent) mount(keyStatus, h("span", { style: "color:var(--bad)" }, "✗ " + (r.error || t("common.error"))));
|
mount(keyStatus, h("span", { style: "color:var(--bad)" }, "✗ " + (r.error || t("common.error"))));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!silent) mount(keyStatus, h("span", { style: "color:var(--bad)" }, "✗ " + String(e.message || e)));
|
mount(keyStatus, h("span", { style: "color:var(--bad)" }, "✗ " + String(e.message || e)));
|
||||||
}
|
}
|
||||||
testBtn.disabled = false;
|
testBtn.disabled = false;
|
||||||
}
|
}
|
||||||
testBtn.addEventListener("click", () => testKey(false));
|
testBtn.addEventListener("click", testKey);
|
||||||
keyIn.addEventListener("change", () => testKey(true));
|
|
||||||
|
|
||||||
const keyHint =
|
const keyHint =
|
||||||
existing && existing.key_source === "store" ? t("models.form.keyStored")
|
existing && existing.key_source === "store" ? t("models.form.keyStored")
|
||||||
@@ -201,7 +155,7 @@ function modelForm(meta, existing) {
|
|||||||
dl,
|
dl,
|
||||||
h("div", { class: "row" }, field(t("models.form.kind"), kindSel), field(t("models.form.costTier"), tierSel)),
|
h("div", { class: "row" }, field(t("models.form.kind"), kindSel), field(t("models.form.costTier"), tierSel)),
|
||||||
h("div", { class: "row" }, field(t("models.form.priceIn"), priceInIn), field(t("models.form.priceOut"), priceOutIn)),
|
h("div", { class: "row" }, field(t("models.form.priceIn"), priceInIn), field(t("models.form.priceOut"), priceOutIn)),
|
||||||
field(t("models.form.caps"), h("div", { class: "flex wrap", style: "gap:10px" }, ...capInputs.map(({ c, cb }) => h("label", { class: "check", style: "margin:0" }, cb, CAP_EMOJIS[c] || c)))),
|
field(t("models.form.caps"), h("div", { class: "flex wrap" }, ...capInputs.map(({ c, cb }) => h("label", { class: "check" }, cb, c)))),
|
||||||
advParams
|
advParams
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user