Merge remote-tracking branch 'origin/master-jdk21-ai' into master-jdk21-ai

This commit is contained in:
YunaiV 2024-05-10 22:48:58 +08:00
commit ba1333bdef
7 changed files with 82 additions and 17 deletions

View File

@ -49,8 +49,8 @@ public class AiImageDO extends BaseDO {
// ============ mj 需要字段
@Schema(description = "用户操作的消息编号(MJ返回)")
private String mjMessageId;
@Schema(description = "用户操作的Nonce编号(MJ返回)")
private String mjNonceId;
@Schema(description = "用户操作的操作编号(MJ返回)")
private String mjOperationId;

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.ai.dal.mysql;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
@ -17,4 +18,13 @@ import org.springframework.stereotype.Repository;
public interface AiImageMapper extends BaseMapperX<AiImageDO> {
/**
* 更新 - 根据 messageId
*
* @param mjNonceId
* @param aiImageDO
*/
default void updateByMjNonce(Long mjNonceId, AiImageDO aiImageDO) {
this.update(aiImageDO, new LambdaQueryWrapperX<AiImageDO>().eq(AiImageDO::getMjNonceId, mjNonceId));
}
}

View File

@ -145,7 +145,7 @@ public class AiImageServiceImpl implements AiImageService {
// 校验 OperateId 是否存在
AiImageMidjourneyOperationsVO midjourneyOperationsVO = validateMidjourneyOperationsExists(midjourneyOperations, req.getOperateId());
// 校验 messageId
validateMessageId(aiImageDO.getMjMessageId(), req.getMessageId());
validateMessageId(aiImageDO.getMjNonceId(), req.getMessageId());
// 获取 mjOperationName
String mjOperationName = midjourneyOperationsVO.getLabel();
// 保存一个 image 任务记录
@ -222,7 +222,7 @@ public class AiImageServiceImpl implements AiImageService {
aiImageDO.setDrawingImageUrl(drawingImageUrl);
aiImageDO.setDrawingErrorMessage(drawingErrorMessage);
//
aiImageDO.setMjMessageId(mjMessageId);
aiImageDO.setMjNonceId(mjMessageId);
aiImageDO.setMjOperationId(mjOperationId);
aiImageDO.setMjOperationName(mjOperationName);
aiImageMapper.insert(aiImageDO);

View File

@ -62,12 +62,11 @@ public class YuDaoMidjourneyMessageHandler implements MidjourneyMessageHandler {
private void errorHandler(MidjourneyMessage midjourneyMessage) {
// image 编号
Long aiImageId = Long.valueOf(midjourneyMessage.getNonce());
Long nonceId = Long.valueOf(midjourneyMessage.getNonce());
// 获取 error message
String errorMessage = getErrorMessage(midjourneyMessage);
aiImageMapper.updateById(
aiImageMapper.updateByMjNonce(nonceId,
new AiImageDO()
.setId(aiImageId)
.setDrawingErrorMessage(errorMessage)
.setDrawingStatus(AiImageDrawingStatusEnum.FAIL.getStatus())
);
@ -83,7 +82,8 @@ public class YuDaoMidjourneyMessageHandler implements MidjourneyMessageHandler {
private void successHandler(MidjourneyMessage midjourneyMessage) {
// 获取id
Long aiImageId = Long.valueOf(midjourneyMessage.getNonce());
Long nonceId = Long.valueOf(midjourneyMessage.getNonce());
// TODO @芋艿 这个地方有问题不能根据 nonce来更新不返回这个信息(别人获取了 image-xxx-xx 后面一段hash由于没有mj账号测试暂不清楚)
// 获取生成 url
String imageUrl = null;
if (CollUtil.isNotEmpty(midjourneyMessage.getAttachments())) {
@ -102,12 +102,11 @@ public class YuDaoMidjourneyMessageHandler implements MidjourneyMessageHandler {
// 获取 midjourneyOperations
List<AiImageMidjourneyOperationsVO> midjourneyOperations = getMidjourneyOperationsList(midjourneyMessage);
// 更新数据库
aiImageMapper.updateById(
aiImageMapper.updateByMjNonce(nonceId,
new AiImageDO()
.setId(aiImageId)
.setDrawingImageUrl(imageUrl)
.setDrawingStatus(drawingStatusEnum == null ? null : drawingStatusEnum.getStatus())
.setMjMessageId(midjourneyMessage.getId())
.setMjNonceId(midjourneyMessage.getId())
.setMjOperations(JsonUtils.toJsonString(midjourneyOperations))
);
}

View File

@ -20,5 +20,5 @@ Content-Type: application/json
Authorization: {{token}}
{
"prompt": "Cute cartoon style mobile game scene, a colorful camping car with an outdoor table and chairs next to it on the road in a spring forest, the simple structure of the camper van, soft lighting, C4D rendering, 3d model in the style of a cartoon, cute shape, a pastel color scheme, closeup view from the side angle, high resolution, bright colors, a happy atmosphere. --ar 1:2 --v 6.0"
"prompt": "Cute cartoon style mobile game scene, a colorful camping car with an outdoor table and chairs next to it on the road in a spring forest, the simple structure of the camper van, soft lighting, C4D rendering, 3d model in the style of a cartoon, cute shape, a pastel color scheme, closeup view from the side angle, high resolution, bright colors, a happy atmosphere."
}

View File

@ -0,0 +1,54 @@
{
"type": 2,
"application_id": "936929561302675456",
"guild_id": "1237948819677904956",
"channel_id": "1237948819677904960",
"session_id": "4bdb0c32158f625bbd7f0a54bfbb54aa",
"data": {
"version": "1237876415471554623",
"id": "938956540159881230",
"name": "imagine",
"type": 1,
"options": [
{
"type": 3,
"name": "prompt",
"value": "哈哈哈"
}
],
"application_command": {
"id": "938956540159881230",
"type": 1,
"application_id": "936929561302675456",
"version": "1237876415471554623",
"name": "imagine",
"description": "Create images with Midjourney",
"options": [
{
"type": 3,
"name": "prompt",
"description": "The prompt to imagine",
"required": true,
"description_localized": "The prompt to imagine",
"name_localized": "prompt"
}
],
"dm_permission": true,
"contexts": [
0,
1,
2
],
"integration_types": [
0,
1
],
"global_popularity_rank": 1,
"description_localized": "Create images with Midjourney",
"name_localized": "imagine"
},
"attachments": []
},
"nonce": "1238062212925358080",
"analytics_location": "slash_ui"
}

View File

@ -52,7 +52,7 @@ spring:
# url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=ruoyi-vue-pro;SelectMethod=cursor;encrypt=false;rewriteBatchedStatements=true;useUnicode=true;characterEncoding=utf-8 # SQLServer 连接的示例
# url: jdbc:dm://127.0.0.1:5236?schema=RUOYI_VUE_PRO # DM 连接的示例
username: root
password: 123456
password: root
# username: sa # SQL Server 连接的示例
# password: Yudao@2024 # SQL Server 连接的示例
# username: SYSDBA # DM 连接的示例
@ -61,7 +61,7 @@ spring:
lazy: true # 开启懒加载,保证启动速度
url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
username: root
password: 123456
password: root
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
data:
@ -248,9 +248,9 @@ yudao:
style: vivid
midjourney:
enable: true
token: OTc1MzcyNDg1OTcxMzEyNzAw.G2iiSo.OqW9vToC5dokiyb1QOWnCwRPsYpOjLyNcf9--M
guild-id: 1234355413420347402
channel-id: 1234380679576424448
token: MTE4MjE3MjY2MjkxNTY3ODIzOA.GEV1SG.c49F8lZoGCUHwsj8O0UdodmM6nyQHvuD2fXflw
guild-id: 1237948819677904956
channel-id: 1237948819677904960
captcha:
enable: false # 本地环境,暂时关闭图片验证码,方便登录等接口的测试;
security:
@ -267,6 +267,8 @@ yudao:
enable: false
demo: false # 关闭演示模式
tencent-lbs-key: TVDBZ-TDILD-4ON4B-PFDZA-RNLKH-VVF6E # QQ 地图的密钥 https://lbs.qq.com/service/staticV2/staticGuide/staticDoc
tenant:
enable: false
justauth:
enabled: true