|
|
|
@ -6,7 +6,6 @@ import lombok.Data;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.ai.document.Document;
|
|
|
|
|
import org.springframework.ai.embedding.*;
|
|
|
|
|
import org.springframework.core.SpringProperties;
|
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
@ -17,6 +16,11 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class VectorEmbeddingClient extends AbstractEmbeddingClient {
|
|
|
|
|
|
|
|
|
|
private final String embeddingUrl;
|
|
|
|
|
|
|
|
|
|
public VectorEmbeddingClient(String embeddingUrl) {
|
|
|
|
|
this.embeddingUrl = embeddingUrl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<Double> embed(Document document) {
|
|
|
|
@ -32,7 +36,7 @@ public class VectorEmbeddingClient extends AbstractEmbeddingClient {
|
|
|
|
|
public EmbeddingResponse call(EmbeddingRequest request) {
|
|
|
|
|
Assert.notEmpty(request.getInstructions(), "At least one text is required!");
|
|
|
|
|
List<List<Double>> embeddingList = new ArrayList<>();
|
|
|
|
|
String embeddingUrl = SpringProperties.getProperty("embeddingUrl");
|
|
|
|
|
|
|
|
|
|
for (String inputContent : request.getInstructions()) {
|
|
|
|
|
// 这里需要吧inputContent转化为向量数据
|
|
|
|
|
String post = HttpUtil.post(embeddingUrl, JSONUtil.toJsonStr(Map.of("text", inputContent)));
|
|
|
|
|