feat: 集成 KieAI Grok 模型,支持 field103 配置切换视频生成模型
- 新增 ToolGrokService 接口和 ToolGrokServiceImpl 实现 - 对接 https://kie.ai/grok-imagine 文生视频和图生视频接口 - 新增 KieAIConfig.grokBaseUrl 配置项 - 修改 KieAIController,根据 system_config.field103 自动切换 Sora/Grok - 原有 /text-to-video 和 /image-to-video 接口支持自动模型选择 - 新增 /grok/text-to-video 和 /grok/image-to-video 专用接口 配置说明: - eb_system_config.name=field103, value=grok 时使用 Grok - value=sora 或空时使用 Sora(默认)
This commit is contained in:
@@ -10,6 +10,8 @@ import com.zbkj.common.response.kieai.KieAINanoBananaResponse;
|
||||
import com.zbkj.common.response.kieai.KieAIQueryTaskResponse;
|
||||
import com.zbkj.common.response.kieai.KieAIVideoTaskStatus;
|
||||
import com.zbkj.common.result.CommonResult;
|
||||
import com.zbkj.service.service.SystemConfigService;
|
||||
import com.zbkj.service.service.tool.ToolGrokService;
|
||||
import com.zbkj.service.service.tool.ToolKieAIService;
|
||||
import com.zbkj.service.service.tool.ToolSora2Service;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -22,6 +24,8 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.util.Map;
|
||||
@@ -48,6 +52,12 @@ public class KieAIController {
|
||||
@Autowired
|
||||
private ToolSora2Service toolSora2Service;
|
||||
|
||||
@Autowired
|
||||
private ToolGrokService toolGrokService;
|
||||
|
||||
@Autowired
|
||||
private SystemConfigService systemConfigService;
|
||||
|
||||
@Autowired
|
||||
private KieAIConfig kieAIConfig;
|
||||
|
||||
@@ -190,7 +200,7 @@ public class KieAIController {
|
||||
// ==================== Sora2 视频生成接口(复刻自 models-integration) ====================
|
||||
|
||||
/**
|
||||
* 创建文生视频任务
|
||||
* 创建文生视频任务(打卡视频上传根据 system_config 表 field103 切换模型:grok 用 Grok,其他用 Sora)
|
||||
*/
|
||||
@PostMapping("/text-to-video")
|
||||
@ApiOperation(value = "创建文生视频任务", notes = "通过文本描述创建视频生成任务")
|
||||
@@ -201,11 +211,23 @@ public class KieAIController {
|
||||
if (input == null || input.getPrompt() == null || input.getPrompt().isEmpty()) {
|
||||
return CommonResult.failed("prompt参数不能为空");
|
||||
}
|
||||
String taskId = toolSora2Service.createTextToVideoTask(
|
||||
request.getTenant_id(), request.getTitle(), input.getPrompt(),
|
||||
input.getAspect_ratio(), input.getN_frames(), input.getRemove_watermark(),
|
||||
request.getCallBackUrl(), request.getApi_key(),
|
||||
request.getUid(), request.getNickname());
|
||||
String field103 = null;
|
||||
try {
|
||||
field103 = systemConfigService.getValueByKey("field103");
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
boolean useGrok = StrUtil.isNotBlank(field103) && "grok".equalsIgnoreCase(field103.trim());
|
||||
String taskId = useGrok
|
||||
? toolGrokService.createTextToVideoTask(
|
||||
request.getTenant_id(), request.getTitle(), input.getPrompt(),
|
||||
input.getAspect_ratio(), input.getN_frames(), input.getRemove_watermark(),
|
||||
request.getCallBackUrl(), request.getApi_key(),
|
||||
request.getUid(), request.getNickname())
|
||||
: toolSora2Service.createTextToVideoTask(
|
||||
request.getTenant_id(), request.getTitle(), input.getPrompt(),
|
||||
input.getAspect_ratio(), input.getN_frames(), input.getRemove_watermark(),
|
||||
request.getCallBackUrl(), request.getApi_key(),
|
||||
request.getUid(), request.getNickname());
|
||||
if (taskId != null) {
|
||||
return CommonResult.success(taskId);
|
||||
}
|
||||
@@ -217,7 +239,7 @@ public class KieAIController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建图生视频任务
|
||||
* 创建图生视频任务(打卡视频上传根据 system_config 表 field103 切换模型:grok 用 Grok,其他用 Sora)
|
||||
*/
|
||||
@PostMapping("/image-to-video")
|
||||
@ApiOperation(value = "创建图生视频任务", notes = "通过图片URL创建视频生成任务")
|
||||
@@ -231,11 +253,23 @@ public class KieAIController {
|
||||
if (input.getImage_urls() == null || input.getImage_urls().length == 0) {
|
||||
return CommonResult.failed("image_urls参数不能为空");
|
||||
}
|
||||
String taskId = toolSora2Service.createImageToVideoTask(
|
||||
request.getTenant_id(), request.getTitle(), input.getPrompt(),
|
||||
input.getImage_urls(), input.getAspect_ratio(), input.getN_frames(), input.getRemove_watermark(),
|
||||
request.getCallBackUrl(), request.getApi_key(),
|
||||
request.getUid(), request.getNickname());
|
||||
String field103 = null;
|
||||
try {
|
||||
field103 = systemConfigService.getValueByKey("field103");
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
boolean useGrok = StrUtil.isNotBlank(field103) && "grok".equalsIgnoreCase(field103.trim());
|
||||
String taskId = useGrok
|
||||
? toolGrokService.createImageToVideoTask(
|
||||
request.getTenant_id(), request.getTitle(), input.getPrompt(),
|
||||
input.getImage_urls(), input.getAspect_ratio(), input.getN_frames(), input.getRemove_watermark(),
|
||||
request.getCallBackUrl(), request.getApi_key(),
|
||||
request.getUid(), request.getNickname())
|
||||
: toolSora2Service.createImageToVideoTask(
|
||||
request.getTenant_id(), request.getTitle(), input.getPrompt(),
|
||||
input.getImage_urls(), input.getAspect_ratio(), input.getN_frames(), input.getRemove_watermark(),
|
||||
request.getCallBackUrl(), request.getApi_key(),
|
||||
request.getUid(), request.getNickname());
|
||||
if (taskId != null) {
|
||||
return CommonResult.success(taskId);
|
||||
}
|
||||
@@ -246,6 +280,65 @@ public class KieAIController {
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== Grok 视频生成接口(https://kie.ai/grok-imagine) ====================
|
||||
|
||||
/**
|
||||
* Grok 创建文生视频任务
|
||||
*/
|
||||
@PostMapping("/grok/text-to-video")
|
||||
@ApiOperation(value = "Grok创建文生视频任务", notes = "通过文本描述创建Grok视频生成任务")
|
||||
public CommonResult<String> createGrokTextToVideoTask(@RequestBody Sora2Request request) {
|
||||
try {
|
||||
logger.info("Grok创建文生视频任务,参数:{}", request);
|
||||
Sora2Request.Input input = request.getInput();
|
||||
if (input == null || input.getPrompt() == null || input.getPrompt().isEmpty()) {
|
||||
return CommonResult.failed("prompt参数不能为空");
|
||||
}
|
||||
String taskId = toolGrokService.createTextToVideoTask(
|
||||
request.getTenant_id(), request.getTitle(), input.getPrompt(),
|
||||
input.getAspect_ratio(), input.getN_frames(), input.getRemove_watermark(),
|
||||
request.getCallBackUrl(), request.getApi_key(),
|
||||
request.getUid(), request.getNickname());
|
||||
if (taskId != null) {
|
||||
return CommonResult.success(taskId);
|
||||
}
|
||||
return CommonResult.failed("Grok创建文生视频任务失败");
|
||||
} catch (Exception e) {
|
||||
logger.error("Grok创建文生视频任务失败:{}", e.getMessage(), e);
|
||||
return CommonResult.failed("Grok创建文生视频任务失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Grok 创建图生视频任务
|
||||
*/
|
||||
@PostMapping("/grok/image-to-video")
|
||||
@ApiOperation(value = "Grok创建图生视频任务", notes = "通过图片URL创建Grok视频生成任务")
|
||||
public CommonResult<String> createGrokImageToVideoTask(@RequestBody Sora2Request request) {
|
||||
try {
|
||||
logger.info("Grok创建图生视频任务,参数:{}", request);
|
||||
Sora2Request.Input input = request.getInput();
|
||||
if (input == null || input.getPrompt() == null || input.getPrompt().isEmpty()) {
|
||||
return CommonResult.failed("prompt参数不能为空");
|
||||
}
|
||||
if (input.getImage_urls() == null || input.getImage_urls().length == 0) {
|
||||
return CommonResult.failed("image_urls参数不能为空");
|
||||
}
|
||||
String taskId = toolGrokService.createImageToVideoTask(
|
||||
request.getTenant_id(), request.getTitle(), input.getPrompt(),
|
||||
input.getImage_urls(), input.getAspect_ratio(), input.getN_frames(), input.getRemove_watermark(),
|
||||
request.getCallBackUrl(), request.getApi_key(),
|
||||
request.getUid(), request.getNickname());
|
||||
if (taskId != null) {
|
||||
return CommonResult.success(taskId);
|
||||
}
|
||||
return CommonResult.failed("Grok创建图生视频任务失败");
|
||||
} catch (Exception e) {
|
||||
logger.error("Grok创建图生视频任务失败:{}", e.getMessage(), e);
|
||||
return CommonResult.failed("Grok创建图生视频任务失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建专业版本文生视频任务
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user