HamaWhiteGG / langchain-java

Java version of LangChain, while empowering LLM for Big Data.
Apache License 2.0
551 stars 107 forks source link

Do you have any proxy servers that require authentication support? #30

Closed kael-aiur closed 1 year ago

kael-aiur commented 1 year ago

I use my own proxy server to access the OpenAI interface, but my proxy server requires authentication. However, I do not know how to set the authentication information for the current interface, so I received the following error message:

Exception in thread "main" java.lang.RuntimeException: java.io.IOException: Failed to authenticate with proxy
    at io.reactivex.internal.util.ExceptionHelper.wrapOrThrow(ExceptionHelper.java:45)
    at io.reactivex.internal.observers.BlockingMultiObserver.blockingGet(BlockingMultiObserver.java:90)
    at io.reactivex.Single.blockingGet(Single.java:2002)
    at com.hw.openai.OpenAiClient.create(OpenAiClient.java:195)
    at com.hw.langchain.llms.openai.BaseOpenAI._generate(BaseOpenAI.java:192)
    at com.hw.langchain.llms.base.BaseLLM.generate(BaseLLM.java:61)
    at com.hw.langchain.llms.base.BaseLLM.call(BaseLLM.java:50)
    at com.hw.langchain.llms.base.BaseLLM.call(BaseLLM.java:54)
    at com.netease.mail.demo.langchain.Application.main(Application.java:19)
Caused by: java.io.IOException: Failed to authenticate with proxy
    at okhttp3.internal.connection.RealConnection.createTunnel(RealConnection.java:418)
    at okhttp3.internal.connection.RealConnection.connectTunnel(RealConnection.java:236)
    at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:177)
    at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.java:224)
    at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.java:108)
    at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.java:88)
    at okhttp3.internal.connection.Transmitter.newExchange(Transmitter.java:169)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:41)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
    at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:223)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
    at com.hw.openai.OpenAiClient.lambda$init$0(OpenAiClient.java:101)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:229)
    at okhttp3.RealCall.execute(RealCall.java:81)
    at retrofit2.OkHttpCall.execute(OkHttpCall.java:204)
    at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:46)
    at io.reactivex.Observable.subscribe(Observable.java:10151)
    at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:35)
    at io.reactivex.Observable.subscribe(Observable.java:10151)
    at io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35)
    at io.reactivex.Single.subscribe(Single.java:2517)
    at io.reactivex.Single.blockingGet(Single.java:2001)
HamaWhiteGG commented 1 year ago

I have added two parameters: proxyUsername and proxyPassword. You can try them out (I don't have the environment to test them). Here's how to use them:

var llm = OpenAI.builder()
        .openaiOrganization("xxx")
        .openaiApiKey("xxx")
        .openaiProxy("http://host:port")
        .proxyUsername("xxx")
        .proxyPassword("xxx")
        .requestTimeout(16)
        .build()
        .init();