feat: implement AI gateway phase one runtime

This commit is contained in:
2026-05-09 21:18:32 +08:00
parent a5e66e79cd
commit fdcdcd477b
46 changed files with 5678 additions and 768 deletions
@@ -0,0 +1,26 @@
DELETE FROM model_pricing_rules
WHERE resource_type = 'image_edit'
OR rule_key = 'image_edit';
DELETE FROM model_pricing_rules old_rule
USING model_pricing_rules image_rule
WHERE old_rule.rule_set_id IS NOT DISTINCT FROM image_rule.rule_set_id
AND old_rule.rule_key = 'image_generation'
AND image_rule.rule_key = 'image';
UPDATE model_pricing_rules
SET rule_key = 'image',
display_name = '图像',
resource_type = 'image',
unit = 'image',
base_price = 10,
base_weight = '{"meter":"count"}'::jsonb,
dynamic_weight = '{"resolutionFactors":{"1K":1,"2K":1.5,"3K":1.75,"4K":2,"8K":4},"qualityFactors":{"low":0.5,"medium":1,"high":1.5}}'::jsonb,
calculator_type = 'unit_weight',
dimension_schema = '{"dimensions":["count","resolution","quality"],"defaults":{"count":1,"quality":"medium","resolution":"1K"}}'::jsonb,
formula_config = '{"formula":"count * base_price * resolution_factor * quality_factor"}'::jsonb,
priority = 30,
metadata = metadata || '{"migration":"0008_pricing_image_single_rule"}'::jsonb,
updated_at = now()
WHERE resource_type = 'image'
AND rule_key IN ('image_generation', 'image');