<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ChatGPT归档 - Liao&#039;s blog</title>
	<atom:link href="https://www.laobaiblog.top/tag/chatgpt/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.laobaiblog.top/tag/chatgpt/</link>
	<description>路漫漫其修远兮，吾将上下而求索</description>
	<lastBuildDate>Mon, 15 Jan 2024 07:50:02 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.laobaiblog.top/wp-content/uploads/2022/01/cropped-tyuu-32x32.png</url>
	<title>ChatGPT归档 - Liao&#039;s blog</title>
	<link>https://www.laobaiblog.top/tag/chatgpt/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>使用Nginx转发代理ChatGpt接口，Java调用实现多轮对话</title>
		<link>https://www.laobaiblog.top/2024/01/15/%e4%bd%bf%e7%94%a8nginx%e8%bd%ac%e5%8f%91%e4%bb%a3%e7%90%86chatgpt%e6%8e%a5%e5%8f%a3%ef%bc%8cjava%e8%b0%83%e7%94%a8%e5%ae%9e%e7%8e%b0%e5%a4%9a%e8%bd%ae%e5%af%b9%e8%af%9d/</link>
		
		<dc:creator><![CDATA[大白]]></dc:creator>
		<pubDate>Mon, 15 Jan 2024 07:50:02 +0000</pubDate>
				<category><![CDATA[Docker]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[分享]]></category>
		<category><![CDATA[ChatGPT]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[域名]]></category>
		<guid isPermaLink="false">https://www.laobaiblog.top/?p=462</guid>

					<description><![CDATA[<p>一、理论概述 ChatGpt接口目前只能在国外互联网环境中使用，国内想要使用相关服务的话可以寻求代理 &#8230;</p>
<p><a href="https://www.laobaiblog.top/2024/01/15/%e4%bd%bf%e7%94%a8nginx%e8%bd%ac%e5%8f%91%e4%bb%a3%e7%90%86chatgpt%e6%8e%a5%e5%8f%a3%ef%bc%8cjava%e8%b0%83%e7%94%a8%e5%ae%9e%e7%8e%b0%e5%a4%9a%e8%bd%ae%e5%af%b9%e8%af%9d/">使用Nginx转发代理ChatGpt接口，Java调用实现多轮对话</a>最先出现在<a href="https://www.laobaiblog.top">Liao&#039;s blog</a>。</p>
]]></description>
										<content:encoded><![CDATA[<h3>一、理论概述</h3>
<p>ChatGpt接口目前只能在国外互联网环境中使用，国内想要使用相关服务的话可以寻求代理，在这里使用的是一台国外服务器安装Nginx服务进行相关代理。</p>
<h3>二、环境要求</h3>
<ul>
<li>一台拥有公网IP的国外服务器</li>
<li>一个域名及免费ssl证书（可在腾讯云免费申请ssl证书）</li>
<li>一个ChatGpt账号及相关的<a class="wp-editor-md-post-content-link" href="https://platform.openai.com/api-keys">APIkey</a></li>
</ul>
<p>以上就是所有需要用到的环境，<strong><em>请注意，如要使用接口还需要<a class="wp-editor-md-post-content-link" href="https://platform.openai.com/account/billing/overview">充值API</a>额度</em></strong>。除此之外还需要将你的域名解析到公网IP上。完成准备工作后进行以下操作。</p>
<h3>三、Nginx转发</h3>
<ol>
<li>在服务器中安装nginx，这里使用的是docker服务，根据以往博文中可自行安装Docker服务。</li>
</ol>
<pre><code class="language-shell line-numbers">#服务器中新建一个nginx目录，下级目录新建conf.d、logs、ssl三个目录
mkdir -p nginx/conf.d
mkdir -p nginx/logs
mkdir -p nginx/ssl

#在nginx目录中新建start.sh脚本
vim start.sh

docker stop nginx
docker rm nginx
docker run  -p 80:80  -p 443:443 --name nginx --net=host  --restart=always  --privileged=true \
    -v `pwd`/conf.d/:/etc/nginx/conf.d \
    -v `pwd`/logs/:/var/log/nginx  \
    -v `pwd`/ssl/:/var/ssl \
    -e TZ="Asia/Shanghai" \
    nginx:latest

#输入 :wq 保存后授权并执行即可
chmod a+x start.sh
./start.sh
</code></pre>
<ol start="2">
<li>将域名ssl证书放置在ssl目录下后，编辑nginx转发代理，执行<code>start.sh</code>脚本重启nginx服务。</li>
</ol>
<pre><code class="language-shell line-numbers">vim conf.d/gpt.conf

#填入域名信息
server {
        listen       443 ssl;
        server_name  域名;
        ssl_certificate /var/ssl/域名.crt;     #配置证书位置
        ssl_certificate_key /var/ssl/域名.key; #配置秘钥位置】

        ssl_session_timeout 5m;
        ssl_protocols SSLv2 SSLv3 TLSv1.2;
        ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
        ssl_prefer_server_ciphers on;

        underscores_in_headers on;
        charset utf-8;

        location /v1/ {
             proxy_ssl_server_name on;
             proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
             proxy_pass https://api.openai.com;
        }
}
</code></pre>
<p>以上便完成了针对chatgpt接口地址 <strong><em><code>api.openai.com</code></em></strong> 的转发工作，转发后的地址既是你的域名。</p>
<h3>四、Java实例调用实现多轮对话</h3>
<ol>
<li>新建Maven项目ChatGPTClient，在<code>pom.xml</code>中添加后续用到的依赖，重构后拉取。</li>
</ol>
<pre data-language=XML><code class="language-markup line-numbers">&lt;dependency&gt;
            &lt;groupId&gt;com.squareup.okhttp3&lt;/groupId&gt;
            &lt;artifactId&gt;okhttp&lt;/artifactId&gt;
            &lt;version&gt;4.9.3&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
            &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
            &lt;artifactId&gt;gson&lt;/artifactId&gt;
            &lt;version&gt;2.8.9&lt;/version&gt; &lt;!-- 使用最新的可用版本 --&gt;
&lt;/dependency&gt;
</code></pre>
<ol start="2">
<li>java代码</li>
</ol>
<pre><code class="language-shell line-numbers">import okhttp3.*;
import com.google.gson.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class ChatGPTClient {
    private final String apiKey;
    private final OkHttpClient client;
    private final List&lt;Message&gt; messages;
    private final Gson gson;
    private int tokenCount = 0;
    private int inputTokenCount = 0;
    private int outputTokenCount = 0;

    public ChatGPTClient(String apiKey) {
        this.apiKey = apiKey;
        this.client = new OkHttpClient();
        this.messages = new ArrayList&lt;&gt;();
        this.gson = new Gson();
    }

    public String sendMessage(String message) throws IOException {
        updateTokenCount(message, true);

        messages.add(new Message("system", "user", message));
//model模型选择可以有gpt-3.5-turbo、gpt-4、gpt-4-turbo价格以此类推
        RequestBody body = RequestBody.create(
                MediaType.get("application/json; charset=utf-8"),
                "{\"model\": \"gpt-3.5-turbo\", \"messages\": " + gson.toJson(messages) + "}"
        );

        Request request = new Request.Builder()
                .url("https://你的域名地址/v1/chat/completions")
                .addHeader("Authorization", "Bearer " + this.apiKey)
                .addHeader("Content-Type", "application/json")
                .post(body)
                .build();

        try (Response response = client.newCall(request).execute()) {
            JsonObject respJson = JsonParser.parseString(response.body().string()).getAsJsonObject();
            JsonArray choices = respJson.getAsJsonArray("choices");
            if (choices != null &amp;&amp; choices.size() &gt; 0) {
                JsonObject firstChoice = choices.get(0).getAsJsonObject();
                String aiResponse = firstChoice.getAsJsonObject("message").get("content").getAsString();

                updateTokenCount(aiResponse, false);

                messages.add(new Message("system", "assistant", aiResponse));

                System.out.println("输入的 Token 数: " + inputTokenCount);
                System.out.println("输出的 Token 数: " + outputTokenCount);
                System.out.println("总使用的 Token 数: " + tokenCount);

                return aiResponse;
            }
        }
        return "无法获取响应。";
    }

    private void updateTokenCount(String text, boolean isInput) {
        int count = 0;
        for (char c : text.toCharArray()) {
            count += (String.valueOf(c).matches("[\\u0000-\\u00ff]") ? 1 : 4);
        }
        int tokens = (int) Math.ceil(count / 4.0);
        tokenCount += tokens;
        if (isInput) {
            inputTokenCount += tokens;
        } else {
            outputTokenCount += tokens;
        }
    }

    private static class Message {
        String role;
        String content;

        public Message(String type, String role, String content) {
            this.role = role;
            this.content = content;
        }
    }

    public static void main(String[] args) throws IOException {
        ChatGPTClient client = new ChatGPTClient("YOUR-API-KEY");

        Scanner scanner = new Scanner(System.in, "UTF-8");
        String input;
        while (true) {
            System.out.print("输入消息（输入 'bye' 结束对话）: ");
            input = scanner.nextLine();
            if ("bye".equalsIgnoreCase(input)) {
                break;
            }
            String response = client.sendMessage(input);
            System.out.println("ChatGPT 回应: " + response);
        }
    }
}

</code></pre>
<p>在以上代码中，增加了每次对话后所使用的token值，以便查询核对接口使用费。可在官网查询相关定价。</p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2024/01/wp_editor_md_7ca6ffab890759733ec128bda9db6a20.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2024/01/wp_editor_md_7ca6ffab890759733ec128bda9db6a20.jpg" alt="" /></a></p>
<h3>五、运行结果</h3>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2024/01/wp_editor_md_86a520f2c97f583072037ca931be6455.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2024/01/wp_editor_md_86a520f2c97f583072037ca931be6455.jpg" alt="" /></a></p>
<p><a href="https://www.laobaiblog.top/2024/01/15/%e4%bd%bf%e7%94%a8nginx%e8%bd%ac%e5%8f%91%e4%bb%a3%e7%90%86chatgpt%e6%8e%a5%e5%8f%a3%ef%bc%8cjava%e8%b0%83%e7%94%a8%e5%ae%9e%e7%8e%b0%e5%a4%9a%e8%bd%ae%e5%af%b9%e8%af%9d/">使用Nginx转发代理ChatGpt接口，Java调用实现多轮对话</a>最先出现在<a href="https://www.laobaiblog.top">Liao&#039;s blog</a>。</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>ChatGPT Java实例接入</title>
		<link>https://www.laobaiblog.top/2023/02/21/chatgpt%e6%8e%a5%e5%85%a5%e5%ae%9e%e4%be%8b/</link>
		
		<dc:creator><![CDATA[大白]]></dc:creator>
		<pubDate>Tue, 21 Feb 2023 06:51:06 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[分享]]></category>
		<category><![CDATA[ChatGPT]]></category>
		<category><![CDATA[openAi]]></category>
		<category><![CDATA[人工智能]]></category>
		<guid isPermaLink="false">https://www.laobaiblog.top/?p=385</guid>

					<description><![CDATA[<p>前言：ChatGPT因为国内的各种原因，官网目前已经提高了原生IP的访问门槛。 现状 应该有很多人和 &#8230;</p>
<p><a href="https://www.laobaiblog.top/2023/02/21/chatgpt%e6%8e%a5%e5%85%a5%e5%ae%9e%e4%be%8b/">ChatGPT Java实例接入</a>最先出现在<a href="https://www.laobaiblog.top">Liao&#039;s blog</a>。</p>
]]></description>
										<content:encoded><![CDATA[<p><em>前言：ChatGPT因为国内的各种原因，官网目前已经提高了原生IP的访问门槛。</em></p>
<h2>现状</h2>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_05555a3648930d6f79441546e9b1d2d4.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_05555a3648930d6f79441546e9b1d2d4.jpg" alt="" /></a></p>
<p>应该有很多人和我一样，之前能在<a class="wp-editor-md-post-content-link" href="https://chat.openai.com/chat">官网</a>直接使用<a class="wp-editor-md-post-content-link" href="https://chat.openai.com/chat">ChatGPT</a>，现在因为节点IP不够纯正而被限制访问，不过好在<strong>官网提供的API接口是正常使用的</strong>，所以曲线救国思路就是：</p>
<ul>
<li>申请官网API keys</p>
</li>
<li>
<p>查看官网实例调用ChatGPT</p>
</li>
<li>
<p>API调用额度查看</p>
</li>
</ul>
<h4>申请API keys</h4>
<p>前文：<a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/2022/12/08/chatgpt%e6%b3%a8%e5%86%8c%e4%bd%bf%e7%94%a8%e7%b3%bb%e5%88%97%e4%b8%80/">ChatGPT注册使用系列一</a>文中，注册好账号后，在<a class="wp-editor-md-post-content-link" href="https://platform.openai.com/account/api-keys">个人页</a>创建自己的<strong>API keys</strong></p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_8fced2b62d0e7686a5329f9aac7e7c0e.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_8fced2b62d0e7686a5329f9aac7e7c0e.jpg" alt="" /></a></p>
<h4>官网支持语言一览</h4>
<p><a class="wp-editor-md-post-content-link" href="https://platform.openai.com/docs/libraries/community-libraries">官网</a>中可以看到ChatGPT已经支持很多语言接入了。</p>
<p><a class="wp-editor-md-post-content-link" href="https://github.com/TheoKanning/openai-java">openai-java</a></p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_d57dfa1fcca95a80803e95b3ef67dc47.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_d57dfa1fcca95a80803e95b3ef67dc47.jpg" alt="" /></a></p>
<h4>调用费用</h4>
<p>程序接入到 ChatGPT，<strong>调用接口要收费的</strong>。<br />
不过<strong>新注册的账号，前3个月免费使用，总消费额度不超过18美元</strong>。<br />
我的账号是到2023年4月1日，这期间只要调用费用不超过18美元相当于是免费使用</p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_5ebb08c846a4ad8dee1ca49bcaadae83.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_5ebb08c846a4ad8dee1ca49bcaadae83.jpg" alt="" /></a></p>
<h2>官网实例接入</h2>
<p>以上准备工作及注意事项做好之后，我们就可以开始接入ChatGPT了。<br />
下面是官网给出的调用例子（只是其中一个使用场景）</p>
<pre><code class="language-shell line-numbers">curl https://api.openai.com/v1/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{"model": "text-davinci-003", "prompt": "中国的首都是什么地方？", "temperature": 0, "max_tokens": 7}'
</code></pre>
<p><strong>重要参数解释：</strong></p>
<ul>
<li><strong>model：接入模型</strong><br />
<a class="wp-editor-md-post-content-link" href="https://platform.openai.com/docs/models/gpt-3">OpenAI API</a>提供了一系列具有不同功能和价格点的模型,其中，GPT-3是最为智能的模型，也是收费最高的，后面代码中我们将使用其中的text-davinci-003。<br />
<a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_6853edb2ae5e4b1cbd79af59a0cb414a.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_6853edb2ae5e4b1cbd79af59a0cb414a.jpg" alt="" /></a><br />
<a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_b937e808a676673c239b6f648d95f652.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_b937e808a676673c239b6f648d95f652.jpg" alt="" /></a></li>
</ul>
<h4>使用场景</h4>
<p>官网给我们列出来很多使用<strong><a class="wp-editor-md-post-content-link" href="https://platform.openai.com/examples">场景</a></strong></p>
<ul>
<li>Answers（问答场景）<br />
<a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_fbc63daab97421d75e28d4c28f1b5da2.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_fbc63daab97421d75e28d4c28f1b5da2.jpg" alt="" /></a></p>
</li>
<li>
<p>Classification（分类场景）<br />
<a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_b07d4627ab63e58198215d23daaae228.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_b07d4627ab63e58198215d23daaae228.jpg" alt="" /></a></p>
</li>
<li>
<p>Code(代码场景)<br />
<a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_8488f7a00c66e29339a3010ebb8d1d04.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_8488f7a00c66e29339a3010ebb8d1d04.jpg" alt="" /></a></p>
</li>
<li>
<p>Conversation（谈话场景）<br />
<a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_cd7e8e6dc56b453179e0aadba442b109.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_cd7e8e6dc56b453179e0aadba442b109.jpg" alt="" /></a></p>
</li>
<li>
<p>Translation（翻译场景）<br />
<a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_b5ebdd7240f8fad098e99708d6230ded.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_b5ebdd7240f8fad098e99708d6230ded.jpg" alt="" /></a></p>
</li>
<li>
<p>Transformation（转换场景）<br />
<a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_6f99e394d7cfe6f39bdcea29263e58c2.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_6f99e394d7cfe6f39bdcea29263e58c2.jpg" alt="" /></a></p>
</li>
</ul>
<h3>代码实现</h3>
<p>官网有大约49种场景。代码中，我们以<strong>Answers（问答场景）</strong> 为例，只要<strong>点场景图标</strong>，就可以<strong>跳到该场景查看对应参数调用实例</strong>了。具体如下：</p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_fa0e4302233c0949146cd7560d873a89.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_fa0e4302233c0949146cd7560d873a89.jpg" alt="" /></a></p>
<h4>postman调用测试</h4>
<p><em>可以在github中下载对应汉化版本的 <a class="wp-editor-md-post-content-link" href="https://github.com/hlmd/Postman-cn">postman</a>，参考<a class="wp-editor-md-post-content-link" href="https://www.quanxiaoha.com/article/postman-set-cn.html">相应教程</a></em></p>
<ul>
<li><strong>选择请求方式，填入接口地址，添加自己账号创建的Token</strong></li>
</ul>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_ad7183ad7ef3c68d755eeb4235eddb60.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_ad7183ad7ef3c68d755eeb4235eddb60.jpg" alt="" /></a></p>
<ul>
<li><strong>请求头中添加Content-Type类型为json</strong></li>
</ul>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_7ec77d39456140b33981c109d868e937.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_7ec77d39456140b33981c109d868e937.jpg" alt="" /></a></p>
<ul>
<li><strong>拼接json格式的入参</strong></li>
</ul>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_8b99f937d1cff8abb84c8d82f8f1609e.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_8b99f937d1cff8abb84c8d82f8f1609e.jpg" alt="" /></a></p>
<ul>
<li><strong>调用成功</strong></li>
</ul>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_cdb357d4266204eccc28d6db3927745b.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_cdb357d4266204eccc28d6db3927745b.jpg" alt="" /></a></p>
<h4>Java代码调用</h4>
<ol>
<li>IDEA新建一个Maven项目：ChatGPT</li>
<li>POM添加Hutool依赖，使用Hutool工具发送http post请求，json对象封装等等。</li>
</ol>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_02bb4f54a9babded6dda5f3ce7fbb502.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_02bb4f54a9babded6dda5f3ce7fbb502.jpg" alt="" /></a><br />
3. <strong>Java代码</strong></p>
<pre><code class="language-java line-numbers">import cn.hutool.http.*;
import cn.hutool.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class ChatGptDemo {
    public static void main(String[] args) {
        Map&lt;String,String&gt; headers = new HashMap&lt;String,String&gt;();
        headers.put("Content-Type","application/json;charset=UTF-8");

        JSONObject json = new JSONObject();
        //选择模型
        json.set("model","text-davinci-003");
        //添加我们需要输入的内容
        json.set("prompt","中国的首都在哪里？");
        json.set("temperature",0.9);
        json.set("max_tokens",2048);
        json.set("top_p",1);
        json.set("frequency_penalty",0.0);
        json.set("presence_penalty",0.6);

        HttpResponse response = HttpRequest.post("https://api.openai.com/v1/completions")
                .headerMap(headers, false)
                .bearerAuth("API keys")
                .body(String.valueOf(json))
                .timeout(5 * 60 * 1000)
                .execute();

        System.out.println(response.body());
    }
}
</code></pre>
<p>调用返回结果：</p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_80bc1f3014183f70417ebdfd5e72c59f.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_80bc1f3014183f70417ebdfd5e72c59f.jpg" alt="" /></a></p>
<p><span id="more-385"></span></p>
<p>使用场景有很多，具体需求可以在官网实例中找到自己感兴趣的场景学习研究。目前Github上有很多优秀的基于ChatGPT二次开发的封装的项目，可以多多试验。<br />
&#8211; <a class="wp-editor-md-post-content-link" href="https://zhuanlan.zhihu.com/p/597371088#:~:text=%E7%9B%98%E7%82%B9%E8%BF%91%E6%9C%9F%E9%9D%9E%E5%B8%B8%E7%81%AB%E7%83%AD%E7%9A%84ChatGPT%E5%BC%80%E6%BA%90%E9%A1%B9%E7%9B%AE%201%20ChatGPT%20Vscode%20Plugin%202%20wechat-chatgpt,3%20ChatGPT%20for%20Google%204%20chatgpt-api%205%20awesome-chatgpt-prompts">盘点近期非常火热的ChatGPT开源项目</a></p>
<ul>
<li><a class="wp-editor-md-post-content-link" href="https://github.com/search?q=chatgpt">Github项目</a><br />
<a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_e0554dde3570512c0360d4849ce37c01.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_e0554dde3570512c0360d4849ce37c01.jpg" alt="" /></a></li>
</ul>
<p><!--more--></p>
<p>我也根据一个<a class="wp-editor-md-post-content-link" href="https://github.com/slippersheepig/chatgpt-web">开源小项目</a>搭建了一个网页版ChatGPT<br />
https://github.com/slippersheepig/chatgpt-web</p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_56fec56cbff554deb16365657736a89f.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_56fec56cbff554deb16365657736a89f.jpg" alt="" /></a></p>
<p><!--more--></p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_008801e6c58082083fc00cfdbd1864e4.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_008801e6c58082083fc00cfdbd1864e4.jpg" alt="" /></a></p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_272b1739f0fe2ef4b1de8837ee761ad4.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2023/02/wp_editor_md_272b1739f0fe2ef4b1de8837ee761ad4.jpg" alt="" /></a></p>
<p><strong>PS：18美元的免费额度，大概能回答54000000字。每天限制调用200次</strong></p>
<p><a href="https://www.laobaiblog.top/2023/02/21/chatgpt%e6%8e%a5%e5%85%a5%e5%ae%9e%e4%be%8b/">ChatGPT Java实例接入</a>最先出现在<a href="https://www.laobaiblog.top">Liao&#039;s blog</a>。</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>ChatGPT注册使用系列一</title>
		<link>https://www.laobaiblog.top/2022/12/08/chatgpt%e6%b3%a8%e5%86%8c%e4%bd%bf%e7%94%a8%e7%b3%bb%e5%88%97%e4%b8%80/</link>
		
		<dc:creator><![CDATA[大白]]></dc:creator>
		<pubDate>Thu, 08 Dec 2022 09:53:50 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[分享]]></category>
		<category><![CDATA[ChatGPT]]></category>
		<category><![CDATA[openAi]]></category>
		<category><![CDATA[人工智能]]></category>
		<guid isPermaLink="false">https://www.laobaiblog.top/?p=354</guid>

					<description><![CDATA[<p>ChatGPT 是什么？ 这个问题，由ChatGPT 亲自回答：:satisfied: ChatGP &#8230;</p>
<p><a href="https://www.laobaiblog.top/2022/12/08/chatgpt%e6%b3%a8%e5%86%8c%e4%bd%bf%e7%94%a8%e7%b3%bb%e5%88%97%e4%b8%80/">ChatGPT注册使用系列一</a>最先出现在<a href="https://www.laobaiblog.top">Liao&#039;s blog</a>。</p>
]]></description>
										<content:encoded><![CDATA[<h2>ChatGPT 是什么？</h2>
<p><strong>这个问题，由ChatGPT 亲自回答：</strong>:satisfied:</p>
<blockquote><p>
  ChatGPT 是一种自然语言生成模型，它用来自然地生成与人类语言交互。这是一种机器学习技术，它可以通过对大量文本数据进行学习，然后利用这些学习结果来生成新的文本。这种技术可以用来改善人机交互，提高聊天机器人的效率。-ChatGPT<br />
  <!---->
</p></blockquote>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_7a347ec149313ab6e8d8f1a2559b1fa9.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_7a347ec149313ab6e8d8f1a2559b1fa9.jpg" alt="" /></a></p>
<h2>OpenAI 又是什么？</h2>
<p><strong>如是说：</strong></p>
<blockquote><p>
  OpenAI 是一家人工智能研究和开发公司，它的目标是通过研究和开发人工智能技术来解决全球最重要的问题。OpenAI 是由一群技术领袖和慈善家共同创立的，包括 Elon Musk 和 Sam Altman 等。该公司的研究领域包括人工智能、机器学习、神经网络等。OpenAI 也开发了许多技术产品，例如 GPT-3、Dactyl 等。-ChatGPT
</p></blockquote>
<h5>以下是维基百科关于 ChatGPT 的相关介绍：</h5>
<blockquote><p>
  ChatGPT是由OpenAI开发的一个人工智能聊天机器人程序，于2022年11月30日推出。该程序使用基于GPT-3.5架构的大型语言模型并通过强化学习进行训练。ChatGPT 使用基于人类反馈的强化学习进行训练，这种方法通过人类干预以增强机器学习的效果，从而获得更为逼真的结果。其使用基于GPT-3.5架构的语言模型。在训练过程中，人类训练师扮演着用户与人工智能助手的角色。模型在Microsoft Azure的超级计算机上训练，并通过近端策略优化算法（proximal policy optimization）进行微调。这种策略优化算法比信任域策略优化（trust region policy optimization）算法更为高效。
</p></blockquote>
<h2>如何注册 ChatGPT</h2>
<p>要注册使用 ChatGPT，你需要做好以下准备：</p>
<ul>
<li>全局代理（推荐美国节点）</p>
</li>
<li>
<p>一个邮箱用于注册（Gmail, Outlook 均可）</p>
</li>
<li>
<p>一个国外手机号用于接收验证码（Google Voice 虚拟号码不行）</p>
</li>
<li>
<p>一个浏览器（建议使用无痕模式）</p>
</li>
</ul>
<p>关于第1个准备，本文就不做介绍了，这种内容不能写在文章里，懂的都懂。第2和第4个准备应该没什么问题，本文会详细介绍第3个准备步骤。</p>
<h5>ChatGPT 具体注册步骤如下：</h5>
<ol>
<li><strong>在你的设备上开启全局代理。</strong><br />
建议使用美国地区的节点。</p>
</li>
<li>
<p><strong>访问 ChatGPT 登录页开始注册。</strong><br />
ChatGPT 登录页为 https://chat.openai.com/auth/login。点击 Sign up 根据提示进行创建一个 OpenAI 账号；输入你的电子邮箱继续。如果你有 Gmail，你也可以点击下方的 Continue with Google 按钮直接以 Google 账号注册。</p>
</li>
</ol>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_f1b760fa61d92871613eb716a22d629e.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_f1b760fa61d92871613eb716a22d629e.jpg" alt="" /></a></p>
<ol start="3">
<li><strong>根据屏幕指示操作。</strong><br />
完善你的姓名，机构名称可不填，点击下方的 Continue 按钮后，你会来到验证手机号码界面：</li>
</ol>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_89f68fb4e988517d20d997e4c1cdcfbf.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_89f68fb4e988517d20d997e4c1cdcfbf.jpg" alt="" /></a><br />
先停在这个界面；接下来我们需要准备一个手机号码接收验证码。</p>
<ol start="4">
<li><strong>前往接码平台租用一个海外手机号</strong><br />
我们只需要一个临时的海外手机号来接收 OpenAI 的验证码即可，不需要购买海外的实体手机卡。<br />
推荐在 <a class="wp-editor-md-post-content-link" href="https://sms-activate.org/cn">sms-activate.org</a> 上花 $0.2 买一个印度尼西亚的手机号接收验证码。具体操作步骤如下：<br />
1) 前往 sms-activate.org 并注册账号；注册完成后登录账号。<br />
注：如果英文界面看不懂，可以切换语言为中文。<br />
)2 点击右上角下方的金额，然后选择开始充值：</li>
</ol>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_a8d0d1e9bf9cc5e7d18c5e797015a1e2.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_a8d0d1e9bf9cc5e7d18c5e797015a1e2.jpg" alt="" /></a><br />
3) 下滑屏幕找到 Alipay 并点击，在弹出的窗口中输入你要充值的金额。充值0.2美元即可。</p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_0f21e0ec9e15cb0cb77c0d43ffcefcce.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_0f21e0ec9e15cb0cb77c0d43ffcefcce.jpg" alt="" /></a><br />
4) 充值完毕后，返回首页；在左侧边栏的搜索框内，输入 openai 找到 OpenAI 服务，并点击：</p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_60c226957d487a6898e2de4e501741e9.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_60c226957d487a6898e2de4e501741e9.jpg" alt="" /></a><br />
点击 Indonesia 右侧的购物车按钮，你会得到一个62开头的印度尼西亚手机号码。<br />
5) 将这个手机号码复制并粘贴至步骤3中的验证手机号码界面，然后点击 Send code via SMS。</p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_b29aaa995ba0e4b2105dc17228a1e595.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_b29aaa995ba0e4b2105dc17228a1e595.jpg" alt="" /></a><br />
留意 sms-activate.org 页面，很快将会收到来自 OpenAI API 的验证码；将验证码填入 OpenAI 页面的验证码输入框，即可完成验证。</p>
<ol start="5">
<li><strong>选择你注册 OpenAI 的主要用途</strong><br />
此处选择“I’m exploring personal feature” 即可。</li>
</ol>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_42b08a56e887c0ce4780bacd9334e3c0.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_42b08a56e887c0ce4780bacd9334e3c0.jpg" alt="" /></a></p>
<ol start="6">
<li><strong>开始使用 ChatGPT</strong><br />
接下来，只需点击顶部的 Try it，然后使用前面注册的 OpenAI 账号登录，就可以开始与 ChatGPT 聊天啦！</li>
</ol>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_02e08441064e5d7d5318a27d46a27a99.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_02e08441064e5d7d5318a27d46a27a99.jpg" alt="" /></a></p>
<ol start="7">
<li><strong>在底部输入框内输入你想要问的问题，开始与 ChatGPT 进行互动。</strong></li>
</ol>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_ae80d4b3775a1ace6f333ec44fcd8c77.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_ae80d4b3775a1ace6f333ec44fcd8c77.jpg" alt="" /></a></p>
<ol start="8">
<li><strong>随堂测试</strong></li>
</ol>
<p><strong>我还写什么代码！直接描述。</strong></p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_81129c7a40b00243c2b225a7dd1ba270.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_81129c7a40b00243c2b225a7dd1ba270.jpg" alt="" /></a></p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_b8c8dc474036c1ccc3dc899f99306444.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_b8c8dc474036c1ccc3dc899f99306444.jpg" alt="" /></a></p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_a598d50b83e1c713c9a6eb396417dd1b.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_a598d50b83e1c713c9a6eb396417dd1b.jpg" alt="" /></a></p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_eabf9b99f14d5619760d5dd4491f338a.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_eabf9b99f14d5619760d5dd4491f338a.jpg" alt="" /></a></p>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_41be113a0bc660f660526381b45c7702.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_41be113a0bc660f660526381b45c7702.jpg" alt="" /></a></p>
<ol start="9">
<li><strong>ChatGPT现状</strong><br />
目前公开接口部分大致实现了文本、图像、文件等，搭建了一个本地环境，但因为请求网络的原因暂时没法完全研究它的功能模块，但我相信那一天不会遥远！</li>
</ol>
<p><a class="wp-editor-md-post-content-link" href="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_7d497c01d915d9d92ea43a3658f07a78.jpg"><img decoding="async" src="https://www.laobaiblog.top/wp-content/uploads/2022/12/wp_editor_md_7d497c01d915d9d92ea43a3658f07a78.jpg" alt="" /></a></p>
<p><a href="https://www.laobaiblog.top/2022/12/08/chatgpt%e6%b3%a8%e5%86%8c%e4%bd%bf%e7%94%a8%e7%b3%bb%e5%88%97%e4%b8%80/">ChatGPT注册使用系列一</a>最先出现在<a href="https://www.laobaiblog.top">Liao&#039;s blog</a>。</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
