SpringAI集成DeepSeek

1、利用spring-ai-openai集成DeepSeek

1.1、在 DeepSeek 开放平台创建API KEY

SpringAI集成DeepSeek_第1张图片

1.2、创建SpringBoot工程,引入依赖


    4.0.0

    
        org.springframework.boot
        spring-boot-starter-parent
        3.3.8
         
    

    org.example
    springai-deepseek
    1.0-SNAPSHOT

    
        17
        17
        1.0.0-M5
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
        
            org.springframework.ai
            spring-ai-openai-spring-boot-starter
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    
    
        
            
                org.springframework.ai
                spring-ai-bom
                ${spring-ai.version}
                pom
                import
            
        
    

1.3、创建配置文件

application.properties

server.port=8899
spring.application.name=spring-ai-deepseek-demo

spring.ai.openai.api-key=sk-136298bee728426280df86bd9****
spring.ai.openai.base-url=https://api.deepseek.com
spring.ai.openai.chat.options.model=deepseek-chat
spring.ai.openai.chat.options.temperature=0.7

#temperature参数用于控制生成文本的多样性。具体来说:

‌#值越高‌,生成的文本越多样化,但也可能包含更多的随机性和不可预测的内容。
‌#值越低‌,生成的文本越接近于确定性的结果,即生成的文本会更加一致和可预测。
1.4、创建启动类
@SpringBootApplication
public class SpringAiDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringAiDemoApplication.class, args);
    }

}
1.5、创建Controller
@RestController
public class ChatDeepSeekController {

    @Autowired
    private OpenAiChatModel chatModel;

    @GetMapping("/ai/generate")
    public String generate(@RequestParam(value = "message", defaultValue = "hello")
                           String message) {
        String response = this.chatModel.call(message);
        System.out.println("response : "+response);
        return response;
    }
}

你可能感兴趣的:(java,人工智能,spring,boot)