Open DanielV1992 opened 2 weeks ago
Just ran into this issue as well... I've also set the azure-openai-emit-token-metric APIM API policy. When the APIM setting to support custom metrics is enabled, this error occurs. When I disable the custom metrics, this error does not occur. When I directly use the openai
python library to get embeddings, there's no error as far so far. So the workaround is to just use the openai python library directly for embeddings if you want to keep using the azure-openai-emit-token-metric
APIM API policy.
Another workaround appears to be simply setting check_embedding_ctx_length=False
; see https://api.python.langchain.com/en/latest/embeddings/langchain_openai.embeddings.base.OpenAIEmbeddings.html#langchain_openai.embeddings.base.OpenAIEmbeddings.check_embedding_ctx_length
@nuernber - you are a lifesaver! Building a whole AI platform with APIM and token consumption mechanisms, only the have this ambiguous error, was annoying. Yet your solution is easy to implement and proven to be working. Thanks a lot!
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
ApimUtils-set_embed : Error while initializing embedding model - Error code: 400 - {'statusCode': 400, 'message': "Unable to parse and estimate tokens from incoming request. Please ensure incoming request is of one of the following types: 'Chat Completion', 'Completion', 'Embeddings' and works with current prompt estimation mode of 'Auto'."}
Description
When using the AzureOpenAIEmbedding class with our Azure APIM in front of our Azure OpenAI services it breaks within our APIM policy which captures/calculates prompt/completion tokens from the request. We believe this is due to how the AzureOpenAIEmbedding class is sending a list of integers ex. b'{"input": [[3923, 374, 279, 4611, 96462, 46295, 58917, 30]], "model": "text-embedding-ada-002", "encoding_format": "base64"}' vs [str] from the query text.
System Info
System Information
Package Information