NENGYONGLE
This commit is contained in:
parent
5c07291f11
commit
740abd06a1
Binary file not shown.
@ -16,9 +16,9 @@ class PosterGenerateRequest(BaseModel):
|
||||
templateId: str = Field("vibrant", description="模板ID")
|
||||
imagesBase64: Optional[str] = Field(None, description="图像base64编码")
|
||||
posterContent: Optional[Dict[str, Any]] = Field(None, description="海报内容,如果提供则直接使用此内容")
|
||||
contentId: Optional[int] = Field(None, description="内容ID,用于AI生成内容")
|
||||
productId: Optional[int] = Field(None, description="产品ID,用于AI生成内容")
|
||||
scenicSpotId: Optional[int] = Field(None, description="景区ID,用于AI生成内容")
|
||||
contentId: Optional[str] = Field(None, description="内容ID,用于AI生成内容")
|
||||
productId: Optional[str] = Field(None, description="产品ID,用于AI生成内容")
|
||||
scenicSpotId: Optional[str] = Field(None, description="景区ID,用于AI生成内容")
|
||||
numVariations: int = Field(3, description="要生成的海报变体数量, 默认为3", ge=1, le=5)
|
||||
forceLlmGeneration: bool = Field(False, description="是否强制使用LLM重新生成内容")
|
||||
generatePsd: bool = Field(False, description="是否生成PSD分层文件")
|
||||
@ -33,9 +33,9 @@ class PosterGenerateRequest(BaseModel):
|
||||
"forceLlmGeneration":False,
|
||||
"generatePsd": True,
|
||||
"psdOutputPath": "custom_poster.psd",
|
||||
"contentId":1,
|
||||
"productId":1,
|
||||
"scenicSpotId":1,
|
||||
"contentId":"1",
|
||||
"productId":"1",
|
||||
"scenicSpotId":"1",
|
||||
"posterContent":{
|
||||
"title":"天津冒险湾",
|
||||
"slogan":"天津冒险湾,让你体验不一样的冒险之旅"
|
||||
|
||||
Binary file not shown.
@ -339,8 +339,8 @@ class PosterService:
|
||||
except Exception as e:
|
||||
logger.warning(f"更新模板统计失败: {e}")
|
||||
|
||||
async def _generate_content_with_llm(self, template_id: str, content_id: Optional[int],
|
||||
product_id: Optional[int], scenic_spot_id: Optional[int]) -> Optional[Dict[str, Any]]:
|
||||
async def _generate_content_with_llm(self, template_id: str, content_id: Optional[str],
|
||||
product_id: Optional[str], scenic_spot_id: Optional[str]) -> Optional[Dict[str, Any]]:
|
||||
"""使用LLM生成海报内容"""
|
||||
# 获取提示词 - 直接从数据库模板信息中获取
|
||||
template_info = self._templates.get(template_id, {})
|
||||
@ -354,14 +354,40 @@ class PosterService:
|
||||
|
||||
logger.info(f"成功加载模板 {template_id} 的提示词配置")
|
||||
|
||||
# 获取相关数据
|
||||
# 获取相关数据 - 将字符串ID转换为整数
|
||||
data = {}
|
||||
|
||||
def safe_int_convert(id_str: Optional[str]) -> Optional[int]:
|
||||
"""安全将字符串ID转换为整数"""
|
||||
if not id_str:
|
||||
return None
|
||||
try:
|
||||
# 如果ID包含非数字字符,只提取数字部分或返回None
|
||||
if id_str.isdigit():
|
||||
return int(id_str)
|
||||
else:
|
||||
# 对于类似 "generated_note_1753693091224_0" 的ID,提取数字部分
|
||||
import re
|
||||
numbers = re.findall(r'\d+', id_str)
|
||||
if numbers:
|
||||
return int(numbers[0]) # 使用第一个数字序列
|
||||
return None
|
||||
except (ValueError, TypeError):
|
||||
logger.warning(f"无法转换ID为整数: {id_str}")
|
||||
return None
|
||||
|
||||
if content_id:
|
||||
data['content'] = self.db_service.get_content_by_id(content_id)
|
||||
content_id_int = safe_int_convert(content_id)
|
||||
if content_id_int:
|
||||
data['content'] = self.db_service.get_content_by_id(content_id_int)
|
||||
if product_id:
|
||||
data['product'] = self.db_service.get_product_by_id(product_id)
|
||||
product_id_int = safe_int_convert(product_id)
|
||||
if product_id_int:
|
||||
data['product'] = self.db_service.get_product_by_id(product_id_int)
|
||||
if scenic_spot_id:
|
||||
data['scenic_spot'] = self.db_service.get_scenic_spot_by_id(scenic_spot_id)
|
||||
scenic_spot_id_int = safe_int_convert(scenic_spot_id)
|
||||
if scenic_spot_id_int:
|
||||
data['scenic_spot'] = self.db_service.get_scenic_spot_by_id(scenic_spot_id_int)
|
||||
|
||||
logger.info(f"获取到的数据: content={data.get('content') is not None}, product={data.get('product') is not None}, scenic_spot={data.get('scenic_spot') is not None}")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user