| | |
| | | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiModelDO; |
| | | import cn.iocoder.yudao.module.ai.dal.mysql.model.AiModelMapper; |
| | | import cn.iocoder.yudao.module.ai.enums.model.AiPlatformEnum; |
| | | import cn.iocoder.yudao.module.ai.framework.ai.config.YudaoAiProperties; |
| | | import cn.iocoder.yudao.module.ai.framework.ai.core.model.AiModelFactory; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.ai.chat.model.ChatModel; |
| | |
| | | private AiModelMapper modelMapper; |
| | | @Resource |
| | | private AiModelFactory modelFactory; |
| | | @Resource |
| | | private YudaoAiProperties aiProperties; |
| | | |
| | | @Override |
| | | public Long createModel(AiModelSaveReqVO createReqVO) { |
| | |
| | | AiModelDO model = validateModel(id); |
| | | AiApiKeyDO apiKey = apiKeyService.validateApiKey(model.getKeyId()); |
| | | AiPlatformEnum platform = AiPlatformEnum.validatePlatform(apiKey.getPlatform()); |
| | | return modelFactory.getOrCreateChatModel(platform, apiKey.getApiKey(), apiKey.getUrl(), model.getModel()); |
| | | // temperature / maxTokens 是 AI 模型表上一直存在、却从没人读过的两列: |
| | | // 不读 temperature,库里配的值对调用方是假的;不读 maxTokens,长输出会被静默截断 |
| | | return modelFactory.getOrCreateChatModel(platform, apiKey.getApiKey(), apiKey.getUrl(), model.getModel(), |
| | | model.getTemperature(), model.getMaxTokens(), aiProperties.getTimeout()); |
| | | } |
| | | |
| | | @Override |