ChatGPT介绍
ChatGPT是一款基于自然语言处理技术的聊天机器人。它使用受控语料库,并使用最先进的深度学习技术来学习用户的输入,以便以最相似的方式回应。ChatGPT可以模拟真实的人类对话,并能够更贴近用户的需求,提供更有价值的服务。
SpringBoot介绍
Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。通过这种方式,Spring Boot致力于在蓬勃发展的快速应用开发领域(rapid application development)成为一个重要的先驱。
Spring Boot为Spring应用提供了一种快速的起步方式,可用来创建独立的,生产级的基于Spring的应用程序。它提供了一种更快捷的方式来创建Spring应用,并且不需要任何XML配置。Spring Boot提供了可选择的高级特性,如持久层技术和安全性,可以让你快速构建令人满意的web应用程序和服务。
构建SpringBoot项目
项目主要使用的maven依赖如下,通过Maven构建项目即可
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.yopai</groupId>
<artifactId>openapi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>openapi</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.21</version>
</dependency>
Post请求解析
RestTemplate是Spring框架的一个用于访问RESTful服务的客户端库,它提供了一组简单的、可扩展的方法来访问RESTful服务。它可以访问HTTP服务,并以字符串、Java对象或多种格式的数据(如JSON)进行序列化和反序列化。RestTemplate支持多种HTTP方法,如GET、POST、PUT、DELETE等,可以用来访问RESTful服务,并获取服务器返回的结果。
public static String sendPost(String data) {
RestTemplate client = new RestTemplate();
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Authorization","Bearer <YourAPI>");
httpHeaders.add("Content-Type", "application/json"); // 传递请求体时必须设置
// String requestJson = "{\n" +
// " \"model\": \"text-davinci-003\",\n" +
// " \"prompt\": \"你好\",\n" +
// " \"temperature\": 0, \n" +
// " \"max\_tokens\": 2048\n" +
// "}";
String requestJson = String.format(
"{\n" +
" \"model\": \"text-davinci-003\",\n" +
" \"prompt\": \"%s\",\n" +
" \"temperature\": 0, \n" +
" \"max\_tokens\": 2048\n" +
"}",data
);
HttpEntity<String> entity = new HttpEntity<String>(requestJson,httpHeaders);
ResponseEntity<String> response = client.exchange("https://api.openai.com/v1/completions", HttpMethod.POST, entity, String.class);
System.out.println(response.getBody());
JSONObject jsonObject = JSONObject.parseObject(response.getBody());
JSONArray choices = jsonObject.getJSONArray("choices");
String text = choices.getJSONObject(0).getString("text");
// Object o = jsonObject.get("\"choices\"");
return text;
}
接口控制类
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上物联网嵌入式知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、电子书籍、讲解视频,并且后续会持续更新