689  
查询码: 00000555
通过代理调用外网接口(GPT例)
作者: 系统管理员1 于 2023年05月09日 发布在分类 / 配置安装 / AI / 系统环境 ,于 2023年05月09日 编辑

Clash接口查看

Clash 每次开机启动后都在任务栏里边,我们也可以通过任务栏图标开启,关闭Clash代理。 Clash 默认监听端口为 7890, 其他程序想要自定义设置代理,只需手工设置代理地址为: 127.0.0.1 端口:7890 即可。 一个端口同时支持 HTTP/SOCKS5 协议。

粘贴图片



通过api方法添加代理


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.farm.service;
 
import com.unfbx.chatgpt.OpenAiClient;
import com.unfbx.chatgpt.entity.chat.ChatCompletion;
import com.unfbx.chatgpt.entity.chat.ChatCompletionResponse;
import com.unfbx.chatgpt.entity.chat.Message;
 
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.Arrays;
 
public class Test {
    public static void main(String[] args) {
 
        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 7890));
        // 代理可以为null
        OpenAiClient openAiClient = OpenAiClient.builder().apiKey("sk-59HdAVKcErpi33dh5Ko")
                .proxy(proxy).build();
        // 简单模型
        // CompletionResponse completions =
        // //openAiClient.completions("我想申请转专业,从计算机专业转到会计学专业,帮我完成一份两百字左右的申请书");
        // 最新GPT-3.5-Turbo模型
        Message message = Message.builder().role(Message.Role.USER).content("你好啊我的伙伴!").build();
        ChatCompletion chatCompletion = ChatCompletion.builder().messages(Arrays.asList(message)).build();
        ChatCompletionResponse chatCompletionResponse = openAiClient.chatCompletion(chatCompletion);
        chatCompletionResponse.getChoices().forEach(e -> {
            System.out.println(e.getMessage());
        });
    }
}

0人参与


 历史版本

备注 修改日期 修改人
创建版本 2023-05-09 19:01:11[当前版本] 系统管理员1

 附件

附件类型

PNGPNG

wcp知识库系统-京ICP备15024440号-1 -V 5.2.0 -wcp