-- ============================================================
-- 腾讯混元大模型接入: Hunyuan via tokenhub.tencentmaas.com
-- 
-- 模型:
--   1. hy3                     — 混元 Hy3 (旗舰对话模型)
--   2. hy-vision-2.0-instruct  — HY-Vision 2.0 (视觉理解)
--   3. hy-image-3.0-plus      — HY Image 3.0 Plus (文生图)
--   4. hy-video-1.5-i2v       — HY Video 1.5 I2V (图生视频)
--   5. hy-video-1.5-t2v       — HY Video 1.5 T2V (文生视频)
--
-- 定价来源: 腾讯官方文档 https://cloud.tencent.com/document/product/1823/130080
-- Provider: 腾讯 (wNME9nrITooowlmCuR_XB)
-- Upapp: hunyun (5QXZ-AMP0K0NrcpZiTomA, baseurl: https://tokenhub.tencentmaas.com/v1)
-- ============================================================

-- ===================== Part 1: llm =====================
INSERT INTO llm (id,name,model,description,iconid,upappid,providerid,ownerid,enabled_date,expired_date,min_balance,status) VALUES
('llm_hunyuan_hy3','hy3','hy3','混元 Hy3 — 旗舰对话模型，295B参数，128K上下文',NULL,'5QXZ-AMP0K0NrcpZiTomA','wNME9nrITooowlmCuR_XB','0','2025-01-01','2099-12-31',0.00,'published'),
('llm_hunyuan_vision2','hy-vision-2.0-instruct','hy-vision-2.0-instruct','HY-Vision 2.0 — 视觉理解模型，406B参数',NULL,'5QXZ-AMP0K0NrcpZiTomA','wNME9nrITooowlmCuR_XB','0','2025-01-01','2099-12-31',0.00,'published'),
('llm_hunyuan_image3','hy-image-3.0-plus','hy-image-v3.0','HY Image 3.0 Plus — 文生图模型',NULL,'5QXZ-AMP0K0NrcpZiTomA','wNME9nrITooowlmCuR_XB','0','2025-01-01','2099-12-31',0.00,'published'),
('llm_hunyuan_video_i2v','hy-video-1.5-i2v','hy-video-1.5','HY Video 1.5 — 图生视频',NULL,'5QXZ-AMP0K0NrcpZiTomA','wNME9nrITooowlmCuR_XB','0','2025-01-01','2099-12-31',0.00,'published'),
('llm_hunyuan_video_t2v','hy-video-1.5-t2v','hy-video-1.5','HY Video 1.5 — 文生视频',NULL,'5QXZ-AMP0K0NrcpZiTomA','wNME9nrITooowlmCuR_XB','0','2025-01-01','2099-12-31',0.00,'published')
ON DUPLICATE KEY UPDATE model=VALUES(model), description=VALUES(description);

-- ===================== Part 2: llm_api_map =====================
INSERT INTO llm_api_map (id,llmid,llmcatelogid,apiname,query_apiname,query_period,ppid,isdefaultcatelog) VALUES
('map_hunyuan_hy3','llm_hunyuan_hy3','t2t','t2t',NULL,NULL,'pp_hunyuan_hy3','1'),
('map_hunyuan_vision2','llm_hunyuan_vision2','vision','ti2t',NULL,NULL,'pp_hunyuan_vision2','1'),
('map_hunyuan_image3','llm_hunyuan_image3','t2i','hunyuan-image-tokenhub',NULL,NULL,'pp_hunyuan_image3','1'),
('map_hunyuan_video_i2v','llm_hunyuan_video_i2v','t2v','t2t',NULL,NULL,'pp_hunyuan_video_i2v','1'),
('map_hunyuan_video_t2v','llm_hunyuan_video_t2v','t2v','t2t',NULL,NULL,'pp_hunyuan_video_t2v','1')
ON DUPLICATE KEY UPDATE apiname=VALUES(apiname), ppid=VALUES(ppid);

-- ===================== Part 3: uapiio =====================
INSERT INTO uapiio (id,name,description,input_fields) VALUES
('hunyuan_chat_io','混元文本对话','文本对话输入输出','[{"name":"prompt","label":"用户输入","uitype":"text","required":true},{"name":"sys_prompt","label":"系统提示词","uitype":"text","required":false},{"name":"image_file","label":"图像URL","uitype":"image","required":false},{"name":"max_tokens","label":"最大输出Token","uitype":"number","required":false,"default":1024},{"name":"stream","label":"流式输出","uitype":"switch","required":false}]'),
('hunyuan_vision_io','混元视觉理解','视觉理解输入输出','[{"name":"prompt","label":"用户输入","uitype":"text","required":true},{"name":"image_file","label":"图像URL","uitype":"image","required":true},{"name":"sys_prompt","label":"系统提示词","uitype":"text","required":false},{"name":"max_tokens","label":"最大输出Token","uitype":"number","required":false,"default":1024}]'),
('hunyuan_image_io','混元图像生成','文生图输入输出','[{"name":"prompt","label":"图像描述","uitype":"text","required":true},{"name":"size","label":"图像尺寸","uitype":"text","required":false,"default":"1024x1024"},{"name":"n","label":"生成数量","uitype":"number","required":false,"default":1}]'),
('hunyuan_video_i2v_io','混元图生视频','图生视频输入输出','[{"name":"image_file","label":"输入图像","uitype":"image","required":true},{"name":"prompt","label":"视频描述","uitype":"text","required":false},{"name":"duration","label":"视频时长(秒)","uitype":"number","required":false,"default":5},{"name":"resolution","label":"分辨率","uitype":"text","required":false,"default":"720P"}]'),
('hunyuan_video_t2v_io','混元文生视频','文生视频输入输出','[{"name":"prompt","label":"视频描述","uitype":"text","required":true},{"name":"duration","label":"视频时长(秒)","uitype":"number","required":false,"default":5},{"name":"resolution","label":"分辨率","uitype":"text","required":false,"default":"720P"}]')
ON DUPLICATE KEY UPDATE description=VALUES(description),input_fields=VALUES(input_fields);

-- Link existing uapi to uapiio
UPDATE uapi SET ioid='hunyuan_chat_io' WHERE id='AP29-fYCll4l-byxm3DHN' AND upappid='5QXZ-AMP0K0NrcpZiTomA';
UPDATE uapi SET ioid='hunyuan_vision_io' WHERE id='qStjXm_Meu0nBjiRzdPew' AND upappid='5QXZ-AMP0K0NrcpZiTomA';

-- ===================== Part 4: image uapi (tokenhub) =====================
INSERT INTO uapi (id,name,title,description,need_auth,stream,path,httpmethod,headers,data,response,ioid,upappid) VALUES
('uapi_hunyuan_tokenhub_image','hunyuan-image-tokenhub','混元Image','Hunyuan Image via TokenHub','0','async','/images/generations','POST',
'{"Content-Type":"application/json"}',
'{"model":"{{model}}","prompt":{{json.dumps(prompt,ensure_ascii=False)}}{%if size%},"size":"{{size}}"{%endif%}{%if n%},"n":{{n}}{%endif%}}',
'{"taskid":"{{id}}","taskstatus":"PENDING","status":"PENDING"}',
'hunyuan_image_io','5QXZ-AMP0K0NrcpZiTomA')
ON DUPLICATE KEY UPDATE data=VALUES(data),response=VALUES(response);

-- ===================== Part 5: pricing_program =====================
INSERT INTO pricing_program (id,name,ownerid,providerid,pricing_belong,description) VALUES
('pp_hunyuan_hy3','混元Hy3旗舰对话',NULL,'wNME9nrITooowlmCuR_XB',NULL,'295B参数·128K上下文·按token计费'),
('pp_hunyuan_vision2','HY-Vision 2.0视觉',NULL,'wNME9nrITooowlmCuR_XB',NULL,'406B参数·视觉理解·按token计费'),
('pp_hunyuan_image3','HY Image V3.0',NULL,'wNME9nrITooowlmCuR_XB',NULL,'文生图·0.2元/张'),
('pp_hunyuan_video_i2v','HY Video 1.5',NULL,'wNME9nrITooowlmCuR_XB',NULL,'视频生成·1.5元/次(积分)'),
('pp_hunyuan_video_t2v','HY Video 1.5',NULL,'wNME9nrITooowlmCuR_XB',NULL,'视频生成·1.5元/次(积分)')
ON DUPLICATE KEY UPDATE name=VALUES(name);

-- ===================== Part 6: pricing_program_timing =====================
INSERT INTO pricing_program_timing (id,ppid,name,pricing_data,enabled_date,expired_date) VALUES
('pt_hunyuan_hy3','pp_hunyuan_hy3','混元Hy3定价',
'unit_values:\n  completion_tokens: 1000\n  prompt_tokens: 1000\nfields:\n  price_factors:\n    type: string\n    role: factor\n    label: 计价因子\n  unit_prices:\n    type: float\n    role: factor\n    label: 单位定价\n  unit:\n    type: string\n    role: factor\n    label: 计价单位\npricings:\n- price_factors: completion_tokens\n  unit_prices: 0.004\n  unit: 1K tokens\n- price_factors: prompt_tokens\n  unit_prices: 0.001\n  unit: 1K tokens',
'2025-01-01','9999-12-31'),

('pt_hunyuan_vision2','pp_hunyuan_vision2','HY-Vision 2.0定价',
'unit_values:\n  completion_tokens: 1000\n  prompt_tokens: 1000\nfields:\n  price_factors:\n    type: string\n    role: factor\n    label: 计价因子\n  unit_prices:\n    type: float\n    role: factor\n    label: 单位定价\n  unit:\n    type: string\n    role: factor\n    label: 计价单位\npricings:\n- price_factors: completion_tokens\n  unit_prices: 0.0175\n  unit: 1K tokens\n- price_factors: prompt_tokens\n  unit_prices: 0.0075\n  unit: 1K tokens',
'2025-01-01','9999-12-31'),

('pt_hunyuan_image3','pp_hunyuan_image3','HY Image V3.0定价',
'unit_values:\n  image_count: 1\nfields:\n  price_factors:\n    type: string\n    role: factor\n    label: 计价因子\n  unit_prices:\n    type: float\n    role: factor\n    label: 单位定价\n  unit:\n    type: string\n    role: factor\n    label: 计价单位\npricings:\n- price_factors: image_count\n  unit_prices: 0.2\n  unit: image_count',
'2025-01-01','9999-12-31'),

('pt_hunyuan_video_i2v','pp_hunyuan_video_i2v','HY-Video 1.5定价',
'unit_values:\n  video_count: 1\nfields:\n  price_factors:\n    type: string\n    role: factor\n    label: 计价因子\n  unit_prices:\n    type: float\n    role: factor\n    label: 单位定价\n  unit:\n    type: string\n    role: factor\n    label: 计价单位\npricings:\n- price_factors: video_count\n  unit_prices: 1.5\n  unit: video_count',
'2025-01-01','9999-12-31'),

('pt_hunyuan_video_t2v','pp_hunyuan_video_t2v','HY-Video 1.5定价',
'unit_values:\n  video_count: 1\nfields:\n  price_factors:\n    type: string\n    role: factor\n    label: 计价因子\n  unit_prices:\n    type: float\n    role: factor\n    label: 单位定价\n  unit:\n    type: string\n    role: factor\n    label: 计价单位\npricings:\n- price_factors: video_count\n  unit_prices: 1.5\n  unit: video_count',
'2025-01-01','9999-12-31')
ON DUPLICATE KEY UPDATE ppid=VALUES(ppid), pricing_data=VALUES(pricing_data);
