how to set OPENAI_API_BASE or OPENAI_PROXY? #8896
Replies: 3 comments 4 replies
-
Answer generated by a 🤖 AnswerHello, Based on the context you've provided, it seems you're trying to set the "OPENAI_API_BASE" and "OPENAI_PROXY" environment variables for the OpenAIEmbeddings class in the LangChain framework. To set these environment variables, you can do so when creating an instance of the from langchain.chat_models.openai import ChatOpenAI
openai = ChatOpenAI(
model_name="your-model-name",
openai_api_key="your-api-key",
openai_api_base="http://your-custom-endpoint",
openai_proxy="http://your-proxy-url"
) In the above code, replace These parameters are then used in the @property
def _client_params(self) -> Dict[str, Any]:
"""Get the parameters used for the openai client."""
openai_creds: Dict[str, Any] = {
"api_key": self.openai_api_key,
"api_base": self.openai_api_base,
"organization": self.openai_organization,
"model": self.model_name,
}
if self.openai_proxy:
import openai
openai.proxy = {"http": self.openai_proxy, "https": self.openai_proxy} # type: ignore[assignment] # noqa: E501
return {**self._default_params, **openai_creds} This property is then used in various methods of the For more information, you can refer to the following files in the LangChain repository:
Also, there are similar issues that have been solved in the LangChain repository that you might find helpful:
I hope this helps! If you have any other questions, feel free to ask. Best, Sources
This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. |
Beta Was this translation helpful? Give feedback.
-
Mainly because the OpenAIEmbeddings module will concatenate "embeddings" by default, but our embedding api is "embedding". |
Beta Was this translation helpful? Give feedback.
-
@dosu-bot How to set API Key to Empty when changing the openai_api_base because its optional parameter here. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Like this module ‘OpenAIEmbeddings()‘,I have bolded these parameters, how to set the address after custom encapsulated?
Such as 'http://xxx.cn/embedding'。I found in the process of using, no matter how I set up will give me the final URL to assemble, but actually is not what I want.
import os
os.environ["OPENAI_API_TYPE"] = "azure"
os.environ["OPENAI_API_BASE"] = "https://<your-endpoint.openai.azure.com/"
os.environ["OPENAI_API_KEY"] = "your AzureOpenAI key"
os.environ["OPENAI_API_VERSION"] = "2023-05-15"
os.environ["OPENAI_PROXY"] = "http://your-corporate-proxy:8080"
Beta Was this translation helpful? Give feedback.
All reactions