mirror of
https://gitee.com/myxzgzs/boyue-vue-pro.git
synced 2025-08-08 16:32:46 +08:00
!1294 【功能新增】AI:画图通用功能增加硅基流动平台
Merge pull request !1294 from 拽拽的哥/feature/ai
This commit is contained in:
commit
5dc93cb872
@ -0,0 +1,36 @@
|
||||
package cn.iocoder.yudao.module.ai.controller.admin.creation;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.ai.controller.admin.creation.vo.style.AiartReplaceBackgroundReqVO;
|
||||
import cn.iocoder.yudao.module.ai.controller.admin.creation.vo.style.AiartReplaceBackgroundResVO;
|
||||
import cn.iocoder.yudao.module.ai.service.creation.AiartCreationService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
@Tag(name = "管理后台 - 艺术创作")
|
||||
@RestController
|
||||
@RequestMapping("/ai/artcreation")
|
||||
@Validated
|
||||
public class AiartCreationController {
|
||||
|
||||
@Resource
|
||||
private AiartCreationService aiartCreationService;
|
||||
|
||||
@Operation(summary = "商品图替换背景")
|
||||
@PostMapping("/replacebackground")
|
||||
public CommonResult<AiartReplaceBackgroundResVO> replaceBackground(@Valid @RequestBody AiartReplaceBackgroundReqVO replaceBackgroundReqVO) {
|
||||
return success(aiartCreationService.replaceBackground(getLoginUserId(), replaceBackgroundReqVO));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package cn.iocoder.yudao.module.ai.controller.admin.creation;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.ai.controller.admin.creation.vo.style.BackgroundTemplateReqVO;
|
||||
import cn.iocoder.yudao.module.ai.controller.admin.creation.vo.style.BackgroundTemplateResVO;
|
||||
import cn.iocoder.yudao.module.ai.dal.dataobject.creation.AiartStyleBackgroundTemplateDO;
|
||||
import cn.iocoder.yudao.module.ai.service.creation.AiartStyleService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - 艺术创作模版")
|
||||
@RestController
|
||||
@RequestMapping("/ai/artstyle")
|
||||
@Validated
|
||||
public class AiartStyleController {
|
||||
|
||||
@Resource
|
||||
private AiartStyleService aiartStyleService;
|
||||
|
||||
@PostMapping("/backgroundtemplate-list")
|
||||
@Operation(summary = "获取商品背景模版列表")
|
||||
@PreAuthorize("@ss.hasPermission('ai:artstyle-background:query')")
|
||||
public CommonResult<List<BackgroundTemplateResVO>> queryBackgroundStyle(@Valid @RequestBody BackgroundTemplateReqVO backgroundTemplateReqVO) {
|
||||
List<AiartStyleBackgroundTemplateDO> res = aiartStyleService.queryBackgroundStyle(backgroundTemplateReqVO);
|
||||
return success(BeanUtils.toBean(res,BackgroundTemplateResVO.class));
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package cn.iocoder.yudao.module.ai.controller.admin.creation.vo.style;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 商品替换背景请求 VO")
|
||||
@Data
|
||||
public class AiartReplaceBackgroundReqVO {
|
||||
|
||||
@Schema(description = "提示词", requiredMode = Schema.RequiredMode.REQUIRED, example = "画一个长城")
|
||||
@NotEmpty(message = "提示词不能为空")
|
||||
@Size(max = 1200, message = "提示词最大 1200")
|
||||
private String prompt;
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package cn.iocoder.yudao.module.ai.controller.admin.creation.vo.style;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 商品替换背景结果 VO")
|
||||
@Data
|
||||
public class AiartReplaceBackgroundResVO {
|
||||
|
||||
@Schema(description = "结果url", requiredMode = Schema.RequiredMode.REQUIRED, example = "根据参数不同不一样")
|
||||
private String resultImage;
|
||||
|
||||
@Schema(description = "唯一请求 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "由服务端生成")
|
||||
private String requestId;
|
||||
|
||||
@Schema(description = "MaskUrl", requiredMode = Schema.RequiredMode.REQUIRED, example = "如果 MaskUrl 未传,则返回使用内置商品分割算法得到的 Mask 结果")
|
||||
private String maskImage;
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package cn.iocoder.yudao.module.ai.controller.admin.creation.vo.style;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - AI API 密钥新增/修改 Request VO")
|
||||
@Data
|
||||
public class BackgroundTemplateReqVO {
|
||||
|
||||
@Schema(description = "一级级次名称", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "通用")
|
||||
private String fistLevelName;
|
||||
|
||||
@Schema(description = "二级级次名称", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "色彩背景")
|
||||
private String secondLevelName;
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package cn.iocoder.yudao.module.ai.controller.admin.creation.vo.style;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 商品替换背景模版 VO")
|
||||
@Data
|
||||
public class BackgroundTemplateResVO {
|
||||
|
||||
@Schema(description = "一级分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "汽车、通用")
|
||||
private String levelFirst;
|
||||
|
||||
@Schema(description = "二级分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "色彩背景")
|
||||
private String levelSecond;
|
||||
|
||||
@Schema(description = "背景模版名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "彩虹渐变")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "背景模版提示词", requiredMode = Schema.RequiredMode.REQUIRED, example = "背景为彩虹渐变墙面,亮暖色,清新简约风格,喷涂效果")
|
||||
private String prompt;
|
||||
|
||||
@Schema(description = "背景模版商品示例", requiredMode = Schema.RequiredMode.REQUIRED, example = "小熊玩偶")
|
||||
private String demProduct;
|
||||
|
||||
@Schema(description = "背景模版商品示例效果", requiredMode = Schema.RequiredMode.REQUIRED, example = "url")
|
||||
private String demUrl;
|
||||
}
|
||||
|
@ -0,0 +1,65 @@
|
||||
package cn.iocoder.yudao.module.ai.dal.dataobject.creation;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* AI art商品背景风格 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("ai_backgroundtemplate")
|
||||
@KeySequence("ai_chat_conversation_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AiartStyleBackgroundTemplateDO extends BaseDO {
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String levelFirst;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String levelSecond;
|
||||
/**
|
||||
* 模版名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 模版提示词
|
||||
*/
|
||||
private String prompt;
|
||||
/**
|
||||
* 示例商品
|
||||
*/
|
||||
private String demoProduct;
|
||||
|
||||
/**
|
||||
* 示例效果
|
||||
*/
|
||||
private String demoUrl;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 枚举 {@link CommonStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package cn.iocoder.yudao.module.ai.dal.mysql.creation;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.ai.controller.admin.creation.vo.style.BackgroundTemplateReqVO;
|
||||
import cn.iocoder.yudao.module.ai.dal.dataobject.creation.AiartStyleBackgroundTemplateDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* AI style分隔 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface AiartStyleBackgroundTemplateMapper extends BaseMapperX<AiartStyleBackgroundTemplateDO> {
|
||||
|
||||
/**
|
||||
* 获取有效的商品后端模版
|
||||
* @param reqVO 请求对象
|
||||
* @return 结果
|
||||
*/
|
||||
default List<AiartStyleBackgroundTemplateDO> selectList(BackgroundTemplateReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<AiartStyleBackgroundTemplateDO>()
|
||||
.eqIfPresent(AiartStyleBackgroundTemplateDO::getLevelFirst,reqVO.getFistLevelName())
|
||||
.eqIfPresent(AiartStyleBackgroundTemplateDO::getLevelSecond,reqVO.getSecondLevelName())
|
||||
.eqIfPresent(AiartStyleBackgroundTemplateDO::getStatus, CommonStatusEnum.ENABLE.getStatus())
|
||||
.orderByDesc(AiartStyleBackgroundTemplateDO::getId));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package cn.iocoder.yudao.module.ai.service.creation;
|
||||
|
||||
import cn.iocoder.yudao.module.ai.controller.admin.creation.vo.style.AiartReplaceBackgroundReqVO;
|
||||
import cn.iocoder.yudao.module.ai.controller.admin.creation.vo.style.AiartReplaceBackgroundResVO;
|
||||
|
||||
/**
|
||||
* AI创作Service 接口
|
||||
*
|
||||
* @author zzt
|
||||
*/
|
||||
public interface AiartCreationService {
|
||||
|
||||
|
||||
/**
|
||||
* 替换商品背景图片
|
||||
* @param loginUserId 当前登录用户
|
||||
* @param replaceBackgroundReqVO 请求对象
|
||||
* @return 结果
|
||||
*/
|
||||
AiartReplaceBackgroundResVO replaceBackground(Long loginUserId, AiartReplaceBackgroundReqVO replaceBackgroundReqVO);
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package cn.iocoder.yudao.module.ai.service.creation;
|
||||
|
||||
import cn.iocoder.yudao.module.ai.controller.admin.creation.vo.style.AiartReplaceBackgroundReqVO;
|
||||
import cn.iocoder.yudao.module.ai.controller.admin.creation.vo.style.AiartReplaceBackgroundResVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
/**
|
||||
* AI创作Service 实现类
|
||||
*
|
||||
* @author zzt
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class AiartCreationServiceImpl implements AiartCreationService {
|
||||
|
||||
|
||||
@Override
|
||||
public AiartReplaceBackgroundResVO replaceBackground(Long loginUserId, AiartReplaceBackgroundReqVO replaceBackgroundReqVO) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package cn.iocoder.yudao.module.ai.service.creation;
|
||||
|
||||
import cn.iocoder.yudao.module.ai.controller.admin.creation.vo.style.BackgroundTemplateReqVO;
|
||||
import cn.iocoder.yudao.module.ai.controller.admin.creation.vo.style.BackgroundTemplateResVO;
|
||||
import cn.iocoder.yudao.module.ai.dal.dataobject.creation.AiartStyleBackgroundTemplateDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* AI风格Service 接口
|
||||
*
|
||||
* @author zzt
|
||||
*/
|
||||
public interface AiartStyleService {
|
||||
|
||||
|
||||
/**
|
||||
* 查询商品背景模版列表
|
||||
* @param backgroundTemplateReqVO 商品背景模版请求对象
|
||||
* @return 结果
|
||||
*/
|
||||
List<AiartStyleBackgroundTemplateDO> queryBackgroundStyle(BackgroundTemplateReqVO backgroundTemplateReqVO);
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package cn.iocoder.yudao.module.ai.service.creation;
|
||||
|
||||
import cn.iocoder.yudao.module.ai.controller.admin.creation.vo.style.BackgroundTemplateReqVO;
|
||||
import cn.iocoder.yudao.module.ai.controller.admin.creation.vo.style.BackgroundTemplateResVO;
|
||||
import cn.iocoder.yudao.module.ai.dal.dataobject.creation.AiartStyleBackgroundTemplateDO;
|
||||
import cn.iocoder.yudao.module.ai.dal.mysql.creation.AiartStyleBackgroundTemplateMapper;
|
||||
import cn.iocoder.yudao.module.ai.dal.mysql.model.AiApiKeyMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* AI风格Service 接口
|
||||
*
|
||||
* @author zzt
|
||||
*/
|
||||
public class AiartStyleServiceImpl implements AiartStyleService{
|
||||
|
||||
@Resource
|
||||
private AiartStyleBackgroundTemplateMapper backgroundTemplateMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public List<AiartStyleBackgroundTemplateDO> queryBackgroundStyle(BackgroundTemplateReqVO backgroundTemplateReqVO) {
|
||||
return backgroundTemplateMapper.selectList(backgroundTemplateReqVO);
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiliconflowImageOptions;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageDrawReqVO;
|
||||
@ -144,7 +145,12 @@ public class AiImageServiceImpl implements AiImageService {
|
||||
.withStyle(MapUtil.getStr(draw.getOptions(), "style")) // 风格
|
||||
.withResponseFormat("b64_json")
|
||||
.build();
|
||||
} else if (ObjUtil.equal(model.getPlatform(), AiPlatformEnum.STABLE_DIFFUSION.getPlatform())) {
|
||||
} else if (ObjUtil.equal(model.getPlatform(), AiPlatformEnum.SILICON_FLOW.getPlatform())) {
|
||||
// https://docs.siliconflow.cn/cn/api-reference/images/images-generations
|
||||
return SiliconflowImageOptions.builder().withModel(model.getModel())
|
||||
.withHeight(draw.getHeight()).withWidth(draw.getWidth())
|
||||
.build();
|
||||
} else if (ObjUtil.equal(model.getPlatform(), AiPlatformEnum.STABLE_DIFFUSION.getPlatform())) {
|
||||
// https://platform.stability.ai/docs/api-reference#tag/SDXL-and-SD1.6/operation/textToImage
|
||||
// https://platform.stability.ai/docs/api-reference#tag/Text-to-Image/operation/textToImage
|
||||
return StabilityAiImageOptions.builder().model(model.getModel())
|
||||
|
@ -117,6 +117,13 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- 腾讯大模型图像创作引擎-->
|
||||
<dependency>
|
||||
<groupId>com.tencentcloudapi</groupId>
|
||||
<artifactId>tencentcloud-sdk-java-aiart</artifactId>
|
||||
<version>3.1.1215</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Test 测试相关 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@ -8,6 +8,8 @@ import cn.iocoder.yudao.framework.ai.core.model.deepseek.DeepSeekChatModel;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.doubao.DouBaoChatModel;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.hunyuan.HunYuanChatModel;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiiconflowApiConstants;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiiconflowmageApi;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiliconFlowChatModel;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.suno.api.SunoApi;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoChatModel;
|
||||
@ -113,11 +115,11 @@ public class YudaoAiAutoConfiguration {
|
||||
|
||||
public SiliconFlowChatModel buildSiliconFlowChatClient(YudaoAiProperties.SiliconFlowProperties properties) {
|
||||
if (StrUtil.isEmpty(properties.getModel())) {
|
||||
properties.setModel(SiliconFlowChatModel.MODEL_DEFAULT);
|
||||
properties.setModel(SiiconflowApiConstants.MODEL_DEFAULT);
|
||||
}
|
||||
OpenAiChatModel openAiChatModel = OpenAiChatModel.builder()
|
||||
.openAiApi(OpenAiApi.builder()
|
||||
.baseUrl(SiliconFlowChatModel.BASE_URL)
|
||||
.baseUrl(SiiconflowApiConstants.DEFAULT_BASE_URL)
|
||||
.apiKey(properties.getApiKey())
|
||||
.build())
|
||||
.defaultOptions(OpenAiChatOptions.builder()
|
||||
|
@ -15,7 +15,10 @@ import cn.iocoder.yudao.framework.ai.core.model.deepseek.DeepSeekChatModel;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.doubao.DouBaoChatModel;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.hunyuan.HunYuanChatModel;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiiconflowApiConstants;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiiconflowmageApi;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiliconFlowChatModel;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiliconflowImageModel;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.suno.api.SunoApi;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoChatModel;
|
||||
import cn.iocoder.yudao.framework.common.util.spring.SpringUtils;
|
||||
@ -224,6 +227,8 @@ public class AiModelFactoryImpl implements AiModelFactory {
|
||||
return buildZhiPuAiImageModel(apiKey, url);
|
||||
case OPENAI:
|
||||
return buildOpenAiImageModel(apiKey, url);
|
||||
case SILICON_FLOW:
|
||||
return buildSiiconflowImageModel(apiKey,url);
|
||||
case STABLE_DIFFUSION:
|
||||
return buildStabilityAiImageModel(apiKey, url);
|
||||
default:
|
||||
@ -468,6 +473,15 @@ public class AiModelFactoryImpl implements AiModelFactory {
|
||||
return new OpenAiImageModel(openAiApi);
|
||||
}
|
||||
|
||||
/**
|
||||
* Siiconflow
|
||||
*/
|
||||
private SiliconflowImageModel buildSiiconflowImageModel(String apiToken, String url) {
|
||||
url = StrUtil.blankToDefault(url, SiiconflowApiConstants.DEFAULT_BASE_URL);
|
||||
SiiconflowmageApi openAiApi = SiiconflowmageApi.builder().baseUrl(url).apiKey(apiToken).build();
|
||||
return new SiliconflowImageModel(openAiApi);
|
||||
}
|
||||
|
||||
/**
|
||||
* 可参考 {@link OllamaAutoConfiguration} 的 ollamaApi 方法
|
||||
*/
|
||||
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.iocoder.yudao.framework.ai.core.model.siliconflow;
|
||||
|
||||
/**
|
||||
* Common value constants for Siiconflow api.
|
||||
*
|
||||
* @author zzt
|
||||
*/
|
||||
public final class SiiconflowApiConstants {
|
||||
|
||||
public static final String DEFAULT_BASE_URL = "https://api.siliconflow.cn";
|
||||
|
||||
public static final String MODEL_DEFAULT = "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B";
|
||||
|
||||
public static final String PROVIDER_NAME = "Siiconflow";
|
||||
|
||||
private SiiconflowApiConstants() {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.iocoder.yudao.framework.ai.core.model.siliconflow;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.springframework.ai.model.ApiKey;
|
||||
import org.springframework.ai.model.NoopApiKey;
|
||||
import org.springframework.ai.model.SimpleApiKey;
|
||||
import org.springframework.ai.openai.api.OpenAiImageApi;
|
||||
import org.springframework.ai.retry.RetryUtils;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.ResponseErrorHandler;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Siiconflow Image API.
|
||||
*
|
||||
* @see <a href= "https://docs.siliconflow.cn/cn/api-reference/images/images-generations">Images</a>
|
||||
*
|
||||
* @author zzt
|
||||
*/
|
||||
public class SiiconflowmageApi {
|
||||
|
||||
private final RestClient restClient;
|
||||
|
||||
/**
|
||||
* Create a new Siiconflow Image api with base URL set.
|
||||
* @param aiToken OpenAI apiKey.
|
||||
*/
|
||||
public SiiconflowmageApi(String aiToken) {
|
||||
this(SiiconflowApiConstants.DEFAULT_BASE_URL, aiToken, RestClient.builder());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Siiconflow Image API with the provided base URL.
|
||||
* @param baseUrl the base URL for the OpenAI API.
|
||||
* @param openAiToken Siiconflow apiKey.
|
||||
*/
|
||||
public SiiconflowmageApi(String baseUrl, String openAiToken, RestClient.Builder restClientBuilder) {
|
||||
this(baseUrl, openAiToken, restClientBuilder, RetryUtils.DEFAULT_RESPONSE_ERROR_HANDLER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new OpenAI Image API with the provided base URL.
|
||||
* @param baseUrl the base URL for the OpenAI API.
|
||||
* @param apiKey OpenAI apiKey.
|
||||
* @param restClientBuilder the rest client builder to use.
|
||||
*/
|
||||
public SiiconflowmageApi(String baseUrl, String apiKey, RestClient.Builder restClientBuilder,
|
||||
ResponseErrorHandler responseErrorHandler) {
|
||||
this(baseUrl, apiKey, CollectionUtils.toMultiValueMap(Map.of()), restClientBuilder, responseErrorHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new OpenAI Image API with the provided base URL.
|
||||
* @param baseUrl the base URL for the OpenAI API.
|
||||
* @param apiKey OpenAI apiKey.
|
||||
* @param headers the http headers to use.
|
||||
* @param restClientBuilder the rest client builder to use.
|
||||
* @param responseErrorHandler the response error handler to use.
|
||||
*/
|
||||
public SiiconflowmageApi(String baseUrl, String apiKey, MultiValueMap<String, String> headers,
|
||||
RestClient.Builder restClientBuilder, ResponseErrorHandler responseErrorHandler) {
|
||||
|
||||
this(baseUrl, new SimpleApiKey(apiKey), headers, restClientBuilder, responseErrorHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new OpenAI Image API with the provided base URL.
|
||||
* @param baseUrl the base URL for the OpenAI API.
|
||||
* @param apiKey OpenAI apiKey.
|
||||
* @param headers the http headers to use.
|
||||
* @param restClientBuilder the rest client builder to use.
|
||||
* @param responseErrorHandler the response error handler to use.
|
||||
*/
|
||||
public SiiconflowmageApi(String baseUrl, ApiKey apiKey, MultiValueMap<String, String> headers,
|
||||
RestClient.Builder restClientBuilder, ResponseErrorHandler responseErrorHandler) {
|
||||
|
||||
// @formatter:off
|
||||
this.restClient = restClientBuilder.baseUrl(baseUrl)
|
||||
.defaultHeaders(h -> {
|
||||
if(!(apiKey instanceof NoopApiKey)) {
|
||||
h.setBearerAuth(apiKey.getValue());
|
||||
}
|
||||
h.setContentType(MediaType.APPLICATION_JSON);
|
||||
h.addAll(headers);
|
||||
})
|
||||
.defaultStatusHandler(responseErrorHandler)
|
||||
.build();
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
public ResponseEntity<OpenAiImageApi.OpenAiImageResponse> createImage(SiliconflowImageRequest siliconflowImageRequest) {
|
||||
Assert.notNull(siliconflowImageRequest, "Image request cannot be null.");
|
||||
Assert.hasLength(siliconflowImageRequest.prompt(), "Prompt cannot be empty.");
|
||||
|
||||
return this.restClient.post()
|
||||
.uri("v1/images/generations")
|
||||
.body(siliconflowImageRequest)
|
||||
.retrieve()
|
||||
.toEntity(OpenAiImageApi.OpenAiImageResponse.class);
|
||||
}
|
||||
|
||||
|
||||
// @formatter:off
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record SiliconflowImageRequest (
|
||||
@JsonProperty("prompt") String prompt,
|
||||
@JsonProperty("model") String model,
|
||||
@JsonProperty("batch_size") Integer batchSize,
|
||||
@JsonProperty("negative_prompt") String negativePrompt,
|
||||
@JsonProperty("seed") Integer seed,
|
||||
@JsonProperty("num_inference_steps") Integer numInferenceSteps,
|
||||
@JsonProperty("guidance_scale") Float guidanceScale,
|
||||
@JsonProperty("image") String image) {
|
||||
|
||||
public SiliconflowImageRequest(String prompt, String model) {
|
||||
this(prompt, model, null, null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder to construct {@link SiiconflowmageApi} instance.
|
||||
*/
|
||||
public static class Builder {
|
||||
|
||||
private String baseUrl = SiiconflowApiConstants.DEFAULT_BASE_URL;
|
||||
|
||||
private ApiKey apiKey;
|
||||
|
||||
private MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
|
||||
|
||||
private RestClient.Builder restClientBuilder = RestClient.builder();
|
||||
|
||||
private ResponseErrorHandler responseErrorHandler = RetryUtils.DEFAULT_RESPONSE_ERROR_HANDLER;
|
||||
|
||||
public Builder baseUrl(String baseUrl) {
|
||||
Assert.hasText(baseUrl, "baseUrl cannot be null or empty");
|
||||
this.baseUrl = baseUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder apiKey(ApiKey apiKey) {
|
||||
Assert.notNull(apiKey, "apiKey cannot be null");
|
||||
this.apiKey = apiKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder apiKey(String simpleApiKey) {
|
||||
Assert.notNull(simpleApiKey, "simpleApiKey cannot be null");
|
||||
this.apiKey = new SimpleApiKey(simpleApiKey);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder headers(MultiValueMap<String, String> headers) {
|
||||
Assert.notNull(headers, "headers cannot be null");
|
||||
this.headers = headers;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder restClientBuilder(RestClient.Builder restClientBuilder) {
|
||||
Assert.notNull(restClientBuilder, "restClientBuilder cannot be null");
|
||||
this.restClientBuilder = restClientBuilder;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder responseErrorHandler(ResponseErrorHandler responseErrorHandler) {
|
||||
Assert.notNull(responseErrorHandler, "responseErrorHandler cannot be null");
|
||||
this.responseErrorHandler = responseErrorHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SiiconflowmageApi build() {
|
||||
Assert.notNull(this.apiKey, "apiKey must be set");
|
||||
return new SiiconflowmageApi(this.baseUrl, this.apiKey, this.headers, this.restClientBuilder,
|
||||
this.responseErrorHandler);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -20,10 +20,6 @@ import reactor.core.publisher.Flux;
|
||||
@RequiredArgsConstructor
|
||||
public class SiliconFlowChatModel implements ChatModel {
|
||||
|
||||
public static final String BASE_URL = "https://api.siliconflow.cn";
|
||||
|
||||
public static final String MODEL_DEFAULT = "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B";
|
||||
|
||||
/**
|
||||
* 兼容 OpenAI 接口,进行复用
|
||||
*/
|
||||
|
@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.iocoder.yudao.framework.ai.core.model.siliconflow;
|
||||
|
||||
import io.micrometer.observation.ObservationRegistry;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ai.image.*;
|
||||
import org.springframework.ai.image.observation.DefaultImageModelObservationConvention;
|
||||
import org.springframework.ai.image.observation.ImageModelObservationContext;
|
||||
import org.springframework.ai.image.observation.ImageModelObservationConvention;
|
||||
import org.springframework.ai.image.observation.ImageModelObservationDocumentation;
|
||||
import org.springframework.ai.model.ModelOptionsUtils;
|
||||
import org.springframework.ai.openai.api.OpenAiImageApi;
|
||||
import org.springframework.ai.openai.api.common.OpenAiApiConstants;
|
||||
import org.springframework.ai.openai.metadata.OpenAiImageGenerationMetadata;
|
||||
import org.springframework.ai.retry.RetryUtils;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.retry.support.RetryTemplate;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* cv openapi图片模型方法
|
||||
*
|
||||
* @author zzt
|
||||
*/
|
||||
public class SiliconflowImageModel implements ImageModel {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SiliconflowImageModel.class);
|
||||
|
||||
private static final ImageModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultImageModelObservationConvention();
|
||||
|
||||
/**
|
||||
* The default options used for the image completion requests.
|
||||
*/
|
||||
private final SiliconflowImageOptions defaultOptions;
|
||||
|
||||
/**
|
||||
* The retry template used to retry the OpenAI Image API calls.
|
||||
*/
|
||||
private final RetryTemplate retryTemplate;
|
||||
|
||||
/**
|
||||
* Low-level access to the OpenAI Image API.
|
||||
*/
|
||||
private final SiiconflowmageApi siiconflowmageApi;
|
||||
|
||||
/**
|
||||
* Observation registry used for instrumentation.
|
||||
*/
|
||||
private final ObservationRegistry observationRegistry;
|
||||
|
||||
/**
|
||||
* Conventions to use for generating observations.
|
||||
*/
|
||||
private ImageModelObservationConvention observationConvention = DEFAULT_OBSERVATION_CONVENTION;
|
||||
|
||||
/**
|
||||
* Creates an instance of the OpenAiImageModel.
|
||||
* @param siiconflowmageApi The OpenAiImageApi instance to be used for interacting with
|
||||
* the OpenAI Image API.
|
||||
* @throws IllegalArgumentException if openAiImageApi is null
|
||||
*/
|
||||
public SiliconflowImageModel(SiiconflowmageApi siiconflowmageApi) {
|
||||
this(siiconflowmageApi, SiliconflowImageOptions.builder().build(), RetryUtils.DEFAULT_RETRY_TEMPLATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of the OpenAiImageModel.
|
||||
* @param siiconflowmageApi The OpenAiImageApi instance to be used for interacting with
|
||||
* the OpenAI Image API.
|
||||
* @param options The OpenAiImageOptions to configure the image model.
|
||||
* @param retryTemplate The retry template.
|
||||
*/
|
||||
public SiliconflowImageModel(SiiconflowmageApi siiconflowmageApi, SiliconflowImageOptions options, RetryTemplate retryTemplate) {
|
||||
this(siiconflowmageApi, options, retryTemplate, ObservationRegistry.NOOP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of the OpenAiImageModel.
|
||||
* @param siiconflowmageApi The OpenAiImageApi instance to be used for interacting with
|
||||
* the OpenAI Image API.
|
||||
* @param options The OpenAiImageOptions to configure the image model.
|
||||
* @param retryTemplate The retry template.
|
||||
* @param observationRegistry The ObservationRegistry used for instrumentation.
|
||||
*/
|
||||
public SiliconflowImageModel(SiiconflowmageApi siiconflowmageApi, SiliconflowImageOptions options, RetryTemplate retryTemplate,
|
||||
ObservationRegistry observationRegistry) {
|
||||
Assert.notNull(siiconflowmageApi, "OpenAiImageApi must not be null");
|
||||
Assert.notNull(options, "options must not be null");
|
||||
Assert.notNull(retryTemplate, "retryTemplate must not be null");
|
||||
Assert.notNull(observationRegistry, "observationRegistry must not be null");
|
||||
this.siiconflowmageApi = siiconflowmageApi;
|
||||
this.defaultOptions = options;
|
||||
this.retryTemplate = retryTemplate;
|
||||
this.observationRegistry = observationRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageResponse call(ImagePrompt imagePrompt) {
|
||||
SiiconflowmageApi.SiliconflowImageRequest imageRequest = createRequest(imagePrompt);
|
||||
|
||||
var observationContext = ImageModelObservationContext.builder()
|
||||
.imagePrompt(imagePrompt)
|
||||
.provider(OpenAiApiConstants.PROVIDER_NAME)
|
||||
.requestOptions(imagePrompt.getOptions())
|
||||
.build();
|
||||
|
||||
return ImageModelObservationDocumentation.IMAGE_MODEL_OPERATION
|
||||
.observation(this.observationConvention, DEFAULT_OBSERVATION_CONVENTION, () -> observationContext,
|
||||
this.observationRegistry)
|
||||
.observe(() -> {
|
||||
ResponseEntity<OpenAiImageApi.OpenAiImageResponse> imageResponseEntity = this.retryTemplate
|
||||
.execute(ctx -> this.siiconflowmageApi.createImage(imageRequest));
|
||||
|
||||
ImageResponse imageResponse = convertResponse(imageResponseEntity, imageRequest);
|
||||
|
||||
observationContext.setResponse(imageResponse);
|
||||
|
||||
return imageResponse;
|
||||
});
|
||||
}
|
||||
|
||||
private SiiconflowmageApi.SiliconflowImageRequest createRequest(ImagePrompt imagePrompt) {
|
||||
String instructions = imagePrompt.getInstructions().get(0).getText();
|
||||
|
||||
SiiconflowmageApi.SiliconflowImageRequest imageRequest = new SiiconflowmageApi.SiliconflowImageRequest(instructions,
|
||||
imagePrompt.getOptions().getModel());
|
||||
|
||||
return ModelOptionsUtils.merge(imagePrompt.getOptions(), imageRequest, SiiconflowmageApi.SiliconflowImageRequest.class);
|
||||
}
|
||||
|
||||
private ImageResponse convertResponse(ResponseEntity<OpenAiImageApi.OpenAiImageResponse> imageResponseEntity,
|
||||
SiiconflowmageApi.SiliconflowImageRequest siliconflowImageRequest) {
|
||||
OpenAiImageApi.OpenAiImageResponse imageApiResponse = imageResponseEntity.getBody();
|
||||
if (imageApiResponse == null) {
|
||||
logger.warn("No image response returned for request: {}", siliconflowImageRequest);
|
||||
return new ImageResponse(List.of());
|
||||
}
|
||||
|
||||
List<ImageGeneration> imageGenerationList = imageApiResponse.data()
|
||||
.stream()
|
||||
.map(entry -> new ImageGeneration(new Image(entry.url(), entry.b64Json()),
|
||||
new OpenAiImageGenerationMetadata(entry.revisedPrompt())))
|
||||
.toList();
|
||||
|
||||
ImageResponseMetadata openAiImageResponseMetadata = new ImageResponseMetadata(imageApiResponse.created());
|
||||
return new ImageResponse(imageGenerationList, openAiImageResponseMetadata);
|
||||
}
|
||||
}
|
@ -0,0 +1,166 @@
|
||||
package cn.iocoder.yudao.framework.ai.core.model.siliconflow;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.ai.image.ImageOptions;
|
||||
import org.springframework.ai.openai.OpenAiImageOptions;
|
||||
|
||||
/**
|
||||
* 硅基流动画图能力
|
||||
*
|
||||
* @author zzt
|
||||
*/
|
||||
@Data
|
||||
public class SiliconflowImageOptions implements ImageOptions {
|
||||
|
||||
@JsonProperty("model")
|
||||
private String model;
|
||||
|
||||
@JsonProperty("negative_prompt")
|
||||
private String negativePrompt;
|
||||
|
||||
/**
|
||||
* The number of images to generate. Must be between 1 and 4.
|
||||
*/
|
||||
@JsonProperty("image_size")
|
||||
private String imageSize;
|
||||
|
||||
/**
|
||||
* The number of images to generate. Must be between 1 and 4.
|
||||
*/
|
||||
@JsonProperty("batch_size")
|
||||
private Integer batchSize = 1;
|
||||
|
||||
/**
|
||||
* number of inference steps
|
||||
*/
|
||||
@JsonProperty("num_inference_steps")
|
||||
private Integer numInferenceSteps = 25;
|
||||
|
||||
|
||||
/**
|
||||
* This value is used to control the degree of match between the generated image and the given prompt. The higher the value, the more the generated image will tend to strictly match the text prompt. The lower the value, the more creative and diverse the generated image will be, potentially containing more unexpected elements.
|
||||
*
|
||||
* Required range: 0 <= x <= 20
|
||||
*/
|
||||
@JsonProperty("guidance_scale")
|
||||
private Float guidanceScale = 0.75F;
|
||||
|
||||
/**
|
||||
* 如果想要每次都生成固定的图片,可以把seed设置为固定值。
|
||||
*
|
||||
*/
|
||||
@JsonProperty("seed")
|
||||
private Integer seed = (int)(Math.random() * 1_000_000_000);
|
||||
|
||||
/**
|
||||
* The image that needs to be uploaded should be converted into base64 format.
|
||||
*/
|
||||
@JsonProperty("image")
|
||||
private String image;
|
||||
|
||||
|
||||
/**
|
||||
* 宽
|
||||
*/
|
||||
private Integer width;
|
||||
|
||||
|
||||
/**
|
||||
* 高
|
||||
*/
|
||||
private Integer height;
|
||||
|
||||
public void setHeight(Integer height) {
|
||||
this.height = height;
|
||||
if (this.width != null && this.height != null) {
|
||||
this.imageSize = this.width + "x" + this.height;
|
||||
}
|
||||
}
|
||||
|
||||
public void setWidth(Integer width) {
|
||||
this.width = width;
|
||||
if (this.width != null && this.height != null) {
|
||||
this.imageSize = this.width + "x" + this.height;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 硅基流动
|
||||
* @return
|
||||
*/
|
||||
public static SiliconflowImageOptions.Builder builder() {
|
||||
return new SiliconflowImageOptions.Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
return "SiliconflowImageOptions{" + "model='" + getModel() + '\'' + ", batch_size=" + batchSize + ", imageSize=" + imageSize + ", negativePrompt='"
|
||||
+ negativePrompt + '\'' + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getN() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResponseFormat() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStyle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class Builder extends OpenAiImageOptions{
|
||||
|
||||
private final SiliconflowImageOptions options;
|
||||
|
||||
private Builder() {
|
||||
this.options = new SiliconflowImageOptions();
|
||||
}
|
||||
|
||||
public SiliconflowImageOptions.Builder model(String model) {
|
||||
this.options.setModel(model);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SiliconflowImageOptions.Builder withBatchSize(Integer batchSize) {
|
||||
options.setBatchSize(batchSize);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SiliconflowImageOptions.Builder withModel(String model) {
|
||||
options.setModel(model);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SiliconflowImageOptions.Builder withWidth(Integer width) {
|
||||
options.setWidth(width);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SiliconflowImageOptions.Builder withHeight(Integer height) {
|
||||
options.setHeight(height);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SiliconflowImageOptions.Builder withSeed(Integer seed) {
|
||||
options.setSeed(seed);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SiliconflowImageOptions.Builder withNegativePrompt(String negativePrompt) {
|
||||
options.setNegativePrompt(negativePrompt);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SiliconflowImageOptions build() {
|
||||
return options;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -50,8 +50,8 @@ public class AiUtils {
|
||||
case HUN_YUAN: // 复用 OpenAI 客户端
|
||||
case XING_HUO: // 复用 OpenAI 客户端
|
||||
case SILICON_FLOW: // 复用 OpenAI 客户端
|
||||
return OpenAiChatOptions.builder().model(model).temperature(temperature).maxTokens(maxTokens)
|
||||
.toolNames(toolNames).build();
|
||||
OpenAiChatOptions.Builder builder = OpenAiChatOptions.builder().model(model).temperature(temperature).maxTokens(maxTokens);
|
||||
return toolNames == null ? builder.build() : builder.toolNames(toolNames).build();
|
||||
case AZURE_OPENAI:
|
||||
// TODO 芋艿:貌似没 model 字段???!
|
||||
return AzureOpenAiChatOptions.builder().deploymentName(model).temperature(temperature).maxTokens(maxTokens)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.framework.ai.chat;
|
||||
|
||||
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiiconflowApiConstants;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiliconFlowChatModel;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -25,11 +26,11 @@ public class SiliconFlowChatModelTests {
|
||||
|
||||
private final OpenAiChatModel openAiChatModel = OpenAiChatModel.builder()
|
||||
.openAiApi(OpenAiApi.builder()
|
||||
.baseUrl(SiliconFlowChatModel.BASE_URL)
|
||||
.baseUrl(SiiconflowApiConstants.DEFAULT_BASE_URL)
|
||||
.apiKey("sk-epsakfenqnyzoxhmbucsxlhkdqlcbnimslqoivkshalvdozz") // apiKey
|
||||
.build())
|
||||
.defaultOptions(OpenAiChatOptions.builder()
|
||||
.model(SiliconFlowChatModel.MODEL_DEFAULT) // 模型
|
||||
.model(SiiconflowApiConstants.MODEL_DEFAULT) // 模型
|
||||
// .model("deepseek-ai/DeepSeek-R1") // 模型(deepseek-ai/DeepSeek-R1)可用赠费
|
||||
// .model("Pro/deepseek-ai/DeepSeek-R1") // 模型(Pro/deepseek-ai/DeepSeek-R1)需要付费
|
||||
.temperature(0.7)
|
||||
|
Loading…
x
Reference in New Issue
Block a user