kuaishou_kling_task.md 4.4 KB

快手可灵AI工具封装任务书

工具标识

  • tool_id: kuaishou_kling
  • 工具名称: 快手可灵AI生成工具
  • 工具描述: 支持AI视频生成、AI图片生成、AI对口型等功能的统一接口

功能需求

1. AI视频生成 (aiVideo)

  • 支持文本生成视频
  • 支持图片生成视频
  • 支持首尾帧模式
  • 支持自动添加音频

2. AI图片生成 (aiImage)

  • 文本生成图片
  • 支持多张图片生成(1-4张)
  • 支持负面提示词

3. AI对口型 (aiLipSync)

  • 文本转对口型视频
  • 音频转对口型视频
  • 支持自定义音色

输入Schema

{
  "type": "object",
  "properties": {
    "biz_type": {
      "type": "string",
      "enum": ["aiImage", "aiVideo", "aiLipSync"],
      "description": "业务类型"
    },
    "action": {
      "type": "string",
      "description": "动作类型"
    },
    "prompt": {
      "type": "string",
      "description": "生成内容的提示词"
    },
    "negative_prompt": {
      "type": "string",
      "description": "不希望呈现的内容"
    },
    "cfg": {
      "type": "string",
      "default": "50",
      "description": "创意想象力与创意相关性比例"
    },
    "mode": {
      "type": "string",
      "enum": ["text2video", "audio2video"],
      "description": "生成模式"
    },
    "image_url": {
      "type": "string",
      "description": "参考图片地址"
    },
    "aspect_ratio": {
      "type": "string",
      "enum": ["9:16", "16:9", "1:1"],
      "default": "16:9",
      "description": "长宽比"
    },
    "task_id": {
      "type": "string",
      "description": "查询任务状态时使用"
    },
    "cookie": {
      "type": "string",
      "description": "认证Cookie"
    },
    "version": {
      "type": "string",
      "description": "模型版本"
    },
    "image_count": {
      "type": "integer",
      "default": 4,
      "description": "生成图片数量(1-4)"
    },
    "add_audio": {
      "type": "boolean",
      "default": false,
      "description": "是否自动添加音频"
    },
    "start_frame_image": {
      "type": "string",
      "description": "首帧图片URL"
    },
    "end_frame_image": {
      "type": "string",
      "description": "尾帧图片URL"
    },
    "video_id": {
      "type": "string",
      "description": "视频ID(对口型用)"
    },
    "video_url": {
      "type": "string",
      "description": "视频URL(对口型用)"
    },
    "text": {
      "type": "string",
      "description": "对口型文本内容"
    },
    "voice_id": {
      "type": "string",
      "description": "音色ID"
    },
    "voice_language": {
      "type": "string",
      "enum": ["zh", "en"],
      "default": "zh",
      "description": "音色语种"
    },
    "voice_speed": {
      "type": "number",
      "default": 1.0,
      "description": "语速"
    },
    "audio_type": {
      "type": "string",
      "enum": ["file", "url"],
      "description": "音频类型"
    },
    "audio_file": {
      "type": "string",
      "description": "音频文件路径"
    },
    "audio_url": {
      "type": "string",
      "description": "音频URL"
    }
  },
  "required": ["biz_type"]
}

输出Schema

{
  "type": "object",
  "properties": {
    "task_id": {
      "type": "string",
      "description": "任务ID"
    },
    "status": {
      "type": "string",
      "enum": ["process", "finished", "failed"],
      "description": "任务状态"
    },
    "result": {
      "type": "object",
      "description": "生成结果",
      "properties": {
        "images": {
          "type": "array",
          "items": {"type": "string"},
          "description": "图片URL列表"
        },
        "videos": {
          "type": "array",
          "items": {"type": "string"},
          "description": "视频URL列表"
        }
      }
    },
    "error": {
      "type": "string",
      "description": "错误信息"
    }
  }
}

实现要求

  1. 技术栈: Python 3.12+, FastAPI, uvicorn, httpx
  2. API端点:
    • POST /generate - 创建生成任务
    • GET /status/{task_id} - 查询任务状态
  3. 错误处理: 参数验证、API调用失败、超时处理
  4. 日志: 记录请求参数和响应
  5. 环境: 使用uv创建Python环境
  6. 端口: 默认8000,支持命令行参数指定

参考实现

  • 参考项目中其他工具的FastAPI结构
  • 使用Pydantic模型进行参数验证
  • 实现异步HTTP调用