【功能新增】AI:新增 ZhiPuAiEmbeddingModel 向量模型
This commit is contained in:
parent
d7e801c438
commit
3a3607e1cb
|
@ -36,7 +36,6 @@ public class AiKnowledgeController {
|
|||
@Operation(summary = "获取知识库分页")
|
||||
@PreAuthorize("@ss.hasPermission('ai:knowledge:query')")
|
||||
public CommonResult<PageResult<AiKnowledgeRespVO>> getKnowledgePage(@Valid AiKnowledgePageReqVO pageReqVO) {
|
||||
|
||||
PageResult<AiKnowledgeDO> pageResult = knowledgeService.getKnowledgePage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, AiKnowledgeRespVO.class));
|
||||
}
|
||||
|
|
|
@ -163,9 +163,9 @@ public class AiModelServiceImpl implements AiModelService {
|
|||
|
||||
// 创建或获取 VectorStore 对象
|
||||
return modelFactory.getOrCreateVectorStore(SimpleVectorStore.class, embeddingModel, metadataFields);
|
||||
// return modelFactory.getOrCreateVectorStore(QdrantVectorStore.class, embeddingModel, metadataFields);
|
||||
// return modelFactory.getOrCreateVectorStore(RedisVectorStore.class, embeddingModel, metadataFields);
|
||||
// return modelFactory.getOrCreateVectorStore(MilvusVectorStore.class, embeddingModel, metadataFields);
|
||||
// return modelFactory.getOrCreateVectorStore(QdrantVectorStore.class, embeddingModel, metadataFields);
|
||||
// return modelFactory.getOrCreateVectorStore(RedisVectorStore.class, embeddingModel, metadataFields);
|
||||
// return modelFactory.getOrCreateVectorStore(MilvusVectorStore.class, embeddingModel, metadataFields);
|
||||
}
|
||||
|
||||
}
|
|
@ -77,6 +77,7 @@ import org.springframework.ai.vectorstore.observation.VectorStoreObservationConv
|
|||
import org.springframework.ai.vectorstore.qdrant.QdrantVectorStore;
|
||||
import org.springframework.ai.vectorstore.redis.RedisVectorStore;
|
||||
import org.springframework.ai.zhipuai.ZhiPuAiChatModel;
|
||||
import org.springframework.ai.zhipuai.ZhiPuAiEmbeddingModel;
|
||||
import org.springframework.ai.zhipuai.ZhiPuAiImageModel;
|
||||
import org.springframework.ai.zhipuai.api.ZhiPuAiApi;
|
||||
import org.springframework.ai.zhipuai.api.ZhiPuAiImageApi;
|
||||
|
@ -231,7 +232,9 @@ public class AiModelFactoryImpl implements AiModelFactory {
|
|||
return buildTongYiEmbeddingModel(apiKey, model);
|
||||
case OLLAMA:
|
||||
return buildOllamaEmbeddingModel(url, model);
|
||||
// TODO @芋艿:各个平台的向量化能力;
|
||||
// TODO @芋艿:yiyan
|
||||
case ZHI_PU:
|
||||
return buildZhiPuEmbeddingModel(apiKey, url, model);
|
||||
default:
|
||||
throw new IllegalArgumentException(StrUtil.format("未知平台({})", platform));
|
||||
}
|
||||
|
@ -240,8 +243,8 @@ public class AiModelFactoryImpl implements AiModelFactory {
|
|||
|
||||
@Override
|
||||
public VectorStore getOrCreateVectorStore(Class<? extends VectorStore> type,
|
||||
EmbeddingModel embeddingModel,
|
||||
Map<String, Class<?>> metadataFields) {
|
||||
EmbeddingModel embeddingModel,
|
||||
Map<String, Class<?>> metadataFields) {
|
||||
String cacheKey = buildClientCacheKey(VectorStore.class, embeddingModel, type);
|
||||
return Singleton.get(cacheKey, (Func0<VectorStore>) () -> {
|
||||
if (type == SimpleVectorStore.class) {
|
||||
|
@ -425,17 +428,24 @@ public class AiModelFactoryImpl implements AiModelFactory {
|
|||
|
||||
// ========== 各种创建 EmbeddingModel 的方法 ==========
|
||||
|
||||
// TODO @芋艿:需要测试下
|
||||
/**
|
||||
* 可参考 {@link DashScopeAutoConfiguration} 的 dashscopeEmbeddingModel 方法
|
||||
*/
|
||||
private DashScopeEmbeddingModel buildTongYiEmbeddingModel(String apiKey, String model) {
|
||||
DashScopeApi dashScopeApi = new DashScopeApi(apiKey);
|
||||
DashScopeEmbeddingOptions dashScopeEmbeddingOptions = DashScopeEmbeddingOptions.builder().withModel(model)
|
||||
.build();
|
||||
DashScopeEmbeddingOptions dashScopeEmbeddingOptions = DashScopeEmbeddingOptions.builder().withModel(model).build();
|
||||
return new DashScopeEmbeddingModel(dashScopeApi, MetadataMode.EMBED, dashScopeEmbeddingOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 可参考 {@link ZhiPuAiAutoConfiguration} 的 zhiPuAiEmbeddingModel 方法
|
||||
*/
|
||||
private ZhiPuAiEmbeddingModel buildZhiPuEmbeddingModel(String apiKey, String url, String model) {
|
||||
url = StrUtil.blankToDefault(url, ZhiPuAiConnectionProperties.DEFAULT_BASE_URL);
|
||||
ZhiPuAiApi zhiPuAiApi = new ZhiPuAiApi(url, apiKey);
|
||||
return new ZhiPuAiEmbeddingModel(zhiPuAiApi);
|
||||
}
|
||||
|
||||
private OllamaEmbeddingModel buildOllamaEmbeddingModel(String url, String model) {
|
||||
OllamaApi ollamaApi = new OllamaApi(url);
|
||||
OllamaOptions ollamaOptions = OllamaOptions.builder().model(model).build();
|
||||
|
|
Loading…
Reference in New Issue