前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ChatGPT教程 基于Springboot+Spring+MybatisPlus实现gpt3.5接口开发

ChatGPT教程 基于Springboot+Spring+MybatisPlus实现gpt3.5接口开发

作者头像
大数据小禅
发布2023-05-18 14:56:45
8000
发布2023-05-18 14:56:45
举报
文章被收录于专栏:YO大数据YO大数据

ChatGPT教程: 基于Springboot+Spring+MybatisPlus实现gpt3.5接口开发 文章介绍: 本文基于SpringBoot+Spring+MybatisPlus实现一个响应快速的gpt接口,可通过与前端整合开发对应的前端页面

最终效果演示
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
GPT接口介绍

GPT-3 的 API 接口可以用于许多应用,例如基于自然语言处理的智能问答、机器翻译、文本摘要、文本自动生成、语言模型微调等等。根据 OpenAI 官网的介绍,GPT-3 API 提供了多种可定制的 API 接口,其中包括:

文本生成(Text Completion)API:输入前缀文本,自动生成补全文本。

文本生成(Text Generation)API:输入主题或关键词,自动生成相关的文章或段落。

问答(Question Answering)API:输入问题,自动生成回答。

自然语言交互(Conversational AI)API:模拟人类对话,回答用户的自然语言问题。

文本摘要(Text Summarization)API:输入长篇文章,自动生成简洁精炼的摘要。

机器翻译(Translation)API:将一种语言的文本翻译成另外一种语言。

语言模型微调(Language Model Fine-tuning)API:将预先训练好的语言模型进一步优化以适应特定领域应用,如情感分析、信息提取等。

代码演示

相关依赖

代码语言:javascript
复制
<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>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents.client5/httpclient5 -->
        <dependency>
            <groupId>org.apache.httpcomponents.client5</groupId>
            <artifactId>httpclient5</artifactId>
            <version>5.2.1</version>
        </dependency>
实体类与实现类封装
代码语言:javascript
复制
@RestController
@RequestMapping("/api")
public class ChatController {

    @Autowired
    private HttpGptService httpGpt;
    @PostMapping("robot")
    public JsonData getMessage(@RequestBody GptInfo gptInfo) throws IOException {
        String msg = httpGpt.getMsg(gptInfo.getInfo());
        System.out.println(msg);
        System.out.println(gptInfo.getInfo());
        return JsonData.buildSuccess(msg);
    }
}

@Service
public class GetMasImpl implements HttpGptService {
    @Override
    public String getMsg(String info) throws IOException {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        //
        String apiKey = "your_key";
        CustomChatGpt customChatGpt = new CustomChatGpt(apiKey);
        customChatGpt.setResponseTimeout(80000);
        long start = System.currentTimeMillis();
        String answer = customChatGpt.getAnswer(httpClient, info);
        long end = System.currentTimeMillis();
        System.out.println("该回答花费时间为:" + (end - start) / 1000.0 + "秒");
        System.out.println("该回答花费时间为:" + (end - start) / 1000.0 + "秒");
        httpClient.close();
        return answer;
    }
}
接口相关说明
  • 接口输入: 输入JSON字段,INFO
  • 接口返回: 返回如下三个字段
  • 注意:如果需要部署上线则需要使用代理,或者魔法方法
在这里插入图片描述
在这里插入图片描述
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023/05/17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 最终效果演示
  • GPT接口介绍
  • 代码演示
    • 实体类与实现类封装
    • 接口相关说明
    相关产品与服务
    机器翻译
    机器翻译(Tencent Machine Translation,TMT)结合了神经机器翻译和统计机器翻译的优点,从大规模双语语料库自动学习翻译知识,实现从源语言文本到目标语言文本的自动翻译,目前可支持十余种语言的互译。
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档