Skip to content

Let's use AI to Earn!

wenshengtu

bulaienaofutuojiesenzhang2c1b7024cc16
diff --git a/src/app/[lng]/material/ai-generate/page.tsx b/src/app/[lng]/material/ai-generate/page.tsx
index b57f1e52..c8b4d2d4 100644
--- a/src/app/[lng]/material/ai-generate/page.tsx
+++ b/src/app/[lng]/material/ai-generate/page.tsx
@@ -209,11 +209,11 @@ export default function AIGeneratePage() {
const [imageModels, setImageModels] = useState<any[]>([]);
const [videoModels, setVideoModels] = useState<any[]>([]);
- // 模型积分消耗映射
- const modelCreditCosts: Record<string, number> = {
- 'gpt-image-1': 1,
- 'doubao-seedream-3-0-t2i-250415': 2.6
- };
+ // 模型积分消耗映射 - 现在从接口获取,不再写死
+ // const modelCreditCosts: Record<string, number> = {
+ // 'gpt-image-1': 1,
+ // 'doubao-seedream-3-0-t2i-250415': 2.6
+ // };
// 视频模型积分消耗映射 - 按模型、时长、分辨率组合
const videoModelCreditCosts: Record<string, Record<number, Record<string, number>>> = {
@@ -702,7 +702,7 @@ export default function AIGeneratePage() {
style={{ width: "100%" }}
>
{imageModels.map((modelItem) => {
- const creditCost = modelCreditCosts[modelItem.name] || 0;
+ const creditCost = modelItem.pricing ? parseFloat(modelItem.pricing) : 0;
return (
<Option key={modelItem.name} value={modelItem.name}>
{modelItem.name} {creditCost > 0 && `(${t('aiGenerate.estimatedCreditCost' as any)} ${creditCost} ${t('aiGenerate.credits' as any)})`}
@@ -711,13 +711,17 @@ export default function AIGeneratePage() {
})}
</Select>
)}
- {model && modelCreditCosts[model] && (
- <div className={styles.creditCostInfo}>
- <span style={{ color: '#1890ff', fontSize: '14px' }}>
- 💰 {t('aiGenerate.estimatedCreditCost' as any)}: {modelCreditCosts[model]} {t('aiGenerate.credits' as any)}
- </span>
- </div>
- )}
+ {model && (() => {
+ const selectedModel = imageModels.find(m => m.name === model);
+ const creditCost = selectedModel?.pricing ? parseFloat(selectedModel.pricing) : 0;
+ return creditCost > 0 ? (
+ <div className={styles.creditCostInfo}>
+ <span style={{ color: '#1890ff', fontSize: '14px' }}>
+ 💰 {t('aiGenerate.estimatedCreditCost' as any)}: {creditCost} {t('aiGenerate.credits' as any)}
+ </span>
+ </div>
+ ) : null;
+ })()}
<Button
type="primary"
onClick={handleTextToImage}
diff --git a/src/app/[lng]/material/ai-generate/price-integration.test.ts b/src/app/[lng]/material/ai-generate/price-integration.test.ts
new file mode 100644
index 00000000..29dc2c94
--- /dev/null
+++ b/src/app/[lng]/material/ai-generate/price-integration.test.ts
@@ -0,0 +1,69 @@
+// 测试文生图价格集成
+describe('AI Generate Price Integration', () => {
+ it('should use pricing from API response instead of hardcoded values', () => {
+ // 模拟接口返回的数据
+ const mockImageModels = [
+ {
+ name: "gpt-image-1",
+ description: "gpt-image-1",
+ pricing: "1",
+ qualities: ["high", "medium", "low"],
+ sizes: ["1024x1024", "1536x1024", "1024x1536", "auto"],
+ styles: []
+ },
+ {
+ name: "doubao-seedream-3-0-t2i-250415",
+ description: "doubao-seedream-3-0-t2i-250415",
+ pricing: "2.6",
+ qualities: ["high", "medium", "low"],
+ sizes: ["1024x1024", "1536x1024", "1024x1536", "auto"],
+ styles: []
+ }
+ ];
+
+ // 测试价格解析
+ mockImageModels.forEach(model => {
+ const creditCost = model.pricing ? parseFloat(model.pricing) : 0;
+ expect(creditCost).toBeGreaterThan(0);
+ expect(typeof creditCost).toBe('number');
+ });
+
+ // 测试第一个模型的价格
+ const firstModel = mockImageModels[0];
+ const firstModelPrice = parseFloat(firstModel.pricing);
+ expect(firstModelPrice).toBe(1);
+
+ // 测试第二个模型的价格
+ const secondModel = mockImageModels[1];
+ const secondModelPrice = parseFloat(secondModel.pricing);
+ expect(secondModelPrice).toBe(2.6);
+ });
+
+ it('should handle missing pricing gracefully', () => {
+ const modelWithoutPricing = {
+ name: "test-model",
+ description: "test-model",
+ // pricing 字段缺失
+ qualities: ["high", "medium", "low"],
+ sizes: ["1024x1024"],
+ styles: []
+ };
+
+ const creditCost = modelWithoutPricing.pricing ? parseFloat(modelWithoutPricing.pricing) : 0;
+ expect(creditCost).toBe(0);
+ });
+
+ it('should handle invalid pricing gracefully', () => {
+ const modelWithInvalidPricing = {
+ name: "test-model",
+ description: "test-model",
+ pricing: "invalid",
+ qualities: ["high", "medium", "low"],
+ sizes: ["1024x1024"],
+ styles: []
+ };
+
+ const creditCost = modelWithInvalidPricing.pricing ? parseFloat(modelWithInvalidPricing.pricing) : 0;
+ expect(isNaN(creditCost)).toBe(true);
+ });
+});