Getting an exception while running the openai embeddings

Hello All,

Getting an exception while running the openai embeddings

embeddings = OpenAIEmbeddings(
deployment_id=“text-embedding-ada-002-v2”)
text = “test query.”
embeddings.embed_query(text)

“Unexpected exception formatting exception. Falling back to standard exception”

Traceback (most recent call last):
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 3460, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File “/var/folders/rr/wr3ktvm51c17wbz1kndmx2h80000gn/T/ipykernel_1398/1546663507.py”, line 8, in
embeddings.embed_query(text)
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/langchain/embeddings/openai.py”, line 578, in embed_query
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/langchain/embeddings/openai.py”, line 549, in embed_documents
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/langchain/embeddings/openai.py”, line 425, in _get_len_safe_embeddings
except KeyError:
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/langchain/embeddings/openai.py”, line 106, in embed_with_retry
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/llm_commons/llm/openai/proxy_embedding.py”, line 46, in create
response = _create(cls,
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/llm_commons/llm/openai/proxy_completion.py”, line 183, in _create
return ProxyEngineAPIResource.create(*args, **kwargs)
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/llm_commons/llm/openai/proxy_api_engine_resource.py”, line 33, in create
) = ProxyEngineAPIResource.prepare_create_request(api_key, api_base, api_type, api_version, organization,
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/llm_commons/llm/openai/proxy_api_engine_resource.py”, line 84, in prepare_create_request
params) = ProxyEngineAPIResource._EngineAPIResource__prepare_create_request(
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/openai/api_resources/abstract/engine_api_resource.py”, line 80, in __prepare_create_request
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/openai/api_resources/abstract/api_resource.py”, line 169, in _get_api_type_and_version
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/openai/util.py”, line 35, in from_str
AttributeError: ‘NoneType’ object has no attribute ‘lower’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 2057, in showtraceback
stb = self.InteractiveTB.structured_traceback(
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/IPython/core/ultratb.py”, line 1118, in structured_traceback
return FormattedTB.structured_traceback(
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/IPython/core/ultratb.py”, line 1012, in structured_traceback
return VerboseTB.structured_traceback(
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/IPython/core/ultratb.py”, line 865, in structured_traceback
formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/IPython/core/ultratb.py”, line 818, in format_exception_as_a_whole
frames.append(self.format_record(r))
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/IPython/core/ultratb.py”, line 736, in format_record
result += ‘’.join(_format_traceback_lines(frame_info.lines, Colors, self.has_colors, lvals))
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/stack_data/utils.py”, line 145, in cached_property_wrapper
value = obj.dict[self.func.name] = self.func(obj)
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/stack_data/core.py”, line 698, in lines
pieces = self.included_pieces
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/stack_data/utils.py”, line 145, in cached_property_wrapper
value = obj.dict[self.func.name] = self.func(obj)
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/stack_data/core.py”, line 649, in included_pieces
pos = scope_pieces.index(self.executing_piece)
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/stack_data/utils.py”, line 145, in cached_property_wrapper
value = obj.dict[self.func.name] = self.func(obj)
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/stack_data/core.py”, line 628, in executing_piece
return only(
File “/Users/TEST/anaconda3/lib/python3.10/site-packages/executing/executing.py”, line 164, in only
raise NotOneValueFound(‘Expected one value, found 0’)
executing.executing.NotOneValueFound: Expected one value, found 0

The error informs you that it is expecting a string as input but you sent it a None value… some empty parameter somewhere. Might try updating to the latest openai library version, see if that fixes it.

You say running an OpenAI embedding, can you give a code snippet of the API call that produced the error? there is very little to go on here.

It seems you are using langchain. Not the ideal way to use embeddings - or any OpenAI product really.

The OpenAI python library has recently changed significantly, and Langchain instead has shims for many providers of AI services to keep up with.

If you want stability, you’ll need to pip install openai=0.28.1, the last version to use the format that would not throw such an error with naive use. Then also find a version of Langchain to stick with that is not haphazardly adapting to the changes from two weeks ago.

1 Like