Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

在开启全局代理的情况下,Chat2DB无法调用OpenAI API,建议像IDEA那样支持手动设置代理 #84

Closed
IDJack opened this issue May 6, 2023 · 2 comments
Assignees
Labels
developing This feature will be added in future releases

Comments

@IDJack
Copy link
Contributor

IDJack commented May 6, 2023

以下是ChatGPT的回答:

Clash 是一个代理工具,它可以设置系统代理,使得大部分应用程序通过代理服务器进行通信。然而,并非所有的应用程序都会自动使用系统代理。Java 应用程序在某些情况下不会自动使用系统代理设置,因此您需要在 Java 代码中显式配置代理。

我本机HTTP代理端口是1080,修改类OpenAIClient的代码如下,则Chat2DB可以正常调用OpenAI API

    public static void refresh() {
        String apikey;
        ConfigService configService = ApplicationContextUtil.getBean(ConfigService.class);
        Config config = configService.find(OPENAI_KEY).getData();
        if (config != null) {
            apikey = config.getContent();
        } else {
            apikey = ApplicationContextUtil.getProperty(OPENAI_KEY);
        }
        log.info("refresh openai apikey:{}", maskApiKey(apikey));

        // 新增代码:自定义OkHttpClient,支持代理
        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 1080));
        OkHttpClient okHttpClient = new OkHttpClient.Builder().proxy(proxy).build();
        OPEN_AI_STREAM_CLIENT = OpenAiStreamClient.builder().apiHost(OpenAIConst.OPENAI_HOST).apiKey(
            Lists.newArrayList(apikey)).okHttpClient(okHttpClient).build();
        apiKey = apikey;
    }
@zhuangjiaju zhuangjiaju added the developing This feature will be added in future releases label May 8, 2023
@chenxian01
Copy link
Contributor

正在开发测试中

@chenxian01
Copy link
Contributor

已发布

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
developing This feature will be added in future releases
Projects
None yet
Development

No branches or pull requests

3 participants