From 5a207cce8f026e32c93bf271f80b73570d4b2844 Mon Sep 17 00:00:00 2001 From: warjiang <1096409085@qq.com> Date: Wed, 7 Jun 2023 22:32:57 +0800 Subject: [PATCH] fix: fullfill openai params when embedding (#5821) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #5822 I upgrade my langchain lib by execute `pip install -U langchain`, and the verion is 0.0.192。But i found that openai.api_base not working. I use azure openai service as openai backend, the openai.api_base is very import for me. I hava compared tag/0.0.192 and tag/0.0.191, and figure out that: ![image](https://github.com/hwchase17/langchain/assets/6478745/e183fdb2-8224-45c9-b3b4-26d62823999a) openai params is moved inside `_invocation_params` function,and used in some openai invoke: ![image](https://github.com/hwchase17/langchain/assets/6478745/5a55a048-5fa9-4bf4-aaef-3902226bec5e) ![image](https://github.com/hwchase17/langchain/assets/6478745/85b8cebc-eeb8-4538-a525-814719c8f8df) but still some case not covered like: ![image](https://github.com/hwchase17/langchain/assets/6478745/e0297620-f2b2-4f4f-98bd-d0ed19022dac) #### Before submitting #### Who can review? Tag maintainers/contributors who might be interested: @hwchase17 --------- Co-authored-by: Harrison Chase --- langchain/embeddings/openai.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/langchain/embeddings/openai.py b/langchain/embeddings/openai.py index c10a5526..82955164 100644 --- a/langchain/embeddings/openai.py +++ b/langchain/embeddings/openai.py @@ -97,8 +97,8 @@ class OpenAIEmbeddings(BaseModel, Embeddings): embeddings = OpenAIEmbeddings( deployment="your-embeddings-deployment-name", model="your-embeddings-model-name", - api_base="https://your-endpoint.openai.azure.com/", - api_type="azure", + openai_api_base="https://your-endpoint.openai.azure.com/", + openai_api_type="azure", ) text = "This is a test query." query_result = embeddings.embed_query(text) @@ -257,10 +257,10 @@ class OpenAIEmbeddings(BaseModel, Embeddings): average = embed_with_retry( self, input="", - engine=self.deployment, - request_timeout=self.request_timeout, - headers=self.headers, - )["data"][0]["embedding"] + **self._invocation_params, + )[ + "data" + ][0]["embedding"] else: average = np.average(_result, axis=0, weights=num_tokens_in_batch[i]) embeddings[i] = (average / np.linalg.norm(average)).tolist() @@ -280,10 +280,10 @@ class OpenAIEmbeddings(BaseModel, Embeddings): return embed_with_retry( self, input=[text], - engine=engine, - request_timeout=self.request_timeout, - headers=self.headers, - )["data"][0]["embedding"] + **self._invocation_params, + )[ + "data" + ][0]["embedding"] def embed_documents( self, texts: List[str], chunk_size: Optional[int] = 0