mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-19 03:30:06 +08:00
增加 reRoll,图片选择、图片放大
This commit is contained in:
parent
21b6e9f996
commit
8b980d1e11
@ -20,10 +20,9 @@ public class MjClient {
|
||||
|
||||
static {
|
||||
headers.setContentType(MediaType.APPLICATION_JSON); // 设置内容类型为JSON
|
||||
// headers.set("Authorization", token); // 如果需要,设置认证信息(例如JWT令牌)
|
||||
headers.set("Referer", "https://discord.com/channels/1221445697157468200/1221445862962630706"); // 如果需要,设置认证信息(例如JWT令牌)
|
||||
headers.set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"); // 如果需要,设置认证信息(例如JWT令牌)
|
||||
headers.set("Cookie", "__dcfduid=6ca536c0e3fa11eeb7cbe34c31b49caf; __sdcfduid=6ca536c1e3fa11eeb7cbe34c31b49caf52cce5ffd8983d2a052cf6aba75fe5fe566f2c265902e283ce30dbf98b8c9c93; _gcl_au=1.1.245923998.1710853617; _ga=GA1.1.111061823.1710853617; __cfruid=6385bb3f48345a006b25992db7dcf984e395736d-1712124666; _cfuvid=O09la5ms0ypNptiG0iD8A6BKWlTxz1LG0WR7qRStD7o-1712124666575-0.0.1.1-604800000; locale=zh-CN; cf_clearance=l_YGod1_SUtYxpDVeZXiX7DLLPl1DYrquZe8WVltvYs-1712124668-1.0.1.1-Hl2.fToel23EpF2HCu9J20rB4D7OhhCzoajPSdo.9Up.wPxhvq22DP9RHzEBKuIUlKyH.kJLxXJfAt2N.LD5WQ; OptanonConsent=isIABGlobal=false&datestamp=Wed+Apr+03+2024+14%3A11%3A15+GMT%2B0800+(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4)&version=6.33.0&hosts=&landingPath=https%3A%2F%2Fdiscord.com%2F&groups=C0001%3A1%2CC0002%3A1%2CC0003%3A1; _ga_Q149DFWHT7=GS1.1.1712124668.4.1.1712124679.0.0.0"); // 如果需要,设置认证信息(例如JWT令牌)
|
||||
headers.set("Referer", "https://discord.com/channels/1221445697157468200/1221445862962630706");
|
||||
headers.set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36");
|
||||
headers.set("Cookie", "__dcfduid=6ca536c0e3fa11eeb7cbe34c31b49caf; __sdcfduid=6ca536c1e3fa11eeb7cbe34c31b49caf52cce5ffd8983d2a052cf6aba75fe5fe566f2c265902e283ce30dbf98b8c9c93; _gcl_au=1.1.245923998.1710853617; _ga=GA1.1.111061823.1710853617; __cfruid=6385bb3f48345a006b25992db7dcf984e395736d-1712124666; _cfuvid=O09la5ms0ypNptiG0iD8A6BKWlTxz1LG0WR7qRStD7o-1712124666575-0.0.1.1-604800000; locale=zh-CN; cf_clearance=l_YGod1_SUtYxpDVeZXiX7DLLPl1DYrquZe8WVltvYs-1712124668-1.0.1.1-Hl2.fToel23EpF2HCu9J20rB4D7OhhCzoajPSdo.9Up.wPxhvq22DP9RHzEBKuIUlKyH.kJLxXJfAt2N.LD5WQ; OptanonConsent=isIABGlobal=false&datestamp=Wed+Apr+03+2024+14%3A11%3A15+GMT%2B0800+(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4)&version=6.33.0&hosts=&landingPath=https%3A%2F%2Fdiscord.com%2F&groups=C0001%3A1%2CC0002%3A1%2CC0003%3A1; _ga_Q149DFWHT7=GS1.1.1712124668.4.1.1712124679.0.0.0");
|
||||
}
|
||||
|
||||
public static String post(String url, String token, String body) {
|
||||
|
@ -1,85 +0,0 @@
|
||||
package cn.iocoder.yudao.framework.ai.midjourney.interactions;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.ai.midjourney.MidjourneyConfig;
|
||||
import cn.iocoder.yudao.framework.ai.midjourney.constants.MjInteractionsEnum;
|
||||
import cn.iocoder.yudao.framework.ai.midjourney.vo.ReRoll;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 图片生成
|
||||
*
|
||||
* author: fansili
|
||||
* time: 2024/4/3 17:36
|
||||
*/
|
||||
@Slf4j
|
||||
public class MjImagineInteractions implements MjInteractions {
|
||||
|
||||
private MidjourneyConfig midjourneyConfig;
|
||||
|
||||
public MjImagineInteractions(MidjourneyConfig midjourneyConfig) {
|
||||
this.midjourneyConfig = midjourneyConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MjInteractionsEnum> supperInteractions() {
|
||||
return Lists.newArrayList(MjInteractionsEnum.IMAGINE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean execute(String prompt) {
|
||||
String url = midjourneyConfig.getServerUrl().concat(midjourneyConfig.getApiInteractions());
|
||||
// 获取请求模板
|
||||
String requestTemplate = midjourneyConfig.getRequestTemplates().get("imagine");
|
||||
// 设置参数
|
||||
HashMap<String, String> requestParams = Maps.newHashMap();
|
||||
requestParams.put("guild_id", midjourneyConfig.getGuildId());
|
||||
requestParams.put("channel_id", midjourneyConfig.getChannelId());
|
||||
requestParams.put("session_id", midjourneyConfig.getSessionId());
|
||||
requestParams.put("nonce", String.valueOf(IdUtil.getSnowflakeNextId()));
|
||||
requestParams.put("prompt", prompt);
|
||||
// 设置参数
|
||||
String requestBody = MjClient.setParams(requestTemplate, requestParams);
|
||||
// 发送请求
|
||||
String res = MjClient.post(url, midjourneyConfig.getToken(), requestBody);
|
||||
// 这个 res 只要不返回值,就是成功!
|
||||
boolean isSuccess = StrUtil.isBlank(res);
|
||||
if (isSuccess) {
|
||||
return true;
|
||||
}
|
||||
log.error("请求失败! 请求参数:{} 返回结果! {}", requestBody, res);
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
public Boolean reRoll(ReRoll reRoll) {
|
||||
String url = midjourneyConfig.getServerUrl().concat(midjourneyConfig.getApiInteractions());
|
||||
// 获取请求模板
|
||||
String requestTemplate = midjourneyConfig.getRequestTemplates().get("reroll");
|
||||
// 设置参数
|
||||
HashMap<String, String> requestParams = Maps.newHashMap();
|
||||
requestParams.put("guild_id", midjourneyConfig.getGuildId());
|
||||
requestParams.put("channel_id", midjourneyConfig.getChannelId());
|
||||
requestParams.put("session_id", midjourneyConfig.getSessionId());
|
||||
requestParams.put("nonce", String.valueOf(IdUtil.getSnowflakeNextId()));
|
||||
requestParams.put("custom_id", reRoll.getCustomId());
|
||||
requestParams.put("message_id", reRoll.getMessageId());
|
||||
// 设置参数
|
||||
String requestBody = MjClient.setParams(requestTemplate, requestParams);
|
||||
// 发送请求
|
||||
String res = MjClient.post(url, midjourneyConfig.getToken(), requestBody);
|
||||
// 这个 res 只要不返回值,就是成功!
|
||||
boolean isSuccess = StrUtil.isBlank(res);
|
||||
if (isSuccess) {
|
||||
return true;
|
||||
}
|
||||
log.error("请求失败! 请求参数:{} 返回结果! {}", requestBody, res);
|
||||
return isSuccess;
|
||||
}
|
||||
}
|
@ -1,18 +1,76 @@
|
||||
package cn.iocoder.yudao.framework.ai.midjourney.interactions;
|
||||
|
||||
import cn.iocoder.yudao.framework.ai.midjourney.constants.MjInteractionsEnum;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.ai.midjourney.MidjourneyConfig;
|
||||
import cn.iocoder.yudao.framework.ai.midjourney.vo.ReRoll;
|
||||
import com.google.common.collect.Maps;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* mj Interactions
|
||||
* 图片生成
|
||||
*
|
||||
* author: fansili
|
||||
* time: 2024/4/3 17:22
|
||||
* time: 2024/4/3 17:36
|
||||
*/
|
||||
public interface MjInteractions {
|
||||
@Slf4j
|
||||
public class MjInteractions {
|
||||
|
||||
List<MjInteractionsEnum> supperInteractions();
|
||||
private MidjourneyConfig midjourneyConfig;
|
||||
|
||||
Boolean execute(String prompt);
|
||||
private String url;
|
||||
|
||||
public MjInteractions(MidjourneyConfig midjourneyConfig) {
|
||||
this.midjourneyConfig = midjourneyConfig;
|
||||
this.url = midjourneyConfig.getServerUrl().concat(midjourneyConfig.getApiInteractions());
|
||||
}
|
||||
|
||||
public Boolean imagine(String prompt) {
|
||||
// 获取请求模板
|
||||
String requestTemplate = midjourneyConfig.getRequestTemplates().get("imagine");
|
||||
// 设置参数
|
||||
HashMap<String, String> requestParams = Maps.newHashMap();
|
||||
requestParams.put("guild_id", midjourneyConfig.getGuildId());
|
||||
requestParams.put("channel_id", midjourneyConfig.getChannelId());
|
||||
requestParams.put("session_id", midjourneyConfig.getSessionId());
|
||||
requestParams.put("nonce", String.valueOf(IdUtil.getSnowflakeNextId()));
|
||||
requestParams.put("prompt", prompt);
|
||||
// 设置参数
|
||||
String requestBody = MjClient.setParams(requestTemplate, requestParams);
|
||||
// 发送请求
|
||||
String res = MjClient.post(url, midjourneyConfig.getToken(), requestBody);
|
||||
// 这个 res 只要不返回值,就是成功!
|
||||
boolean isSuccess = StrUtil.isBlank(res);
|
||||
if (isSuccess) {
|
||||
return true;
|
||||
}
|
||||
log.error("请求失败! 请求参数:{} 返回结果! {}", requestBody, res);
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
public Boolean reRoll(ReRoll reRoll) {
|
||||
// 获取请求模板
|
||||
String requestTemplate = midjourneyConfig.getRequestTemplates().get("reroll");
|
||||
// 设置参数
|
||||
HashMap<String, String> requestParams = Maps.newHashMap();
|
||||
requestParams.put("guild_id", midjourneyConfig.getGuildId());
|
||||
requestParams.put("channel_id", midjourneyConfig.getChannelId());
|
||||
requestParams.put("session_id", midjourneyConfig.getSessionId());
|
||||
requestParams.put("nonce", String.valueOf(IdUtil.getSnowflakeNextId()));
|
||||
requestParams.put("custom_id", reRoll.getCustomId());
|
||||
requestParams.put("message_id", reRoll.getMessageId());
|
||||
// 设置参数
|
||||
String requestBody = MjClient.setParams(requestTemplate, requestParams);
|
||||
// 发送请求
|
||||
String res = MjClient.post(url, midjourneyConfig.getToken(), requestBody);
|
||||
// 这个 res 只要不返回值,就是成功!
|
||||
boolean isSuccess = StrUtil.isBlank(res);
|
||||
if (isSuccess) {
|
||||
return true;
|
||||
}
|
||||
log.error("请求失败! 请求参数:{} 返回结果! {}", requestBody, res);
|
||||
return isSuccess;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user