Commit 0563503102c6f1aa9106b926cc8653aa1e6a8a74

Authored by YunaiV
1 parent 458f5acd

【新增】AI:使用 DALL 绘图时,使用 b64_json 返回

yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageDallReqVO.java
@@ -4,7 +4,6 @@ import io.swagger.v3.oas.annotations.media.Schema; @@ -4,7 +4,6 @@ import io.swagger.v3.oas.annotations.media.Schema;
4 import jakarta.validation.constraints.NotNull; 4 import jakarta.validation.constraints.NotNull;
5 import jakarta.validation.constraints.Size; 5 import jakarta.validation.constraints.Size;
6 import lombok.Data; 6 import lombok.Data;
7 -import lombok.experimental.Accessors;  
8 7
9 /** 8 /**
10 * dall2/dall2 绘画 9 * dall2/dall2 绘画
@@ -14,9 +13,11 @@ import lombok.experimental.Accessors; @@ -14,9 +13,11 @@ import lombok.experimental.Accessors;
14 * @since 1.0 13 * @since 1.0
15 */ 14 */
16 @Data 15 @Data
17 -@Accessors(chain = true)  
18 public class AiImageDallReqVO { 16 public class AiImageDallReqVO {
19 17
  18 + @Schema(description = "模型平台", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  19 + private String platform; // 参见 AiPlatformEnum 枚举
  20 +
20 @Schema(description = "提示词") 21 @Schema(description = "提示词")
21 @NotNull(message = "提示词不能为空!") 22 @NotNull(message = "提示词不能为空!")
22 @Size(max = 1200, message = "提示词最大1200") 23 @Size(max = 1200, message = "提示词最大1200")
@@ -31,10 +32,10 @@ public class AiImageDallReqVO { @@ -31,10 +32,10 @@ public class AiImageDallReqVO {
31 32
32 @Schema(description = "图片高度。对于dall-e-2模型,尺寸可为256x256, 512x512, 或 1024x1024。对于dall-e-3模型,尺寸可为1024x1024, 1792x1024, 或 1024x1792。") 33 @Schema(description = "图片高度。对于dall-e-2模型,尺寸可为256x256, 512x512, 或 1024x1024。对于dall-e-3模型,尺寸可为1024x1024, 1792x1024, 或 1024x1792。")
33 @NotNull(message = "图片高度不能为空!") 34 @NotNull(message = "图片高度不能为空!")
34 - private String height; 35 + private Integer height;
35 36
36 @Schema(description = "图片宽度。对于dall-e-2模型,尺寸可为256x256, 512x512, 或 1024x1024。对于dall-e-3模型,尺寸可为1024x1024, 1792x1024, 或 1024x1792。") 37 @Schema(description = "图片宽度。对于dall-e-2模型,尺寸可为256x256, 512x512, 或 1024x1024。对于dall-e-3模型,尺寸可为1024x1024, 1792x1024, 或 1024x1792。")
37 @NotNull(message = "图片宽度不能为空!") 38 @NotNull(message = "图片宽度不能为空!")
38 - private String width; 39 + private Integer width;
39 40
40 } 41 }
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/image/AiImageDO.java
@@ -41,10 +41,10 @@ public class AiImageDO extends BaseDO { @@ -41,10 +41,10 @@ public class AiImageDO extends BaseDO {
41 private String model; 41 private String model;
42 42
43 @Schema(description = "图片宽度") 43 @Schema(description = "图片宽度")
44 - private String width; 44 + private Integer width;
45 45
46 @Schema(description = "图片高度") 46 @Schema(description = "图片高度")
47 - private String height; 47 + private Integer height;
48 48
49 // TODO @fan:这种就注释绘画状态,然后枚举类关联下就好啦 49 // TODO @fan:这种就注释绘画状态,然后枚举类关联下就好啦
50 @Schema(description = "绘画状态:提交、排队、绘画中、绘画完成、绘画失败") 50 @Schema(description = "绘画状态:提交、排队、绘画中、绘画完成、绘画失败")
@@ -56,6 +56,7 @@ public class AiImageDO extends BaseDO { @@ -56,6 +56,7 @@ public class AiImageDO extends BaseDO {
56 @Schema(description = "图片地址(自己服务器)") 56 @Schema(description = "图片地址(自己服务器)")
57 private String picUrl; 57 private String picUrl;
58 58
  59 + // TODO @芋艿:可能要删除掉
59 @Schema(description = "绘画图片地址(绘画好的服务器)") 60 @Schema(description = "绘画图片地址(绘画好的服务器)")
60 private String originalPicUrl; 61 private String originalPicUrl;
61 62
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java
1 package cn.iocoder.yudao.module.ai.service.image; 1 package cn.iocoder.yudao.module.ai.service.image;
2 2
3 import cn.hutool.core.bean.BeanUtil; 3 import cn.hutool.core.bean.BeanUtil;
4 -import cn.hutool.core.util.StrUtil; 4 +import cn.hutool.core.codec.Base64;
5 import cn.hutool.core.util.ObjUtil; 5 import cn.hutool.core.util.ObjUtil;
  6 +import cn.hutool.core.util.StrUtil;
6 import cn.hutool.extra.spring.SpringUtil; 7 import cn.hutool.extra.spring.SpringUtil;
7 import cn.hutool.http.HttpUtil; 8 import cn.hutool.http.HttpUtil;
8 import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum; 9 import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum;
9 import cn.iocoder.yudao.framework.ai.core.enums.OpenAiImageModelEnum; 10 import cn.iocoder.yudao.framework.ai.core.enums.OpenAiImageModelEnum;
10 import cn.iocoder.yudao.framework.ai.core.enums.OpenAiImageStyleEnum; 11 import cn.iocoder.yudao.framework.ai.core.enums.OpenAiImageStyleEnum;
11 -import cn.iocoder.yudao.framework.ai.core.exception.AiException; 12 +import cn.iocoder.yudao.framework.ai.core.factory.AiClientFactory;
12 import cn.iocoder.yudao.framework.common.pojo.PageParam; 13 import cn.iocoder.yudao.framework.common.pojo.PageParam;
13 import cn.iocoder.yudao.framework.common.pojo.PageResult; 14 import cn.iocoder.yudao.framework.common.pojo.PageResult;
14 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 15 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@@ -30,11 +31,9 @@ import cn.iocoder.yudao.module.infra.api.file.FileApi; @@ -30,11 +31,9 @@ import cn.iocoder.yudao.module.infra.api.file.FileApi;
30 import com.google.common.collect.ImmutableMap; 31 import com.google.common.collect.ImmutableMap;
31 import jakarta.annotation.Resource; 32 import jakarta.annotation.Resource;
32 import lombok.extern.slf4j.Slf4j; 33 import lombok.extern.slf4j.Slf4j;
33 -import org.springframework.ai.image.ImageGeneration;  
34 -import org.springframework.ai.image.ImagePrompt;  
35 -import org.springframework.ai.image.ImageResponse;  
36 -import org.springframework.ai.openai.OpenAiImageClient; 34 +import org.springframework.ai.image.*;
37 import org.springframework.ai.openai.OpenAiImageOptions; 35 import org.springframework.ai.openai.OpenAiImageOptions;
  36 +import org.springframework.ai.stabilityai.api.StabilityAiImageOptions;
38 import org.springframework.beans.factory.annotation.Autowired; 37 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.beans.factory.annotation.Value; 38 import org.springframework.beans.factory.annotation.Value;
40 import org.springframework.scheduling.annotation.Async; 39 import org.springframework.scheduling.annotation.Async;
@@ -42,8 +41,6 @@ import org.springframework.stereotype.Service; @@ -42,8 +41,6 @@ import org.springframework.stereotype.Service;
42 import org.springframework.transaction.annotation.Transactional; 41 import org.springframework.transaction.annotation.Transactional;
43 42
44 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 43 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
45 -  
46 -  
47 import static cn.iocoder.yudao.module.ai.ErrorCodeConstants.AI_IMAGE_NOT_EXISTS; 44 import static cn.iocoder.yudao.module.ai.ErrorCodeConstants.AI_IMAGE_NOT_EXISTS;
48 45
49 /** 46 /**
@@ -62,7 +59,7 @@ public class AiImageServiceImpl implements AiImageService { @@ -62,7 +59,7 @@ public class AiImageServiceImpl implements AiImageService {
62 private FileApi fileApi; 59 private FileApi fileApi;
63 60
64 @Resource 61 @Resource
65 - private OpenAiImageClient openAiImageClient; 62 + private AiClientFactory aiClientFactory;
66 63
67 @Autowired 64 @Autowired
68 private MidjourneyProxyClient midjourneyProxyClient; 65 private MidjourneyProxyClient midjourneyProxyClient;
@@ -81,48 +78,58 @@ public class AiImageServiceImpl implements AiImageService { @@ -81,48 +78,58 @@ public class AiImageServiceImpl implements AiImageService {
81 } 78 }
82 79
83 @Override 80 @Override
84 - public Long dall(Long loginUserId, AiImageDallReqVO req) {  
85 - // 保存数据库  
86 - AiImageDO aiImageDO = BeanUtils.toBean(req, AiImageDO.class)  
87 - .setUserId(loginUserId)  
88 - .setWidth(req.getWidth())  
89 - .setHeight(req.getHeight()) 81 + public Long dall(Long userId, AiImageDallReqVO req) {
  82 + req.setPlatform("dall"); // TODO 芋艿:临时写死
  83 + // 1. 保存数据库
  84 + AiImageDO image = BeanUtils.toBean(req, AiImageDO.class)
  85 + .setUserId(userId).setStatus(AiImageStatusEnum.IN_PROGRESS.getStatus())
  86 + .setWidth(req.getWidth()).setHeight(req.getHeight())
90 .setDrawRequest(ImmutableMap.of(AiCommonConstants.DRAW_REQ_KEY_STYLE, req.getStyle())) 87 .setDrawRequest(ImmutableMap.of(AiCommonConstants.DRAW_REQ_KEY_STYLE, req.getStyle()))
91 - .setPublicStatus(AiImagePublicStatusEnum.PRIVATE.getStatus())  
92 - .setStatus(AiImageStatusEnum.IN_PROGRESS.getStatus());  
93 - imageMapper.insert(aiImageDO);  
94 - // 异步执行  
95 - getSelf().doDall(aiImageDO, req);  
96 - // 转换 AiImageDallDrawingRespVO  
97 - return aiImageDO.getId(); 88 + .setPublicStatus(AiImagePublicStatusEnum.PRIVATE.getStatus());
  89 + imageMapper.insert(image);
  90 + // 2. 异步绘制,后续前端通过返回的 id 进行伦旭
  91 + getSelf().doDall(image, req);
  92 + return image.getId();
98 } 93 }
99 94
100 @Async 95 @Async
101 - public void doDall(AiImageDO aiImageDO, AiImageDallReqVO req) { 96 + public void doDall(AiImageDO image, AiImageDallReqVO req) {
102 try { 97 try {
103 - // 获取 model  
104 - OpenAiImageModelEnum openAiImageModelEnum = OpenAiImageModelEnum.valueOfModel(req.getModel());  
105 - OpenAiImageStyleEnum openAiImageStyleEnum = OpenAiImageStyleEnum.valueOfStyle(req.getStyle());  
106 -  
107 - // 转换openai 参数  
108 - // TODO @fan:需要考虑,不同平台,参数不同;  
109 - OpenAiImageOptions openAiImageOptions = new OpenAiImageOptions();  
110 - openAiImageOptions.setModel(openAiImageModelEnum.getModel());  
111 - openAiImageOptions.setStyle(openAiImageStyleEnum.getStyle());  
112 - openAiImageOptions.setSize(String.format(AiCommonConstants.DALL_SIZE_TEMPLATE, req.getWidth(), req.getHeight()));  
113 - ImageResponse imageResponse = openAiImageClient.call(new ImagePrompt(req.getPrompt(), openAiImageOptions));  
114 - // 发送  
115 - ImageGeneration imageGeneration = imageResponse.getResult();  
116 - // 图片保存到服务器  
117 - String filePath = fileApi.createFile(HttpUtil.downloadBytes(imageGeneration.getOutput().getUrl()));  
118 - // 更新数据库  
119 - imageMapper.updateById(new AiImageDO().setId(aiImageDO.getId()).setStatus(AiImageStatusEnum.COMPLETE.getStatus())  
120 - .setPicUrl(filePath).setOriginalPicUrl(imageGeneration.getOutput().getUrl()));  
121 - } catch (AiException aiException) {  
122 - // TODO @fan:错误日志,也打印下哈;因为 aiException.getMessage() 比较精简;  
123 - imageMapper.updateById(new AiImageDO().setId(aiImageDO.getId()).setStatus(AiImageStatusEnum.FAIL.getStatus())  
124 - .setErrorMessage(aiException.getMessage())); 98 + // 1.1 构建请求
  99 + ImageOptions request = buildImageOptions(req);
  100 + // 1.2 执行请求
  101 + ImageClient imageClient = aiClientFactory.getDefaultImageClient(AiPlatformEnum.validatePlatform(req.getPlatform()));
  102 + ImageResponse response = imageClient.call(new ImagePrompt(req.getPrompt(), request));
  103 +
  104 + // 2. 上传到文件服务
  105 + byte[] fileContent = Base64.decode(response.getResult().getOutput().getB64Json());
  106 + String filePath = fileApi.createFile(fileContent);
  107 +
  108 + // 3. 更新数据库
  109 + imageMapper.updateById(new AiImageDO().setId(image.getId()).setStatus(AiImageStatusEnum.COMPLETE.getStatus())
  110 + .setPicUrl(filePath));
  111 + } catch (Exception ex) {
  112 + log.error("[doDall][image({}) 生成异常]", image, ex);
  113 + imageMapper.updateById(new AiImageDO().setId(image.getId())
  114 + .setStatus(AiImageStatusEnum.FAIL.getStatus()).setErrorMessage(ex.getMessage()));
  115 + }
  116 + }
  117 +
  118 + private static ImageOptions buildImageOptions(AiImageDallReqVO draw) {
  119 + if (ObjUtil.equal(draw.getPlatform(), AiPlatformEnum.OPEN_AI_DALL.getPlatform())) {
  120 + OpenAiImageOptions request = new OpenAiImageOptions();
  121 + request.setModel(OpenAiImageModelEnum.valueOfModel(draw.getModel()).getModel());
  122 + request.setStyle(OpenAiImageStyleEnum.valueOfStyle(draw.getStyle()).getStyle());
  123 + request.setSize(String.format(AiCommonConstants.DALL_SIZE_TEMPLATE, draw.getWidth(), draw.getHeight()));
  124 + request.setResponseFormat("b64_json");
  125 + return request;
  126 + } else {
  127 + // https://platform.stability.ai/docs/api-reference#tag/Generate/paths/~1v2beta~1stable-image~1generate~1sd3/post
  128 + return StabilityAiImageOptions.builder().withModel(draw.getModel())
  129 + .withHeight(draw.getHeight()).withWidth(draw.getWidth())
  130 + .build();
125 } 131 }
  132 +// return null;
126 } 133 }
127 134
128 @Override 135 @Override
yudao-module-ai/yudao-module-ai-biz/src/main/resources/ai_image.sql deleted
1 -/*  
2 - Navicat Premium Data Transfer  
3 -  
4 - Source Server : localhost  
5 - Source Server Type : MySQL  
6 - Source Server Version : 80034 (8.0.34)  
7 - Source Host : localhost:3306  
8 - Source Schema : ruoyi-vue-pro  
9 -  
10 - Target Server Type : MySQL  
11 - Target Server Version : 80034 (8.0.34)  
12 - File Encoding : 65001  
13 -  
14 - Date: 30/05/2024 17:20:37  
15 -*/  
16 -  
17 -SET NAMES utf8mb4;  
18 -SET FOREIGN_KEY_CHECKS = 0;  
19 -  
20 --- ----------------------------  
21 --- Table structure for ai_image  
22 --- ----------------------------  
23 -DROP TABLE IF EXISTS `ai_image`;  
24 -CREATE TABLE `ai_image` (  
25 - `id` bigint NOT NULL AUTO_INCREMENT,  
26 - `user_id` bigint DEFAULT NULL,  
27 - `prompt` varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '提示词\n',  
28 - `platform` varchar(32) COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '平台',  
29 - `model` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '模型 dall2/dall3、MJ、NIJI',  
30 - `width` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '图片宽度',  
31 - `height` varchar(32) COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '图片高度',  
32 - `status` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '绘画状态:提交、排队、绘画中、绘画完成、绘画失败\n',  
33 - `public_status` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '是否发布',  
34 - `pic_url` varchar(512) COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '图片地址',  
35 - `original_pic_url` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '绘画图片地址\n',  
36 - `error_message` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '错误信息',  
37 - `draw_request` json DEFAULT NULL COMMENT '绘画request',  
38 - `draw_response` json DEFAULT NULL COMMENT '绘画response',  
39 - `create_time` datetime DEFAULT NULL COMMENT '创建时间',  
40 - `update_time` datetime DEFAULT NULL COMMENT '更新时间',  
41 - `creator` bigint DEFAULT NULL COMMENT '创建用户',  
42 - `updater` bigint DEFAULT NULL COMMENT '更新用户',  
43 - `deleted` bit(1) DEFAULT b'0' COMMENT '删除',  
44 - PRIMARY KEY (`id`)  
45 -) ENGINE=InnoDB AUTO_INCREMENT=107 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;  
46 -  
47 --- ----------------------------  
48 --- Records of ai_image  
49 --- ----------------------------  
50 -BEGIN;  
51 -INSERT INTO `ai_image` (`id`, `user_id`, `prompt`, `platform`, `model`, `width`, `height`, `status`, `public_status`, `pic_url`, `original_pic_url`, `error_message`, `draw_request`, `draw_response`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (91, 1, '北极企鹅', NULL, 'dall-e-2', '1024', '1024', '20', NULL, 'http://test.yudao.iocoder.cn/75b4d733222b60aafdbdcd0475562ff88149eaaff93a25c4e4c66a95bd07f01f.png', 'https://oaidalleapiprodscus.blob.core.windows.net/private/org-FttVrm20iQRlsxxFE7BLEgkT/user-5p7zykU5aS1sYXCjczkTXn8I/img-z4KBxbWtUpLBYmgaYPvWXjBh.png?st=2024-05-29T04%3A50%3A54Z&se=2024-05-29T06%3A50%3A54Z&sp=r&sv=2023-11-03&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2024-05-28T23%3A21%3A22Z&ske=2024-05-29T23%3A21%3A22Z&sks=b&skv=2023-11-03&sig=jSw/hJfuPWJqQgjSoINtVrt4w61FsaQ6ed4pRCM8UUA%3D', NULL, '{\"style\": \"vivid\"}', NULL, '2024-05-29 13:50:43', '2024-05-29 13:51:05', 1, 1, b'0');  
52 -INSERT INTO `ai_image` (`id`, `user_id`, `prompt`, `platform`, `model`, `width`, `height`, `status`, `public_status`, `pic_url`, `original_pic_url`, `error_message`, `draw_request`, `draw_response`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (93, 1, '北极企鹅', NULL, 'dall-e-2', '1024', '1024', '20', 'private', 'http://test.yudao.iocoder.cn/ab326bbf3fae9a940770a5c36bbf39467ae539a5b94a030b6c6cc2f179d7dd31.png', 'https://oaidalleapiprodscus.blob.core.windows.net/private/org-FttVrm20iQRlsxxFE7BLEgkT/user-5p7zykU5aS1sYXCjczkTXn8I/img-CsJtCgLT9lTigTuBDJtPyO8X.png?st=2024-05-29T09%3A02%3A12Z&se=2024-05-29T11%3A02%3A12Z&sp=r&sv=2023-11-03&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2024-05-28T23%3A21%3A54Z&ske=2024-05-29T23%3A21%3A54Z&sks=b&skv=2023-11-03&sig=tH6yFzHtcp3Dxwaua2crFYurCdE7B7%2BAXhyPNVVep1c%3D', NULL, '{\"style\": \"vivid\"}', NULL, '2024-05-29 18:02:03', '2024-05-29 18:02:17', 1, 1, b'0');  
53 -INSERT INTO `ai_image` (`id`, `user_id`, `prompt`, `platform`, `model`, `width`, `height`, `status`, `public_status`, `pic_url`, `original_pic_url`, `error_message`, `draw_request`, `draw_response`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (94, 1, '北极大熊猫', NULL, 'dall-e-2', '1024', '1024', '20', 'private', 'http://test.yudao.iocoder.cn/ed9d43a6c841c4a967700e211c998778994eeea60cff2dfeb1c3a88b0542ebdd.png', 'https://oaidalleapiprodscus.blob.core.windows.net/private/org-FttVrm20iQRlsxxFE7BLEgkT/user-5p7zykU5aS1sYXCjczkTXn8I/img-GAwShv01C2408VY5lXvLTP4Q.png?st=2024-05-30T01%3A31%3A28Z&se=2024-05-30T03%3A31%3A28Z&sp=r&sv=2023-11-03&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2024-05-29T23%3A39%3A20Z&ske=2024-05-30T23%3A39%3A20Z&sks=b&skv=2023-11-03&sig=n/rqAnD0qJDkhbh/Qm12lz1Se70PQSdXetarmwCKoMY%3D', NULL, '{\"style\": \"vivid\"}', NULL, '2024-05-30 10:31:18', '2024-05-30 10:31:34', 1, 1, b'1');  
54 -INSERT INTO `ai_image` (`id`, `user_id`, `prompt`, `platform`, `model`, `width`, `height`, `status`, `public_status`, `pic_url`, `original_pic_url`, `error_message`, `draw_request`, `draw_response`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (102, 1, '女少侠', 'midjourney', NULL, NULL, NULL, '30', 'private', NULL, NULL, '无可用的账号实例', NULL, '{}', '2024-05-30 16:11:13', '2024-05-30 16:11:13', 1, 1, b'1');  
55 -INSERT INTO `ai_image` (`id`, `user_id`, `prompt`, `platform`, `model`, `width`, `height`, `status`, `public_status`, `pic_url`, `original_pic_url`, `error_message`, `draw_request`, `draw_response`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (103, 1, '123123', 'midjourney', NULL, NULL, NULL, '30', 'private', NULL, NULL, '无可用的账号实例', NULL, '{}', '2024-05-30 16:27:34', '2024-05-30 16:27:34', 1, 1, b'1');  
56 -INSERT INTO `ai_image` (`id`, `user_id`, `prompt`, `platform`, `model`, `width`, `height`, `status`, `public_status`, `pic_url`, `original_pic_url`, `error_message`, `draw_request`, `draw_response`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (104, 1, '123123', 'midjourney', NULL, NULL, NULL, '30', 'private', NULL, NULL, '无可用的账号实例', NULL, '{}', '2024-05-30 16:28:23', '2024-05-30 16:28:24', 1, 1, b'1');  
57 -INSERT INTO `ai_image` (`id`, `user_id`, `prompt`, `platform`, `model`, `width`, `height`, `status`, `public_status`, `pic_url`, `original_pic_url`, `error_message`, `draw_request`, `draw_response`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (105, 1, '123123', 'midjourney', NULL, NULL, NULL, '30', 'private', NULL, NULL, '无可用的账号实例', NULL, '{}', '2024-05-30 16:28:25', '2024-05-30 16:28:25', 1, 1, b'1');  
58 -INSERT INTO `ai_image` (`id`, `user_id`, `prompt`, `platform`, `model`, `width`, `height`, `status`, `public_status`, `pic_url`, `original_pic_url`, `error_message`, `draw_request`, `draw_response`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (106, 1, '123123', 'midjourney', NULL, NULL, NULL, '30', 'private', NULL, NULL, '无可用的账号实例', NULL, '{}', '2024-05-30 16:28:34', '2024-05-30 16:28:34', 1, 1, b'1');  
59 -COMMIT;  
60 -  
61 -SET FOREIGN_KEY_CHECKS = 1;  
yudao-module-ai/yudao-module-ai-biz/src/main/resources/chat.sql deleted
1 -/*  
2 - Navicat Premium Data Transfer  
3 -  
4 - Source Server : localhost  
5 - Source Server Type : MySQL  
6 - Source Server Version : 80034 (8.0.34)  
7 - Source Host : localhost:3306  
8 - Source Schema : ruoyi-vue-pro  
9 -  
10 - Target Server Type : MySQL  
11 - Target Server Version : 80034 (8.0.34)  
12 - File Encoding : 65001  
13 -  
14 - Date: 08/05/2024 18:10:05  
15 -*/  
16 -  
17 -SET NAMES utf8mb4;  
18 -SET FOREIGN_KEY_CHECKS = 0;  
19 -  
20 --- ----------------------------  
21 --- Table structure for ai_chat_conversation  
22 --- ----------------------------  
23 -DROP TABLE IF EXISTS `ai_chat_conversation`;  
24 -CREATE TABLE `ai_chat_conversation` (  
25 - `id` bigint NOT NULL AUTO_INCREMENT,  
26 - `user_id` bigint DEFAULT NULL COMMENT '用户id',  
27 - `role_id` bigint DEFAULT NULL COMMENT '聊天角色',  
28 - `title` varchar(256) COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '标题',  
29 - `type` varchar(16) COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '对话类型',  
30 - `chat_count` int DEFAULT NULL COMMENT '聊天次数',  
31 - `model_id` bigint DEFAULT NULL COMMENT '模型id',  
32 - `model` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '模型',  
33 - `pinned` blob COMMENT '是否置顶',  
34 - `temperature` double DEFAULT NULL COMMENT '温度参数',  
35 - `max_tokens` int DEFAULT NULL COMMENT '单条回复的最大 Token 数量',  
36 - `max_contexts` int DEFAULT NULL COMMENT '上下文的最大 Message 数量',  
37 - `create_time` datetime DEFAULT NULL COMMENT '创建时间',  
38 - `update_time` datetime DEFAULT NULL COMMENT '更新时间',  
39 - `creator` bigint DEFAULT NULL COMMENT '创建用户',  
40 - `updater` bigint DEFAULT NULL COMMENT '更新用户',  
41 - `deleted` bit(1) DEFAULT b'0' COMMENT '删除',  
42 - PRIMARY KEY (`id`)  
43 -) ENGINE=InnoDB AUTO_INCREMENT=1781604279872581650 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;  
44 -  
45 --- ----------------------------  
46 --- Records of ai_chat_conversation  
47 --- ----------------------------  
48 -BEGIN;  
49 -INSERT INTO `ai_chat_conversation` (`id`, `user_id`, `role_id`, `title`, `type`, `chat_count`, `model_id`, `model`, `pinned`, `temperature`, `max_tokens`, `max_contexts`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (1781604279872581647, 1, NULL, '新增对话', NULL, NULL, 9, 'ERNIE-3.5-8K', 0x30, NULL, NULL, NULL, '2024-05-07 16:20:06', '2024-05-07 16:20:06', 1, 1, b'1');  
50 -INSERT INTO `ai_chat_conversation` (`id`, `user_id`, `role_id`, `title`, `type`, `chat_count`, `model_id`, `model`, `pinned`, `temperature`, `max_tokens`, `max_contexts`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (1781604279872581648, 1, 9, '新增对话', NULL, NULL, 9, 'ERNIE-3.5-8K', 0x30, NULL, NULL, NULL, '2024-05-07 16:20:35', '2024-05-07 16:20:35', 1, 1, b'0');  
51 -INSERT INTO `ai_chat_conversation` (`id`, `user_id`, `role_id`, `title`, `type`, `chat_count`, `model_id`, `model`, `pinned`, `temperature`, `max_tokens`, `max_contexts`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (1781604279872581649, 1, NULL, '新增对话', NULL, NULL, 9, 'ERNIE-3.5-8K', 0x30, NULL, NULL, NULL, '2024-05-07 16:22:37', '2024-05-07 16:22:37', 1, 1, b'0');  
52 -COMMIT;  
53 -  
54 --- ----------------------------  
55 --- Table structure for ai_chat_message  
56 --- ----------------------------  
57 -DROP TABLE IF EXISTS `ai_chat_message`;  
58 -CREATE TABLE `ai_chat_message` (  
59 - `id` bigint NOT NULL AUTO_INCREMENT,  
60 - `conversation_id` bigint DEFAULT NULL COMMENT '对话id',  
61 - `user_id` bigint DEFAULT NULL COMMENT '用户id',  
62 - `role_id` bigint DEFAULT NULL COMMENT '角色id',  
63 - `type` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '类型system、user、assistant\n',  
64 - `model` varchar(32) COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '模型',  
65 - `model_id` bigint DEFAULT NULL COMMENT '模型id',  
66 - `content` varchar(2048) COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '内容',  
67 - `tokens` int DEFAULT NULL COMMENT '消耗 Token 数量',  
68 - `temperature` double DEFAULT NULL COMMENT '用于调整生成回复的随机性和多样性程度',  
69 - `max_tokens` int DEFAULT NULL COMMENT '单条回复的最大 Token 数量',  
70 - `max_contexts` int DEFAULT NULL COMMENT '上下文的最大 Message 数量',  
71 - `create_time` datetime DEFAULT NULL COMMENT '创建时间',  
72 - `update_time` datetime DEFAULT NULL COMMENT '更新时间',  
73 - `creator` bigint DEFAULT NULL COMMENT '创建用户',  
74 - `updater` bigint DEFAULT NULL COMMENT '更新用户',  
75 - `deleted` bit(1) DEFAULT b'0' COMMENT '删除',  
76 - PRIMARY KEY (`id`) USING BTREE  
77 -) ENGINE=InnoDB AUTO_INCREMENT=65 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;  
78 -  
79 --- ----------------------------  
80 --- Records of ai_chat_message  
81 --- ----------------------------  
82 -BEGIN;  
83 -INSERT INTO `ai_chat_message` (`id`, `conversation_id`, `user_id`, `role_id`, `type`, `model`, `model_id`, `content`, `tokens`, `temperature`, `max_tokens`, `max_contexts`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (61, 1781604279872581649, 1, NULL, 'user', 'ERNIE-3.5-8K', 9, '苹果是什么颜色?', NULL, NULL, NULL, NULL, '2024-05-07 17:18:29', '2024-05-07 17:18:29', 1, 1, b'0');  
84 -INSERT INTO `ai_chat_message` (`id`, `conversation_id`, `user_id`, `role_id`, `type`, `model`, `model_id`, `content`, `tokens`, `temperature`, `max_tokens`, `max_contexts`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (62, 1781604279872581649, 1, NULL, 'system', 'ERNIE-3.5-8K', 9, '苹果是一种水果,其颜色可以因品种和成熟度而异。常见的苹果颜色包括:\n\n1. 红色:许多苹果品种,如红富士、红元帅等,在成熟时会呈现出鲜艳的红色。\n2. 绿色:一些苹果品种,如青苹果、青香蕉等,在成熟时保持绿色或带有绿色条纹。\n3. 黄色:金苹果、黄元帅等品种在成熟时呈黄色。\n\n此外,还有一些苹果品种在成熟时会呈现出不同的颜色组合,如红绿相间、红黄相间等。因此,苹果的颜色并不是单一的,而是根据品种和成熟度而有所不同。', 8, NULL, NULL, NULL, '2024-05-07 17:18:38', '2024-05-07 17:18:38', NULL, NULL, b'0');  
85 -INSERT INTO `ai_chat_message` (`id`, `conversation_id`, `user_id`, `role_id`, `type`, `model`, `model_id`, `content`, `tokens`, `temperature`, `max_tokens`, `max_contexts`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (63, 1781604279872581649, 1, NULL, 'user', 'ERNIE-3.5-8K', 9, '中国好看吗?', NULL, NULL, NULL, NULL, '2024-05-07 17:18:53', '2024-05-07 17:18:53', 1, 1, b'0');  
86 -INSERT INTO `ai_chat_message` (`id`, `conversation_id`, `user_id`, `role_id`, `type`, `model`, `model_id`, `content`, `tokens`, `temperature`, `max_tokens`, `max_contexts`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (64, 1781604279872581649, 1, NULL, 'system', 'ERNIE-3.5-8K', 9, '中国是一个拥有悠久历史、灿烂文化、广袤土地和多元民族的国家,自然景观和人文景观都非常丰富。从雄伟的长城、壮丽的黄山到神秘的西藏,从繁华的上海、历史悠久的北京到充满异域风情的云南,中国各地都有独特的魅力。\n\n此外,中国还拥有丰富多彩的非物质文化遗产,如京剧、川剧、皮影戏等传统艺术形式,以及中秋节、春节等传统节日。这些文化遗产反映了中国人民的智慧和创造力,也是中国文化的重要组成部分。\n\n因此,可以说中国非常美丽,值得人们去探索和发现它的魅力。无论是自然景观还是人文景观,中国都有着独特的魅力和吸引力。', 1, NULL, NULL, NULL, '2024-05-07 17:19:03', '2024-05-07 17:19:03', 1, 1, b'0');  
87 -COMMIT;  
88 -  
89 --- ----------------------------  
90 --- Table structure for ai_chat_model  
91 --- ----------------------------  
92 -DROP TABLE IF EXISTS `ai_chat_model`;  
93 -CREATE TABLE `ai_chat_model` (  
94 - `id` bigint NOT NULL AUTO_INCREMENT,  
95 - `key_id` bigint DEFAULT NULL COMMENT 'API 秘钥编号',  
96 - `name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '模型名字\n',  
97 - `model` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '模型类型(自己定义qianwen、yiyan、xinghuo、openai)\n',  
98 - `platform` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '平台',  
99 - `sort` int DEFAULT NULL COMMENT '排序',  
100 - `status` tinyint DEFAULT NULL COMMENT '禁用 0、正常 1、禁用\n',  
101 - `temperature` double DEFAULT NULL COMMENT '温度参数',  
102 - `max_tokens` int DEFAULT NULL COMMENT '单条回复的最大 Token 数量',  
103 - `max_contexts` int DEFAULT NULL COMMENT '上下文的最大 Message 数量',  
104 - `create_time` datetime DEFAULT NULL COMMENT '创建时间',  
105 - `update_time` datetime DEFAULT NULL COMMENT '更新时间',  
106 - `creator` bigint DEFAULT NULL COMMENT '创建用户',  
107 - `updater` bigint DEFAULT NULL COMMENT '更新用户',  
108 - `deleted` bit(1) DEFAULT b'0' COMMENT '删除',  
109 - PRIMARY KEY (`id`)  
110 -) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;  
111 -  
112 --- ----------------------------  
113 --- Records of ai_chat_model  
114 --- ----------------------------  
115 -BEGIN;  
116 -INSERT INTO `ai_chat_model` (`id`, `key_id`, `name`, `model`, `platform`, `sort`, `status`, `temperature`, `max_tokens`, `max_contexts`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (9, 1, '小红书Ai写作大模型3.5 8k', 'ERNIE-3.5-8K', 'yiyan', 100, 0, NULL, NULL, NULL, '2024-05-07 15:08:22', '2024-05-07 15:20:32', 1, 1, b'0');  
117 -INSERT INTO `ai_chat_model` (`id`, `key_id`, `name`, `model`, `platform`, `sort`, `status`, `temperature`, `max_tokens`, `max_contexts`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (10, 1, '小红书Ai写作大模型4.0', 'ERNIE 4.0', 'yiyan', 100, 0, NULL, NULL, NULL, '2024-05-07 15:23:33', '2024-05-07 15:23:33', 1, 1, b'0');  
118 -COMMIT;  
119 -  
120 --- ----------------------------  
121 --- Table structure for ai_chat_role  
122 --- ----------------------------  
123 -DROP TABLE IF EXISTS `ai_chat_role`;  
124 -CREATE TABLE `ai_chat_role` (  
125 - `id` bigint NOT NULL AUTO_INCREMENT,  
126 - `user_id` bigint DEFAULT NULL,  
127 - `model_id` bigint DEFAULT NULL COMMENT '模型编号',  
128 - `name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '角色名,角色的显示名称\n',  
129 - `avatar` varchar(256) COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '头像',  
130 - `category` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '分类,角色所属的类别,如娱乐、创作等\n',  
131 - `sort` int DEFAULT NULL COMMENT '排序',  
132 - `description` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '角色描述',  
133 - `welcome_message` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '角色欢迎语',  
134 - `system_message` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '角色设定(消息)',  
135 - `public_status` blob COMMENT '是否公开 true - 公开;false - 私有',  
136 - `status` tinyint DEFAULT NULL COMMENT '状态 0、开启 1、关闭',  
137 - `create_time` datetime DEFAULT NULL COMMENT '创建时间',  
138 - `update_time` datetime DEFAULT NULL COMMENT '更新时间',  
139 - `creator` bigint DEFAULT NULL COMMENT '创建用户',  
140 - `updater` bigint DEFAULT NULL COMMENT '更新用户',  
141 - `deleted` bit(1) DEFAULT b'0' COMMENT '删除',  
142 - PRIMARY KEY (`id`)  
143 -) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;  
144 -  
145 --- ----------------------------  
146 --- Records of ai_chat_role  
147 --- ----------------------------  
148 -BEGIN;  
149 -INSERT INTO `ai_chat_role` (`id`, `user_id`, `model_id`, `name`, `avatar`, `category`, `sort`, `description`, `welcome_message`, `system_message`, `public_status`, `status`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (8, 1, 9, '小红书写作v2', 'http://baidu.com', 'writing', 0, '采用gpt3.5模型,拥有小红书优质作者写作经验。', '欢迎使用小红书写作模型!', '你是一名优秀的小红书人文、风光作者,你热爱旅游,每去往一个城市你都会用美妙的文字抒写着这座城市的大街小巷,描述着这座城市的美好。', 0x31, 0, '2024-05-07 15:30:30', '2024-05-07 15:35:54', 1, 1, b'1');  
150 -INSERT INTO `ai_chat_role` (`id`, `user_id`, `model_id`, `name`, `avatar`, `category`, `sort`, `description`, `welcome_message`, `system_message`, `public_status`, `status`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (9, 1, 9, '小红书写作v1', 'http://baidu.com', 'writing', 0, '采用gpt3.5模型,拥有小红书优质作者写作经验。', '欢迎使用小红书写作模型!', '你是一名优秀的小红书人文、风光作者,你热爱旅游,每去往一个城市你都会用美妙的文字抒写着这座城市的大街小巷,描述着这座城市的美好。', 0x30, 0, '2024-05-07 15:36:40', '2024-05-07 15:36:40', 1, 1, b'0');  
151 -COMMIT;  
152 -  
153 --- ----------------------------  
154 --- Table structure for ai_image  
155 --- ----------------------------  
156 -DROP TABLE IF EXISTS `ai_image`;  
157 -CREATE TABLE `ai_image` (  
158 - `id` bigint NOT NULL AUTO_INCREMENT,  
159 - `user_id` bigint DEFAULT NULL,  
160 - `prompt` varchar(2000) COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '提示词\n',  
161 - `modal` varchar(32) COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '模型\n',  
162 - `size` varchar(32) COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '生成图像的尺寸大小。对于dall-e-2模型,尺寸可为256x256, 512x512, 或 1024x1024。对于dall-e-3模型,尺寸可为1024x1024, 1792x1024, 或 1024x1792。\n',  
163 - `drawing_status` varchar(32) COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '绘画状态:提交、排队、绘画中、绘画完成、绘画失败\n',  
164 - `drawing_image_url` varchar(512) COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '绘画图片地址\n',  
165 - `drawing_error_message` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '错误信息',  
166 - `mj_message_id` varchar(32) COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '用户操作的消息编号(MJ返回)\n',  
167 - `mj_operation_id` varchar(128) COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '用户操作的操作编号(MJ返回)\n',  
168 - `mj_operation_name` varchar(32) COLLATE utf8mb4_0900_bin DEFAULT NULL COMMENT '用户操作的操作名字(MJ返回)\n',  
169 - `mj_operations` json DEFAULT NULL COMMENT 'mj图片生产成功保存的 components json 数组\n',  
170 - `create_time` datetime DEFAULT NULL COMMENT '创建时间',  
171 - `update_time` datetime DEFAULT NULL COMMENT '更新时间',  
172 - `creator` bigint DEFAULT NULL COMMENT '创建用户',  
173 - `updater` bigint DEFAULT NULL COMMENT '更新用户',  
174 - `deleted` bit(1) DEFAULT b'0' COMMENT '删除',  
175 - PRIMARY KEY (`id`)  
176 -) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;  
177 -  
178 --- ----------------------------  
179 --- Records of ai_image  
180 --- ----------------------------  
181 -BEGIN;  
182 -INSERT INTO `ai_image` (`id`, `user_id`, `prompt`, `modal`, `size`, `drawing_status`, `drawing_image_url`, `drawing_error_message`, `mj_message_id`, `mj_operation_id`, `mj_operation_name`, `mj_operations`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (22, 1, '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', 'midjoureny', NULL, 'fail', NULL, 'You have reached the maximum allowed number of concurrent jobs. Don\'t worry, this job will start as soon as another one finishes!', NULL, NULL, NULL, NULL, '2024-05-08 17:26:01', '2024-05-08 17:26:04', 1, NULL, b'0');  
183 -INSERT INTO `ai_image` (`id`, `user_id`, `prompt`, `modal`, `size`, `drawing_status`, `drawing_image_url`, `drawing_error_message`, `mj_message_id`, `mj_operation_id`, `mj_operation_name`, `mj_operations`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (23, 1, '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', 'midjoureny', NULL, 'fail', NULL, 'Your job queue is full. Please wait for a job to finish first, then resubmit this one.', '1788144718477979648', NULL, NULL, NULL, '2024-05-08 17:51:38', '2024-05-08 17:51:39', 1, NULL, b'0');  
184 -INSERT INTO `ai_image` (`id`, `user_id`, `prompt`, `modal`, `size`, `drawing_status`, `drawing_image_url`, `drawing_error_message`, `mj_message_id`, `mj_operation_id`, `mj_operation_name`, `mj_operations`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES (24, 1, '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', 'midjoureny', NULL, 'submit', NULL, NULL, '1788145293357699072', NULL, NULL, NULL, '2024-05-08 17:53:55', '2024-05-08 17:53:55', 1, 1, b'0');  
185 -COMMIT;  
186 -  
187 -SET FOREIGN_KEY_CHECKS = 1;  
yudao-module-ai/yudao-spring-boot-starter-ai/pom.xml
@@ -22,6 +22,11 @@ @@ -22,6 +22,11 @@
22 <artifactId>spring-ai-openai-spring-boot-starter</artifactId> 22 <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
23 <version>1.0.3</version> 23 <version>1.0.3</version>
24 </dependency> 24 </dependency>
  25 + <dependency>
  26 + <groupId>io.springboot.ai</groupId>
  27 + <artifactId>spring-ai-stability-ai</artifactId>
  28 + <version>1.0.3</version>
  29 + </dependency>
25 <!-- <dependency>--> 30 <!-- <dependency>-->
26 <!-- <groupId>io.springboot.ai</groupId>--> 31 <!-- <groupId>io.springboot.ai</groupId>-->
27 <!-- <artifactId>spring-ai-vertex-ai-gemini</artifactId>--> 32 <!-- <artifactId>spring-ai-vertex-ai-gemini</artifactId>-->
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/enums/AiPlatformEnum.java
@@ -20,7 +20,8 @@ public enum AiPlatformEnum { @@ -20,7 +20,8 @@ public enum AiPlatformEnum {
20 QIAN_WEN("QianWen", "千问"), // 阿里 20 QIAN_WEN("QianWen", "千问"), // 阿里
21 GEMIR ("gemir ", "gemir "), // 谷歌 21 GEMIR ("gemir ", "gemir "), // 谷歌
22 22
23 - OPEN_AI_DALL("dall", "dall"), // TODO OpenAI 提供的绘图,接入中 23 + OPEN_AI_DALL("dall", "dall"), // TODO OpenAI 提供的绘图,接入中;TODO 要不要统一下?!
  24 + STABLE_DIFFUSION("StableDiffusion", "StableDiffusion"), // Stability AI
24 MIDJOURNEY("midjourney", "midjourney"), // TODO MJ 提供的绘图,接入中 25 MIDJOURNEY("midjourney", "midjourney"), // TODO MJ 提供的绘图,接入中
25 ; 26 ;
26 27
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/enums/OpenAiImageModelEnum.java
@@ -13,6 +13,7 @@ import lombok.Getter; @@ -13,6 +13,7 @@ import lombok.Getter;
13 */ 13 */
14 @AllArgsConstructor 14 @AllArgsConstructor
15 @Getter 15 @Getter
  16 +@Deprecated
16 public enum OpenAiImageModelEnum { 17 public enum OpenAiImageModelEnum {
17 18
18 DALL_E_2("dall-e-2", "dall-e-2"), 19 DALL_E_2("dall-e-2", "dall-e-2"),
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/enums/OpenAiImageStyleEnum.java
@@ -13,6 +13,7 @@ import lombok.Getter; @@ -13,6 +13,7 @@ import lombok.Getter;
13 */ 13 */
14 @AllArgsConstructor 14 @AllArgsConstructor
15 @Getter 15 @Getter
  16 +@Deprecated
16 public enum OpenAiImageStyleEnum { 17 public enum OpenAiImageStyleEnum {
17 18
18 // 图像生成的风格。可为vivid(生动)或 natural(自然)。vivid会使模型偏向生成超现实和戏剧性的图像,而natural则会让模型产出更自然、不那么超现实的图像。该参数仅对dall-e-3模型有效。 19 // 图像生成的风格。可为vivid(生动)或 natural(自然)。vivid会使模型偏向生成超现实和戏剧性的图像,而natural则会让模型产出更自然、不那么超现实的图像。该参数仅对dall-e-3模型有效。
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/factory/AiClientFactory.java
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.ai.core.factory; @@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.ai.core.factory;
3 import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum; 3 import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum;
4 import org.springframework.ai.chat.StreamingChatClient; 4 import org.springframework.ai.chat.StreamingChatClient;
5 import org.springframework.ai.chat.prompt.ChatOptions; 5 import org.springframework.ai.chat.prompt.ChatOptions;
  6 +import org.springframework.ai.image.ImageClient;
6 7
7 /** 8 /**
8 * AI 客户端工厂的接口类 9 * AI 客户端工厂的接口类
@@ -34,6 +35,16 @@ public interface AiClientFactory { @@ -34,6 +35,16 @@ public interface AiClientFactory {
34 StreamingChatClient getDefaultStreamingChatClient(AiPlatformEnum platform); 35 StreamingChatClient getDefaultStreamingChatClient(AiPlatformEnum platform);
35 36
36 /** 37 /**
  38 + * 基于默认配置,获得 ImageClient 对象
  39 + *
  40 + * 默认配置,指的是在 application.yaml 配置文件中的 spring.ai 相关的配置
  41 + *
  42 + * @param platform 平台
  43 + * @return ImageClient 对象
  44 + */
  45 + ImageClient getDefaultImageClient(AiPlatformEnum platform);
  46 +
  47 + /**
37 * 创建 Chat 参数 48 * 创建 Chat 参数
38 * 49 *
39 * @param platform 平台 50 * @param platform 平台
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/factory/AiClientFactoryImpl.java
@@ -24,11 +24,13 @@ import org.springframework.ai.autoconfigure.ollama.OllamaAutoConfiguration; @@ -24,11 +24,13 @@ import org.springframework.ai.autoconfigure.ollama.OllamaAutoConfiguration;
24 import org.springframework.ai.autoconfigure.openai.OpenAiAutoConfiguration; 24 import org.springframework.ai.autoconfigure.openai.OpenAiAutoConfiguration;
25 import org.springframework.ai.chat.StreamingChatClient; 25 import org.springframework.ai.chat.StreamingChatClient;
26 import org.springframework.ai.chat.prompt.ChatOptions; 26 import org.springframework.ai.chat.prompt.ChatOptions;
  27 +import org.springframework.ai.image.ImageClient;
27 import org.springframework.ai.ollama.OllamaChatClient; 28 import org.springframework.ai.ollama.OllamaChatClient;
28 import org.springframework.ai.ollama.api.OllamaApi; 29 import org.springframework.ai.ollama.api.OllamaApi;
29 import org.springframework.ai.ollama.api.OllamaOptions; 30 import org.springframework.ai.ollama.api.OllamaOptions;
30 import org.springframework.ai.openai.OpenAiChatClient; 31 import org.springframework.ai.openai.OpenAiChatClient;
31 import org.springframework.ai.openai.OpenAiChatOptions; 32 import org.springframework.ai.openai.OpenAiChatOptions;
  33 +import org.springframework.ai.openai.OpenAiImageClient;
32 import org.springframework.ai.openai.api.ApiUtils; 34 import org.springframework.ai.openai.api.ApiUtils;
33 import org.springframework.ai.openai.api.OpenAiApi; 35 import org.springframework.ai.openai.api.OpenAiApi;
34 36
@@ -84,6 +86,16 @@ public class AiClientFactoryImpl implements AiClientFactory { @@ -84,6 +86,16 @@ public class AiClientFactoryImpl implements AiClientFactory {
84 } 86 }
85 } 87 }
86 88
  89 + @Override
  90 + public ImageClient getDefaultImageClient(AiPlatformEnum platform) {
  91 + switch (platform) {
  92 + case OPEN_AI_DALL:
  93 + return SpringUtil.getBean(OpenAiImageClient.class);
  94 +
  95 + }
  96 + return null;
  97 + }
  98 +
87 private static String buildClientCacheKey(Class<?> clazz, Object... params) { 99 private static String buildClientCacheKey(Class<?> clazz, Object... params) {
88 if (ArrayUtil.isEmpty(params)) { 100 if (ArrayUtil.isEmpty(params)) {
89 return clazz.getName(); 101 return clazz.getName();
yudao-server/src/main/resources/application.yaml
@@ -144,19 +144,23 @@ spring: @@ -144,19 +144,23 @@ spring:
144 144
145 --- #################### AI 相关配置 #################### 145 --- #################### AI 相关配置 ####################
146 146
147 -spring.ai:  
148 - ollama:  
149 - base-url: http://127.0.0.1:11434  
150 - chat:  
151 - model: llama3  
152 - openai:  
153 - api-key: sk-yzKea6d8e8212c3bdd99f9f44ced1cae37c097e5aa3BTS7z  
154 - base-url: https://api.gptsapi.net  
155 - vertex:  
156 - ai:  
157 - gemini:  
158 - project-id: 1 # TODO 芋艿:缺配置  
159 - location: 2 147 +spring:
  148 + ai:
  149 + ollama:
  150 + base-url: http://127.0.0.1:11434
  151 + chat:
  152 + model: llama3
  153 + openai:
  154 + api-key: sk-yzKea6d8e8212c3bdd99f9f44ced1cae37c097e5aa3BTS7z
  155 + base-url: https://api.gptsapi.net
  156 + stabilityai:
  157 + api-key: sk-e53UqbboF8QJCscYvzJscJxJXoFcFg4iJjl1oqgE7baJETmx
  158 + vertex:
  159 + ai:
  160 + gemini:
  161 + project-id: 1 # TODO 芋艿:缺配置
  162 + location: 2
  163 +
160 164
161 yudao.ai: 165 yudao.ai:
162 yiyan: 166 yiyan:
@@ -202,7 +206,6 @@ yudao.ai: @@ -202,7 +206,6 @@ yudao.ai:
202 suno: 206 suno:
203 enable: true 207 enable: true
204 token: 16b4356581984d538652354b60d69ff0 208 token: 16b4356581984d538652354b60d69ff0
205 -  
206 --- #################### 芋道相关配置 #################### 209 --- #################### 芋道相关配置 ####################
207 210
208 yudao: 211 yudao: