Skip to content

Python: Azure OpenAI text embedding function does not cap inputs #2099

@gramhagen

Description

@gramhagen

Describe the bug
In python using the AzureTextEmbedding:generate_embeddings_async() method with more than 16 elements in the texts list will generate an error because the API doesn't support more than 16.

To Reproduce
Steps to reproduce the behavior:

import asyncio
from semantic_kernel.connectors.ai.open_ai import AzureTextEmbedding

async def embed_test(texts):
    generator = AzureTextEmbedding(
        deployment_name=AOAI_TEXT_EMBEDDING,
        endpoint=AOAI_URL,
        api_key=AOAI_KEY,
    )
    return await generator.generate_embeddings_async(texts)

asyncio.run(embed_test(texts=["hello"]*20))

generates:

semantic_kernel/connectors/ai/open_ai/services/open_ai_text_embedding.py", line 77, in generate_embeddings_async
    raise AIException(
semantic_kernel.connectors.ai.ai_exception.AIException: (<ErrorCodes.ServiceError: 6>, 'OpenAI service failed to generate embeddings', InvalidRequestError(message='Too many inputs. The max number of inputs is 16.  We hope to increase the number of inputs per request soon. Please contact us through an Azure support request at: https://go.microsoft.com/fwlink/?linkid= for further questions.', param=None, code=None, http_status=400, request_id=None))

Expected behavior
It would be nice to provide a way of processing more than 16 inputs

Platform

  • OS: Ubuntu [WSL]
  • IDE: VS Code
  • Language: Python
  • Source: main branch of repository [5721ac4]

Metadata

Metadata

Assignees

Labels

.NETIssue or Pull requests regarding .NET codebugSomething isn't workingpythonPull requests for the Python Semantic Kernel

Type

No type

Projects

Status

Sprint: Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions