From 76bb59f1a2fcd9eb6e388feb4c68858921223b12 Mon Sep 17 00:00:00 2001 From: LnYo-Cly Date: Thu, 26 Sep 2024 17:29:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9C=89=E5=85=B3Pine?= =?UTF-8?q?cone=E5=90=91=E9=87=8F=E6=95=B0=E6=8D=AE=E5=BA=93=E7=9A=84?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- ai4j-spring-boot-stater/pom.xml | 2 +- .../lnyocly/ai4j/AiConfigAutoConfiguration.java | 2 +- .../lnyocly/ai4j/PineconeConfigProperties.java | 2 +- ai4j/pom.xml | 2 +- .../github/lnyocly/ai4j/config/PineconeConfig.java | 2 +- .../lnyocly/ai4j/vector/VertorDataEntity.java | 4 ++++ .../ai4j/vector/pinecone/PineconeQuery.java | 1 + .../ai4j/vector/service/PineconeService.java | 14 +++++++------- pom.xml | 2 +- 10 files changed, 20 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f324a6e..2d04a34 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,12 @@ + 轻松使用Tool Calls + 支持多个函数同时调用(智谱不支持) + 支持stream_options,流式输出直接获取统计token usage -+ 内置向量数据库支持: Pinecone ++ 支持RAG,内置向量数据库支持: Pinecone + 使用Tika读取文件 + Token统计`TikTokensUtil.java` ## 更新日志 ++ [2024-09-26] 修复有关Pinecone向量数据库的一些问题。发布0.6.3版本 + [2024-09-20] 增加对Ollama平台的支持,并修复一些bug。发布0.6.2版本 + [2024-09-19] 增加错误处理链,统一处理为openai错误类型; 修复部分情况下URL拼接问题,修复拦截器中response重复调用而导致的关闭问题。发布0.5.3版本 + [2024-09-12] 修复上个问题OpenAi参数导致错误的遗漏,发布0.5.2版本 diff --git a/ai4j-spring-boot-stater/pom.xml b/ai4j-spring-boot-stater/pom.xml index 6c084df..9f7199a 100644 --- a/ai4j-spring-boot-stater/pom.xml +++ b/ai4j-spring-boot-stater/pom.xml @@ -6,7 +6,7 @@ io.github.lnyo-cly ai4j-spring-boot-stater jar - 0.6.2 + 0.6.3 ai4j-spring-boot-stater 为aj4j所提供的spring-stater,便于接入spring项目。关于ai4j: 一款JavaSDK用于快速接入AI大模型应用,整合多平台大模型,如OpenAi、Ollama、智谱Zhipu(ChatGLM)、深度求索DeepSeek、月之暗面Moonshot(Kimi)、腾讯混元Hunyuan、零一万物(01)等等,提供统一的输入输出(对齐OpenAi)消除差异化,优化函数调用(Tool Call),优化RAG调用、支持向量数据库(Pinecone),并且支持JDK1.8,为用户提供快速整合AI的能力。 diff --git a/ai4j-spring-boot-stater/src/main/java/io/github/lnyocly/ai4j/AiConfigAutoConfiguration.java b/ai4j-spring-boot-stater/src/main/java/io/github/lnyocly/ai4j/AiConfigAutoConfiguration.java index 1fe6078..9576b0f 100644 --- a/ai4j-spring-boot-stater/src/main/java/io/github/lnyocly/ai4j/AiConfigAutoConfiguration.java +++ b/ai4j-spring-boot-stater/src/main/java/io/github/lnyocly/ai4j/AiConfigAutoConfiguration.java @@ -163,7 +163,7 @@ private void initZhipuConfig() { */ private void initPineconeConfig() { PineconeConfig pineconeConfig = new PineconeConfig(); - pineconeConfig.setUrl(pineconeConfigProperties.getUrl()); + pineconeConfig.setHost(pineconeConfigProperties.getHost()); pineconeConfig.setKey(pineconeConfigProperties.getKey()); pineconeConfig.setUpsert(pineconeConfigProperties.getUpsert()); pineconeConfig.setQuery(pineconeConfigProperties.getQuery()); diff --git a/ai4j-spring-boot-stater/src/main/java/io/github/lnyocly/ai4j/PineconeConfigProperties.java b/ai4j-spring-boot-stater/src/main/java/io/github/lnyocly/ai4j/PineconeConfigProperties.java index 2f2d4e0..99dce67 100644 --- a/ai4j-spring-boot-stater/src/main/java/io/github/lnyocly/ai4j/PineconeConfigProperties.java +++ b/ai4j-spring-boot-stater/src/main/java/io/github/lnyocly/ai4j/PineconeConfigProperties.java @@ -12,7 +12,7 @@ @Data @ConfigurationProperties(prefix = "ai.vector.pinecone") public class PineconeConfigProperties { - private String url = "https://xxx.svc.xxx.pinecone.io"; + private String host = "https://xxx.svc.xxx.pinecone.io"; private String key = ""; private String upsert = "/vectors/upsert"; diff --git a/ai4j/pom.xml b/ai4j/pom.xml index 23b87c2..5b9b4c9 100644 --- a/ai4j/pom.xml +++ b/ai4j/pom.xml @@ -7,7 +7,7 @@ io.github.lnyo-cly ai4j jar - 0.6.2 + 0.6.3 ai4j 一款JavaSDK用于快速接入AI大模型应用,整合多平台大模型,如OpenAi、Ollama、智谱Zhipu(ChatGLM)、深度求索DeepSeek、月之暗面Moonshot(Kimi)、腾讯混元Hunyuan、零一万物(01)等等,提供统一的输入输出(对齐OpenAi)消除差异化,优化函数调用(Tool Call),优化RAG调用、支持向量数据库(Pinecone),并且支持JDK1.8,为用户提供快速整合AI的能力。 diff --git a/ai4j/src/main/java/io/github/lnyocly/ai4j/config/PineconeConfig.java b/ai4j/src/main/java/io/github/lnyocly/ai4j/config/PineconeConfig.java index 656942c..96a24c3 100644 --- a/ai4j/src/main/java/io/github/lnyocly/ai4j/config/PineconeConfig.java +++ b/ai4j/src/main/java/io/github/lnyocly/ai4j/config/PineconeConfig.java @@ -14,7 +14,7 @@ @NoArgsConstructor @AllArgsConstructor public class PineconeConfig { - private String url = "https://xxx.svc.xxx.pinecone.io"; + private String host = "https://xxx.svc.xxx.pinecone.io"; private String key = ""; private String upsert = "/vectors/upsert"; diff --git a/ai4j/src/main/java/io/github/lnyocly/ai4j/vector/VertorDataEntity.java b/ai4j/src/main/java/io/github/lnyocly/ai4j/vector/VertorDataEntity.java index 1e4186c..8f6dbdf 100644 --- a/ai4j/src/main/java/io/github/lnyocly/ai4j/vector/VertorDataEntity.java +++ b/ai4j/src/main/java/io/github/lnyocly/ai4j/vector/VertorDataEntity.java @@ -1,6 +1,8 @@ package io.github.lnyocly.ai4j.vector; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import java.util.List; @@ -10,6 +12,8 @@ * @Date 2024/8/14 18:23 */ @Data +@AllArgsConstructor +@NoArgsConstructor public class VertorDataEntity { /** diff --git a/ai4j/src/main/java/io/github/lnyocly/ai4j/vector/pinecone/PineconeQuery.java b/ai4j/src/main/java/io/github/lnyocly/ai4j/vector/pinecone/PineconeQuery.java index 41fa11d..c470674 100644 --- a/ai4j/src/main/java/io/github/lnyocly/ai4j/vector/pinecone/PineconeQuery.java +++ b/ai4j/src/main/java/io/github/lnyocly/ai4j/vector/pinecone/PineconeQuery.java @@ -44,6 +44,7 @@ public class PineconeQuery { /** * 指示响应中是否包含元数据以及id */ + @Builder.Default private Boolean includeMetadata = true; /** diff --git a/ai4j/src/main/java/io/github/lnyocly/ai4j/vector/service/PineconeService.java b/ai4j/src/main/java/io/github/lnyocly/ai4j/vector/service/PineconeService.java index 59033e6..9a1efee 100644 --- a/ai4j/src/main/java/io/github/lnyocly/ai4j/vector/service/PineconeService.java +++ b/ai4j/src/main/java/io/github/lnyocly/ai4j/vector/service/PineconeService.java @@ -5,12 +5,12 @@ import io.github.lnyocly.ai4j.constant.Constants; import io.github.lnyocly.ai4j.exception.CommonException; import io.github.lnyocly.ai4j.service.Configuration; +import io.github.lnyocly.ai4j.utils.ValidateUtil; import io.github.lnyocly.ai4j.vector.VertorDataEntity; import io.github.lnyocly.ai4j.vector.pinecone.*; import lombok.extern.slf4j.Slf4j; import okhttp3.*; -import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; @@ -37,8 +37,8 @@ public PineconeService(Configuration configuration) { // 插入Pinecone向量库 public Integer insert(PineconeInsert pineconeInsertReq){ Request request = new Request.Builder() - .url(pineconeConfig.getUrl() + pineconeConfig.getUpsert()) - .post(RequestBody.create(JSON.toJSONString(pineconeInsertReq), MediaType.parse(Constants.APPLICATION_JSON))) + .url(ValidateUtil.concatUrl(pineconeConfig.getHost(), pineconeConfig.getUpsert())) + .post(RequestBody.create(MediaType.parse(Constants.APPLICATION_JSON), JSON.toJSONString(pineconeInsertReq))) .header("accept", Constants.APPLICATION_JSON) .header("content-type", Constants.APPLICATION_JSON) .header("Api-Key", pineconeConfig.getKey()) @@ -76,8 +76,8 @@ public Integer insert(VertorDataEntity vertorDataEntity, String namespace) { // 从Pinecone向量库中查询相似向量 public PineconeQueryResponse query(PineconeQuery pineconeQueryReq){ Request request = new Request.Builder() - .url(pineconeConfig.getUrl() + pineconeConfig.getQuery()) - .post(RequestBody.create(JSON.toJSONString(pineconeQueryReq), MediaType.parse(Constants.APPLICATION_JSON))) + .url(ValidateUtil.concatUrl(pineconeConfig.getHost(), pineconeConfig.getQuery())) + .post(RequestBody.create(MediaType.parse(Constants.APPLICATION_JSON), JSON.toJSONString(pineconeQueryReq))) .header("accept", Constants.APPLICATION_JSON) .header("content-type", Constants.APPLICATION_JSON) .header("Api-Key", pineconeConfig.getKey()) @@ -106,8 +106,8 @@ public String query(PineconeQuery pineconeQuery, String delimiter){ // 从Pinecone向量库中删除向量 public Boolean delete(PineconeDelete pineconeDeleteReq){ Request request = new Request.Builder() - .url(pineconeConfig.getUrl() + pineconeConfig.getDelete()) - .post(RequestBody.create(JSON.toJSONString(pineconeDeleteReq), MediaType.parse(Constants.APPLICATION_JSON))) + .url(ValidateUtil.concatUrl(pineconeConfig.getHost(), pineconeConfig.getDelete())) + .post(RequestBody.create(MediaType.parse(Constants.APPLICATION_JSON), JSON.toJSONString(pineconeDeleteReq))) .header("accept", Constants.APPLICATION_JSON) .header("content-type", Constants.APPLICATION_JSON) .header("Api-Key", pineconeConfig.getKey()) diff --git a/pom.xml b/pom.xml index 952df41..9687e34 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ io.github.lnyo-cly ai4j-sdk - 0.6.2 + 0.6.3 pom