初始化提交

This commit is contained in:
2025-12-14 15:40:49 +08:00
commit 410b2f068d
72 changed files with 10460 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
# Nano Banana 模型配置
import os
# 价格配置 (CNY per call)
IMAGE_GENERATION_PRICE = float(os.getenv('IMAGE_GENERATION_PRICE', 0.15))
# API 配置 (优先从环境变量获取)
def get_config():
return {
'api_url': os.getenv('NANO_BANANA_API_URL', 'https://api.nanobanana.com/v1'),
'api_key': os.getenv('NANO_BANANA_API_KEY')
}

View File

@@ -0,0 +1,26 @@
from ..base import ModelService
from .config import IMAGE_GENERATION_PRICE, get_config
from typing import Dict, Any, Tuple, Generator, Union
import logging
logger = logging.getLogger(__name__)
class NanoBananaService(ModelService):
def get_api_config(self) -> Tuple[str, str]:
config = get_config()
return config['api_url'], config['api_key']
def check_balance(self, balance: float) -> Tuple[bool, float, str]:
if balance < IMAGE_GENERATION_PRICE:
return False, IMAGE_GENERATION_PRICE, f'余额不足。当前余额: {balance}, 需要: {IMAGE_GENERATION_PRICE}'
return True, IMAGE_GENERATION_PRICE, ""
def calculate_cost(self, usage: Dict[str, Any] = None, stream: bool = False) -> float:
# 固定按次计费
return IMAGE_GENERATION_PRICE
def prepare_payload(self, data: Dict[str, Any]) -> Dict[str, Any]:
return {k: v for k, v in data.items() if k not in ['user']}
def handle_response(self, response, stream: bool) -> Union[Dict[str, Any], Generator]:
pass