publish all priced relay groups

This commit is contained in:
wlx committed 2026-09-27 16:04:23 +08:00
1 parent a80896e3c7
commit a022162382
4 files changed
+200 -1

No files matched your search

@@ -0,0 +1,21 @@
-- Publish every priced relay route for an enabled channel.
--
-- V14 deliberately inserted the relay catalog as disabled so credentials and
-- prices could be reviewed first. V17 populated the channel-specific prices,
-- but routes stayed disabled even after an administrator enabled a channel.
-- That made the user catalog expose only the one route that had been enabled
-- manually, although the same logical model had a priced route in another
-- channel. A route without a price remains hidden until it is configured.
UPDATE model_catalog AS m
SET status = 'active', updated_at = now()
FROM model_providers AS p, model_definitions AS d
WHERE m.provider_id = p.id
AND m.logical_model_id = d.id
AND p.status = 'active'
AND p.deleted_at IS NULL
AND d.status = 'active'
AND d.deleted_at IS NULL
AND m.status = 'disabled'
AND m.deleted_at IS NULL
AND m.pricing IS NOT NULL;
@@ -0,0 +1,81 @@
-- TokenFoundryX currently publishes these seven models in addition to the
-- thirteen routes staged by V14. Keep them under the same logical model as
-- other channels, so the user catalog can show both routes and API Keys can
-- authorize either one.
DO $$
DECLARE
item record;
provider_id_value text;
logical_id_value text;
route_status text;
BEGIN
SELECT id, status INTO provider_id_value, route_status
FROM model_providers
WHERE code = 'tokenfoundryx' AND deleted_at IS NULL
ORDER BY created_at
LIMIT 1;
IF provider_id_value IS NULL THEN
RETURN;
END IF;
FOR item IN
SELECT * FROM (VALUES
('gemini-2.5-flash-lite', 'Google', 75.0::numeric, 300.0::numeric, NULL::numeric, 'gemini-2.5-flash-lite'),
('gemini-2.5-pro', 'Google', 75.0::numeric, 600.0::numeric, NULL::numeric, 'gemini-2.5-pro'),
('gemini-3.7-flash', 'Google', 0.75::numeric, 3.75::numeric, 0.075::numeric, 'gemini-3.7-flash'),
('gemini-3.8-flash', 'Google', 0.75::numeric, 3.75::numeric, 0.075::numeric, 'gemini-3.8-flash'),
('gpt-5.4', 'OpenAI', 17.825::numeric, 106.95::numeric, 1.75::numeric, 'gpt-5.4'),
('gpt-5.4-mini', 'OpenAI', 5.25::numeric, 31.5::numeric, 0.525::numeric, 'gpt-5.4-mini'),
('gpt-5.5', 'OpenAI', 5.0::numeric, 30.0::numeric, 0.5::numeric, 'gpt-5.5')
) AS models(model_key, vendor_name, list_input, list_output, list_cached, upstream_model)
LOOP
INSERT INTO model_definitions (id, model_key, public_name, vendor_name, model_type, call_mode, description, input_types, output_types, status)
SELECT 'relay-def-' || gen_random_uuid()::text, item.model_key, item.model_key, item.vendor_name,
'text', 'sync', '来自 TokenFoundryX 的模型目录。', '["text"]'::jsonb, '["text"]'::jsonb, 'active'
WHERE NOT EXISTS (
SELECT 1 FROM model_definitions
WHERE model_key = item.model_key AND deleted_at IS NULL
);
SELECT id INTO logical_id_value
FROM model_definitions
WHERE model_key = item.model_key AND deleted_at IS NULL
ORDER BY created_at
LIMIT 1;
INSERT INTO model_catalog (
id, provider_id, model_key, source_label, public_name, upstream_model,
model_type, call_mode, description, input_types, output_types,
capabilities, pricing, priority, max_concurrency, logical_model_id, status
)
SELECT 'relay-route-' || gen_random_uuid()::text, provider_id_value, item.model_key,
'TokenFoundryX', d.public_name, item.upstream_model, d.model_type, d.call_mode,
d.description, d.input_types, d.output_types, '{}'::jsonb,
jsonb_build_object(
'input', item.list_input * 7.2,
'output', item.list_output * 7.2,
'unit', 'CNY / 1M tokens',
'exchangeRate', 7.2,
'priceSource', 'TokenFoundryX 模型广场',
'discountLabel', '未提供',
'listPriceUsd', jsonb_strip_nulls(jsonb_build_object(
'input', item.list_input,
'output', item.list_output,
'cachedInput', item.list_cached
)),
'cachedInput', CASE WHEN item.list_cached IS NULL THEN NULL ELSE item.list_cached * 7.2 END
),
100, 1, logical_id_value, CASE WHEN route_status = 'active' THEN 'active' ELSE 'disabled' END
FROM model_definitions d
WHERE d.id = logical_id_value
AND NOT EXISTS (
SELECT 1 FROM model_catalog m
WHERE m.logical_model_id = logical_id_value
AND m.provider_id = provider_id_value
AND m.upstream_model = item.upstream_model
AND m.deleted_at IS NULL
);
END LOOP;
END $$;
@@ -0,0 +1,89 @@
-- Complete the relay routes that are present in the live pricing catalogs but
-- were not included in the original seed. Keep each route separate so a
-- logical model can expose one group per channel.
DO $$
DECLARE
item record;
provider_id_value text;
logical_id_value text;
provider_status text;
route_status text;
BEGIN
FOR item IN
SELECT * FROM (VALUES
('apihub', 'deepseek-v4.1-flash', 'DeepSeek', 0.4::numeric, 1.6::numeric, 0.08::numeric, NULL::numeric, '未提供'),
('apihub', 'glm-5.3-flash', '智谱 AI', 0.8::numeric, 2.8::numeric, 0.23::numeric, NULL::numeric, '未提供'),
('apihub', 'hy3', '其他', 1.0::numeric, 4.0::numeric, 0.25::numeric, NULL::numeric, '未提供'),
('apipro', 'gpt-6-luna', 'OpenAI', 0.1::numeric, 0.5::numeric, NULL::numeric, 0.56::numeric, '5.6折'),
('apipro', 'gpt-6-sol', 'OpenAI', 2.0::numeric, 10.0::numeric, NULL::numeric, 0.56::numeric, '5.6折'),
('apipro', 'grok-4.7', 'xAI', 2.0::numeric, 6.0::numeric, NULL::numeric, 0.56::numeric, '5.6折')
) AS models(provider_code, model_key, vendor_name, list_input, list_output, list_cached, discount, discount_label)
LOOP
SELECT id, status INTO provider_id_value, provider_status
FROM model_providers
WHERE code = item.provider_code AND deleted_at IS NULL
ORDER BY created_at
LIMIT 1;
IF provider_id_value IS NULL THEN
CONTINUE;
END IF;
INSERT INTO model_definitions (
id, model_key, public_name, vendor_name, model_type, call_mode,
description, input_types, output_types, status
)
SELECT 'relay-def-' || gen_random_uuid()::text, item.model_key, item.model_key,
item.vendor_name, 'text', 'sync',
'来自 ' || item.provider_code || ' 模型目录。',
'["text"]'::jsonb, '["text"]'::jsonb, 'active'
WHERE NOT EXISTS (
SELECT 1 FROM model_definitions
WHERE model_key = item.model_key AND deleted_at IS NULL
);
SELECT id INTO logical_id_value
FROM model_definitions
WHERE model_key = item.model_key AND deleted_at IS NULL
ORDER BY created_at
LIMIT 1;
route_status := CASE WHEN provider_status = 'active' THEN 'active' ELSE 'disabled' END;
INSERT INTO model_catalog (
id, provider_id, model_key, source_label, public_name, upstream_model,
model_type, call_mode, description, input_types, output_types,
capabilities, pricing, priority, max_concurrency, logical_model_id, status
)
SELECT 'relay-route-' || gen_random_uuid()::text, provider_id_value,
item.model_key,
CASE item.provider_code WHEN 'apihub' THEN 'ApiHub 国内' ELSE 'APIPro' END,
d.public_name, item.model_key, d.model_type, d.call_mode,
d.description, d.input_types, d.output_types, '{}'::jsonb,
jsonb_strip_nulls(jsonb_build_object(
'input', item.list_input * 7.2 * COALESCE(item.discount, 1),
'output', item.list_output * 7.2 * COALESCE(item.discount, 1),
'unit', 'CNY / 1M tokens',
'discount', CASE WHEN item.discount IS NULL THEN NULL ELSE item.discount * 10 END,
'discountLabel', item.discount_label,
'exchangeRate', 7.2,
'priceSource', CASE item.provider_code WHEN 'apihub' THEN 'ApiHub 模型广场' ELSE 'APIPro 模型广场' END,
'listPriceUsd', jsonb_strip_nulls(jsonb_build_object(
'input', item.list_input,
'output', item.list_output,
'cachedInput', item.list_cached
)),
'cachedInput', CASE WHEN item.list_cached IS NULL THEN NULL ELSE item.list_cached * 7.2 * COALESCE(item.discount, 1) END
)),
100, 1, logical_id_value, route_status
FROM model_definitions d
WHERE d.id = logical_id_value
AND NOT EXISTS (
SELECT 1 FROM model_catalog m
WHERE m.logical_model_id = logical_id_value
AND m.provider_id = provider_id_value
AND m.upstream_model = item.model_key
AND m.deleted_at IS NULL
);
END LOOP;
END $$;