当前位置:   article > 正文

Spring AI的初步使用以及认识_group.springframework.ai使用

group.springframework.ai使用

首先附上Spring Ai的官方文档,以便后面去深入学习
官方文档:Prompts :: Spring AI Reference

SpringAI的认识

        Spring AI项目旨在简化包含人工智能功能的应用程序的开发,而不会产生不必要的复杂性,核心是提供抽象,作为开发AI应用程序的基础。 这些抽象有多个实现,可以用最少的代码更改轻松地进行组件交换。



Spring Ai 怎么对接Open AI

        准备:1.OpenAI 的Api Key

                   2.JDK 17(这个可用可不用)
会用到的依赖

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.apache.httpcomponents</groupId>
  4. <artifactId>httpclient</artifactId>
  5. <version>4.5.13</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>org.springframework.boot</groupId>
  9. <artifactId>spring-boot-starter-web</artifactId>
  10. </dependency>
  11. <dependency>
  12. <groupId>org.springframework.ai</groupId>
  13. <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
  14. </dependency>
  15. <dependency>
  16. <groupId>org.springframework.boot</groupId>
  17. <artifactId>spring-boot-devtools</artifactId>
  18. <scope>runtime</scope>
  19. <optional>true</optional>
  20. </dependency>
  21. <dependency>
  22. <groupId>org.projectlombok</groupId>
  23. <artifactId>lombok</artifactId>
  24. <optional>true</optional>
  25. </dependency>
  26. <dependency>
  27. <groupId>org.springframework.boot</groupId>
  28. <artifactId>spring-boot-starter-test</artifactId>
  29. <scope>test</scope>
  30. </dependency>
  31. </dependencies>
  32. <dependencyManagement>
  33. <dependencies>
  34. <dependency>
  35. <groupId>org.springframework.ai</groupId>
  36. <artifactId>spring-ai-bom</artifactId>
  37. <version>${spring-ai.version}</version>
  38. <type>pom</type>
  39. <scope>import</scope>
  40. </dependency>
  41. </dependencies>
  42. </dependencyManagement>
  43. <repositories>
  44. <!--快照版本的仓库-->
  45. <repository>
  46. <id>spring-snapshot</id>
  47. <name>Spring Snapshots</name>
  48. <url>https://repo.spring.io/snapshot</url>
  49. <releases>
  50. <enabled>false</enabled>
  51. </releases>
  52. </repository>
  53. </repositories>

编写Controller接口

  1. @RestController
  2. public class ChatGPTController{
  3. @Autowired
  4. private OpenAiChatClient openAiChatClient;
  5. @GetMapping("/chatGPT")
  6. public Object chatGPT(@RequestParam("message") String message){
  7. String result = openAiChatClient.call(message);
  8. return result;
  9. }
  10. }

Config配置文件格式

  1. server:
  2. port: 8088
  3. spring:
  4. application:
  5. name: Firstcht
  6. ai:
  7. openai:
  8. api-key: xxx
  9. base-url: openai的地址

 以上只是简单的使用,更多深入可以通过官方文档学习

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/785152
推荐阅读
相关标签
  

闽ICP备14008679号