When I use langchain's OpenAIEmbeddings to access my deployed like openai service, it's not working properly #21015
Labels
🤖:bug
Related to a bug, vulnerability, unexpected error with an existing feature
Ɑ: embeddings
Related to text embedding models module
🔌: openai
Primarily related to OpenAI integrations
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
InternalServerError Traceback (most recent call last)
Cell In[7], line 1
----> 1 query_result = embeddings.embed_query("haha")
File /data/miniconda3/lib/python3.12/site-packages/langchain_openai/embeddings/base.py:573, in OpenAIEmbeddings.embed_query(self, text)
564 def embed_query(self, text: str) -> List[float]:
565 """Call out to OpenAI's embedding endpoint for embedding query text.
566
567 Args:
(...)
571 Embedding for the text.
572 """
--> 573 return self.embed_documents([text])[0]
File /data/miniconda3/lib/python3.12/site-packages/langchain_openai/embeddings/base.py:532, in OpenAIEmbeddings.embed_documents(self, texts, chunk_size)
529 # NOTE: to keep things simple, we assume the list may contain texts longer
530 # than the maximum context and use length-safe embedding function.
531 engine = cast(str, self.deployment)
--> 532 return self._get_len_safe_embeddings(texts, engine=engine)
File /data/miniconda3/lib/python3.12/site-packages/langchain_openai/embeddings/base.py:336, in OpenAIEmbeddings._get_len_safe_embeddings(self, texts, engine, chunk_size)
334 batched_embeddings: List[List[float]] = []
335 for i in _iter:
--> 336 response = self.client.create(
337 input=tokens[i : i + _chunk_size], **self._invocation_params
338 )
339 if not isinstance(response, dict):
340 response = response.model_dump()
File /data/miniconda3/lib/python3.12/site-packages/openai/resources/embeddings.py:114, in Embeddings.create(self, input, model, dimensions, encoding_format, user, extra_headers, extra_query, extra_body, timeout)
108 embedding.embedding = np.frombuffer( # type: ignore[no-untyped-call]
109 base64.b64decode(data), dtype="float32"
110 ).tolist()
112 return obj
--> 114 return self._post(
115 "/embeddings",
116 body=maybe_transform(params, embedding_create_params.EmbeddingCreateParams),
117 options=make_request_options(
118 extra_headers=extra_headers,
119 extra_query=extra_query,
120 extra_body=extra_body,
121 timeout=timeout,
122 post_parser=parser,
123 ),
124 cast_to=CreateEmbeddingResponse,
125 )
File /data/miniconda3/lib/python3.12/site-packages/openai/_base_client.py:1232, in SyncAPIClient.post(self, path, cast_to, body, options, files, stream, stream_cls)
1218 def post(
1219 self,
1220 path: str,
(...)
1227 stream_cls: type[_StreamT] | None = None,
1228 ) -> ResponseT | _StreamT:
1229 opts = FinalRequestOptions.construct(
1230 method="post", url=path, json_data=body, files=to_httpx_files(files), **options
1231 )
-> 1232 return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
File /data/miniconda3/lib/python3.12/site-packages/openai/_base_client.py:921, in SyncAPIClient.request(self, cast_to, options, remaining_retries, stream, stream_cls)
912 def request(
913 self,
914 cast_to: Type[ResponseT],
(...)
919 stream_cls: type[_StreamT] | None = None,
920 ) -> ResponseT | _StreamT:
--> 921 return self._request(
922 cast_to=cast_to,
923 options=options,
924 stream=stream,
925 stream_cls=stream_cls,
926 remaining_retries=remaining_retries,
927 )
File /data/miniconda3/lib/python3.12/site-packages/openai/_base_client.py:997, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
995 if retries > 0 and self._should_retry(err.response):
996 err.response.close()
--> 997 return self._retry_request(
998 options,
999 cast_to,
1000 retries,
1001 err.response.headers,
1002 stream=stream,
1003 stream_cls=stream_cls,
1004 )
1006 # If the response is streamed then we need to explicitly read the response
1007 # to completion before attempting to access the response text.
1008 if not err.response.is_closed:
File /data/miniconda3/lib/python3.12/site-packages/openai/_base_client.py:1045, in SyncAPIClient._retry_request(self, options, cast_to, remaining_retries, response_headers, stream, stream_cls)
1041 # In a synchronous context we are blocking the entire thread. Up to the library user to run the client in a
1042 # different thread if necessary.
1043 time.sleep(timeout)
-> 1045 return self._request(
1046 options=options,
1047 cast_to=cast_to,
1048 remaining_retries=remaining,
1049 stream=stream,
1050 stream_cls=stream_cls,
1051 )
File /data/miniconda3/lib/python3.12/site-packages/openai/_base_client.py:997, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
995 if retries > 0 and self._should_retry(err.response):
996 err.response.close()
--> 997 return self._retry_request(
998 options,
999 cast_to,
1000 retries,
1001 err.response.headers,
1002 stream=stream,
1003 stream_cls=stream_cls,
1004 )
1006 # If the response is streamed then we need to explicitly read the response
1007 # to completion before attempting to access the response text.
1008 if not err.response.is_closed:
File /data/miniconda3/lib/python3.12/site-packages/openai/_base_client.py:1045, in SyncAPIClient._retry_request(self, options, cast_to, remaining_retries, response_headers, stream, stream_cls)
1041 # In a synchronous context we are blocking the entire thread. Up to the library user to run the client in a
1042 # different thread if necessary.
1043 time.sleep(timeout)
-> 1045 return self._request(
1046 options=options,
1047 cast_to=cast_to,
1048 remaining_retries=remaining,
1049 stream=stream,
1050 stream_cls=stream_cls,
1051 )
File /data/miniconda3/lib/python3.12/site-packages/openai/_base_client.py:1012, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
1009 err.response.read()
1011 log.debug("Re-raising status error")
-> 1012 raise self._make_status_error_from_response(err.response) from None
1014 return self._process_response(
1015 cast_to=cast_to,
1016 options=options,
(...)
1019 stream_cls=stream_cls,
1020 )
InternalServerError: Error code: 500 - {'error': {'message': 'bad response status code 500 (request id: 20240429183824796230302KI7yGPut)', 'type': 'upstream_error', 'param': '500', 'code': 'bad_response_status_code'}}
Description
I would like langchain's OpenAIEmbeddings to work properly, just like the openai API
System Info
DEPRECATION: Loading egg at /data/miniconda3/lib/python3.12/site-packages/sacremoses-0.0.43-py3.8.egg is deprecated. pip 24.3 will enforce this behaviour change. A possible replacement is to use pip for package installation.. Discussion can be found at pypa/pip#12330
DEPRECATION: Loading egg at /data/miniconda3/lib/python3.12/site-packages/huggingface_hub-0.22.2-py3.8.egg is deprecated. pip 24.3 will enforce this behaviour change. A possible replacement is to use pip for package installation.. Discussion can be found at pypa/pip#12330
langchain @ file:///home/conda/feedstock_root/build_artifacts/langchain_1712896599223/work
langchain-community @ file:///home/conda/feedstock_root/build_artifacts/langchain-community_1713569638904/work
langchain-core==0.1.46
langchain-openai==0.1.4
langchain-text-splitters @ file:///home/conda/feedstock_root/build_artifacts/langchain-text-splitters_1709389732771/work
The text was updated successfully, but these errors were encountered: