Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat(video): extract prompt from request in VideoService and update response schema (#275)
Sakura9d4f32b6d912
diff --git a/project/backend/apps/aitoearn-server/config/config.js b/project/backend/apps/aitoearn-server/config/config.jsindex dc76e96a..31a5ae56 100644--- a/project/backend/apps/aitoearn-server/config/config.js+++ b/project/backend/apps/aitoearn-server/config/config.js@@ -232,6 +232,17 @@ module.exports = {completion: '0.166',},},+ {+ name: 'gemini-3-pro-image-preview',+ description: 'Nano Banana Pro',+ tags: ['VIP Free'],+ inputModalities: ['text', 'image'],+ outputModalities: ['image'],+ pricing: {+ price: '2',+ },+ freeForVip: true,+ },{name: 'gemini-2.5-flash-image',description: 'Nano Banana',diff --git a/project/backend/apps/aitoearn-server/src/ai/chat/chat.service.ts b/project/backend/apps/aitoearn-server/src/ai/chat/chat.service.tsindex f4b9243f..b36b19d9 100644--- a/project/backend/apps/aitoearn-server/src/ai/chat/chat.service.ts+++ b/project/backend/apps/aitoearn-server/src/ai/chat/chat.service.ts@@ -40,7 +40,7 @@ export class ChatService {const usage = result.usage_metadataif (!usage) {- throw new AppException(ResponseCode.AiCallFailed)+ throw new AppException(ResponseCode.AiCallFailed, { error: 'Missing usage metadata' })}return {diff --git a/project/backend/apps/aitoearn-server/src/ai/libs/fireflycard/fireflycard.service.ts b/project/backend/apps/aitoearn-server/src/ai/libs/fireflycard/fireflycard.service.tsindex 6f68f44c..280f2c55 100644--- a/project/backend/apps/aitoearn-server/src/ai/libs/fireflycard/fireflycard.service.ts+++ b/project/backend/apps/aitoearn-server/src/ai/libs/fireflycard/fireflycard.service.ts@@ -123,7 +123,8 @@ export class FireflycardService {})if (!response.ok) {- throw new AppException(ResponseCode.AiCallFailed)+ const errorText = await response.text().catch(() => 'Unknown error')+ throw new AppException(ResponseCode.AiCallFailed, { error: `HTTP ${response.status}: ${errorText}` })}return responsediff --git a/project/backend/apps/aitoearn-server/src/ai/libs/kling/kling.service.ts b/project/backend/apps/aitoearn-server/src/ai/libs/kling/kling.service.tsindex 22ec0cef..e0e0c66d 100644--- a/project/backend/apps/aitoearn-server/src/ai/libs/kling/kling.service.ts+++ b/project/backend/apps/aitoearn-server/src/ai/libs/kling/kling.service.ts@@ -108,7 +108,7 @@ export class KlingService {data: response.data,msg: '可灵 api 调用失败',})- throw new AppException(ResponseCode.AiCallFailed, klingResponse.message)+ throw new AppException(ResponseCode.AiCallFailed, { error: klingResponse.message || 'Unknown error' })}return response}diff --git a/project/backend/apps/aitoearn-server/src/ai/libs/md2card/md2card.service.ts b/project/backend/apps/aitoearn-server/src/ai/libs/md2card/md2card.service.tsindex 61f8efb6..46133d82 100644--- a/project/backend/apps/aitoearn-server/src/ai/libs/md2card/md2card.service.ts+++ b/project/backend/apps/aitoearn-server/src/ai/libs/md2card/md2card.service.ts@@ -37,7 +37,7 @@ export class Md2cardService {}catch (error: any) {this.logger.error(`MD2Card API 调用失败: ${error.message}`)- throw new AppException(ResponseCode.AiCallFailed)+ throw new AppException(ResponseCode.AiCallFailed, { error: error.message || 'Unknown error' })}}}diff --git a/project/backend/apps/aitoearn-server/src/ai/video/video.service.ts b/project/backend/apps/aitoearn-server/src/ai/video/video.service.tsindex a0ec1f58..45ef3cfe 100644--- a/project/backend/apps/aitoearn-server/src/ai/video/video.service.ts+++ b/project/backend/apps/aitoearn-server/src/ai/video/video.service.ts@@ -373,7 +373,40 @@ export class VideoService {return createTaskResponse(result.id)}+ /**+ * 从请求数据中提取 prompt+ */+ private extractPromptFromRequest(aiLog: AiLog): string | undefined {+ const request = aiLog.request as any+ if (!request) {+ return undefined+ }++ switch (aiLog.channel) {+ case AiLogChannel.Kling:+ return request.prompt+ case AiLogChannel.Volcengine:+ if (request.content && Array.isArray(request.content)) {+ const textContent = request.content.find((c: any) => c.type === ContentType.Text)+ if (textContent && 'text' in textContent) {+ // 使用 parseModelTextCommand 解析出纯 prompt+ const { prompt } = parseModelTextCommand(textContent.text)+ return prompt+ }+ }+ return undefined+ case AiLogChannel.Dashscope:+ return request.input?.prompt+ case AiLogChannel.Sora2:+ return request.prompt+ default:+ return undefined+ }+ }+async transformToCommonResponse(aiLog: AiLog) {+ const prompt = this.extractPromptFromRequest(aiLog)+if (aiLog.status === AiLogStatus.Generating) {return {task_id: aiLog.id,@@ -384,6 +417,7 @@ export class VideoService {start_time: Math.floor(aiLog.startedAt.getTime() / 1000),finish_time: 0,progress: '30%',+ prompt,data: {},}}@@ -401,6 +435,7 @@ export class VideoService {start_time: Math.floor(aiLog.startedAt.getTime() / 1000),finish_time: Math.floor((aiLog.startedAt.getTime() + (aiLog.duration || 0)) / 1000),progress: '100%',+ prompt,data: {},}@@ -765,7 +800,8 @@ export class VideoService {async volcengineCreate(request: VolcengineGenerationRequestDto) {const { userId, userType, model, content, ...params } = request- const prompt = content.find(c => c.type === ContentType.Text)?.text+ const textContent = content.find(c => c.type === ContentType.Text)+ const prompt = textContent && 'text' in textContent ? textContent.text : undefinedif (!prompt) {throw new BadRequestException('prompt is required')diff --git a/project/backend/apps/aitoearn-server/src/ai/video/video.vo.ts b/project/backend/apps/aitoearn-server/src/ai/video/video.vo.tsindex 9d379c51..b56137e3 100644--- a/project/backend/apps/aitoearn-server/src/ai/video/video.vo.ts+++ b/project/backend/apps/aitoearn-server/src/ai/video/video.vo.ts@@ -94,6 +94,7 @@ const videoTaskStatusResponseSchema = z.object({start_time: z.number().describe('开始时间'),finish_time: z.number().describe('完成时间'),progress: z.string().describe('任务进度'),+ prompt: z.string().optional().describe('提示词'),data: z.any(),})diff --git a/project/backend/libs/common/src/i18n/messages.ts b/project/backend/libs/common/src/i18n/messages.tsindex c2cdde90..b9fdc21a 100644--- a/project/backend/libs/common/src/i18n/messages.ts+++ b/project/backend/libs/common/src/i18n/messages.ts@@ -85,8 +85,8 @@ export const messages: Record<ResponseCode, Record<Locale, MessageValue>> = {'zh-CN': '无效的 AI 模型',},[ResponseCode.AiCallFailed]: {- 'en-US': 'AI call failed',- 'zh-CN': 'AI 调用失败',+ 'en-US': template.compile('AI call failed: {{error}}'),+ 'zh-CN': template.compile('AI 调用失败:{{error}}'),},[ResponseCode.InvalidAiTaskId]: {'en-US': 'Invalid AI task ID',