langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
92.28k stars 14.74k forks source link

如何修改langchain包默认访问api.openai.com请求地址,我需要通过代理访问api.openai.com #4759

Closed liuyang77886 closed 9 months ago

liuyang77886 commented 1 year ago

Feature request

本地局域网网络受限,需要通过反向代理访问api.openai.com地址,请问如何修改langchain包访问chatgpt的地址为我的代理地址

Motivation

本地局域网网络受限,需要通过反向代理访问api.openai.com地址,请问如何修改langchain包访问chatgpt的地址为我的代理地址

Your contribution

我使用的项目是gpt4-pdf-chatbot-langchain

liaokongVFX commented 1 year ago

You can set the openai API environment variable "OPENAI_API_BASE".

Related: https://github.com/liaokongVFX/LangChain-Chinese-Getting-Started-Guide/issues/1

FlowerWrong commented 1 year ago

Just pass this parameter openai_api_base see https://github.com/hwchase17/langchain/blob/master/langchain/llms/openai.py#L148

ChatOpenAI(
        temperature=temperature,
        max_tokens=2000,
        model_name=api_key.model,
        openai_api_key=api_key.api_key,
        openai_api_base=api_key.api_base,
)
zerrymore11 commented 1 year ago

The gpt4-pdf-chatbot-langchain project is an application of langchian's typescript version. I have not found the interface to modify the host, i.e., the attribute openai_api_base.

dosubot[bot] commented 9 months ago

Hi, @liuyang77886! I'm Dosu, and I'm here to help the LangChain team manage our backlog. I wanted to let you know that we are marking this issue as stale.

From what I understand, you were requesting guidance on how to modify the default API request address in the langchain package to a proxy address for restricted local network access to api.openai.com. Users liaokongVFX and FlowerWrong have provided solutions by setting the OPENAI_API_BASE environment variable and passing the openai_api_base parameter respectively. User zerrymore11 mentioned that they couldn't find the interface to modify the host.

I'm happy to inform you that this issue has been resolved. The provided solutions by liaokongVFX and FlowerWrong should allow you to modify the default API request address. You can either set the OPENAI_API_BASE environment variable or pass the openai_api_base parameter. These solutions should address your concern about modifying the host.

Before we close this issue, could you please confirm if this issue is still relevant to the latest version of the LangChain repository? If it is, please let us know by commenting on this issue. Otherwise, feel free to close the issue yourself. If we don't hear from you within 7 days, the issue will be automatically closed.

Thank you for your understanding and contribution to the LangChain project!

Best regards, Dosu

harveymx commented 21 hours ago

The gpt4-pdf-chatbot-langchain project is an application of langchian's typescript version. I have not found the interface to modify the host, i.e., the attribute openai_api_base.

with langchainjs,It can be :

const model = new ChatOpenAI({ configuration: { baseURL:"YOUR PROXY URL "}, apiKey: "YOUR API KEY", model:"XXX" });