目录
Thinking
Study question
pox.xml
Maven
Gradle
Configure API Key
Use the AI Client
Question
Thinking
让数据变得更加贴近用户的想法
Study question
- null
pox.xml
添加依赖
Maven
<dependencies><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-openai-spring-boot-starter</artifactId><version>1.0.0</version></dependency>
</dependencies>
For Gradle:
Gradle
dependencies {implementation 'org.springframework.ai:spring-ai-openai-spring-boot-starter:1.0.0'
}
Configure API Key
Get openAi key on the article:Open Ai | 从零搭建属于你的Ai项目(中英结合)
to the application.yaml or application.properties
spring:ai:openai:api-key: YOUR_OPENAI_API_KEYmodel: gpt-3.5-turbo
spring.ai.openai.api-key=sk-YourOpenAIKeyHere
spring.ai.openai.model=gpt-3.5-turbo
Use the AI Client
Create a Spring component or service and autowire the AI client:
import org.springframework.ai.openai.OpenAiChatClient;
import org.springframework.stereotype.Service;@Service
public class AiService {private final OpenAiChatClient chatClient;public AiService(OpenAiChatClient chatClient) {this.chatClient = chatClient;}public String ask(String prompt) {return chatClient.call(prompt);}
}
Question
Could not autowire. No beans of 'OpenAiChatClient' type found.
- Thank you -