spring-projects / spring-ai

An Application Framework for AI Engineering
https://docs.spring.io/spring-ai/reference/1.0-SNAPSHOT/index.html
Apache License 2.0
2.51k stars 602 forks source link

【Spring AI】 pgvector + qianfan Embedding = Embedding failed: error code:3, message:Unsupported openapi method #994

Open MaRuifu opened 4 days ago

MaRuifu commented 4 days ago
<spring-ai.version>1.0.0-SNAPSHOT</spring-ai.version>

<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-qianfan-spring-boot-starter</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-pgvector-store-spring-boot-starter</artifactId>
</dependency>

doc:

@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]
mxsl-gr commented 4 days ago

hi, please make sure the corresponding model is activated by visiting the console page: https://console.bce.baidu.com/qianfan/ais/console/onlineService