@RestController
public class EmbeddingController {
private final EmbeddingClient embeddingClient;
@Autowired
public EmbeddingController(EmbeddingClient embeddingClient) {
this.embeddingClient = embeddingClient;
}
@GetMapping("/ai/embedding")
public Map embed(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
EmbeddingResponse embeddingResponse = this.embeddingClient.embedForResponse(List.of(message));
return Map.of("embedding", embeddingResponse);
}
}
I didn't find EmbeddingClient through the maven dependency above.
I use QianFanEmbeddingModel.
@Autowired
private QianFanEmbeddingModel embeddingClient;
@Operation(summary = "embedding")
@GetMapping("/embedding")
public Map embed(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
EmbeddingResponse embeddingResponse = embeddingClient.embedForResponse(List.of(message));
return Map.of("embedding", embeddingResponse);
}
result:
java.lang.RuntimeException: Embedding failed: error code:3, message:Unsupported openapi method
at org.springframework.ai.qianfan.QianFanEmbeddingModel.lambda$call$1(QianFanEmbeddingModel.java:135) ~[spring-ai-qianfan-1.0.0-20240701.185347-23.jar:1.0.0-SNAPSHOT]
at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:335) ~[spring-retry-2.0.5.jar:na]
at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:211) ~[spring-retry-2.0.5.jar:na]
at org.springframework.ai.qianfan.QianFanEmbeddingModel.call(QianFanEmbeddingModel.java:114) ~[spring-ai-qianfan-1.0.0-20240701.185347-23.jar:1.0.0-SNAPSHOT]
at org.springframework.ai.embedding.EmbeddingModel.embedForResponse(EmbeddingModel.java:70) ~[spring-ai-core-1.0.0-20240701.185347-369.jar:1.0.0-SNAPSHOT]
doc:
I didn't find EmbeddingClient through the maven dependency above. I use QianFanEmbeddingModel.
result: