spring-projects / spring-ai

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

azure-openai and openai #1242

Closed jaychoubaby closed 2 months ago

jaychoubaby commented 2 months ago

Please do a quick search on GitHub issues first, there might be already a duplicate issue for the one you are about to create. If the bug is trivial, just go ahead and create the issue. Otherwise, please take a few moments and fill in the following sections:

Bug description I found that azure-openai and openai don't seem to be usable at the same time.

Environment 1.0.0-SNAPSHOT

Steps to reproduce When I configured both azure-openai and openai at the same time.And when I only have one config, it will throw an error. spring: ai: azure: openai: chat: options: model: openai-4o-mini api-key: xxxxx endpoint: https://xxx.openai.azure.com/ openai: api-key: sk-xxxxxx base-url: xxxxxx chat: options: temperature: 0.7 model: gpt-4o

`@Configuration public class OpenAiConfig {

@Bean
ChatClient chatClient(ChatClient.Builder builder) {
    return builder.build();
}

}`

error: ` Description:

Parameter 1 of method chatClientBuilder in org.springframework.ai.autoconfigure.chat.client.ChatClientAutoConfiguration required a single bean, but 2 were found:

This may be due to missing parameter name information

Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

Ensure that your compiler is configured to use the '-parameters' flag. You may need to update both your build tool settings as well as your IDE. (See https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-6.x#parameter-name-retention) `

Expected behavior I hope I can use multiple AI models at the same time, and they won't directly affect each other.

Minimal Complete Reproducible example `@Slf4j @RestController @RequestMapping("/openai/api") public class OpenAi2Controller {

private final AzureOpenAiChatModel chatModel;

public OpenAi2Controller(AzureOpenAiChatModel chatModel) {
    this.chatModel = chatModel;
}

@GetMapping("/generate")
public Map generate(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
    return Map.of("generation", chatModel.call(message));
}

}`

jaychoubaby commented 2 months ago

I want to use ChatClient because only ChatClient has the .entity method. Why doesn't chatModel have this method?

However, if I configure multiple models in the configuration file at the same time, I won't be able to use ChatClient, and it will prompt me as follows:

Description:

Parameter 1 of method chatClientBuilder in org.springframework.ai.autoconfigure.chat.client.ChatClientAutoConfiguration required a single bean, but 2 were found:

This may be due to missing parameter name information

Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

Ensure that your compiler is configured to use the '-parameters' flag. You may need to update both your build tool settings as well as your IDE.