From 13030a1c543461ac7f20c98173d6586664d19f16 Mon Sep 17 00:00:00 2001 From: Benjamin BERNARD Date: Wed, 11 Jun 2025 14:46:51 +0200 Subject: [PATCH] :bug: [Gen AI Tooling] Let user choose the number of chunk embeded per request. This solved the rate limit issue especially if a single request trigger it. --- .../models/em/azureopenai/azure_openai_em_setting.py | 6 +++++- .../models/em/openai/openai_em_setting.py | 10 +++++++--- .../langchain/factories/em/azure_openai_em_factory.py | 5 +++-- .../langchain/factories/em/openai_em_factory.py | 3 ++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/models/em/azureopenai/azure_openai_em_setting.py b/gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/models/em/azureopenai/azure_openai_em_setting.py index 5c0cb432d8..4d350e9105 100644 --- a/gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/models/em/azureopenai/azure_openai_em_setting.py +++ b/gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/models/em/azureopenai/azure_openai_em_setting.py @@ -38,7 +38,7 @@ class AzureOpenAIEMSetting(BaseEMSetting): ) api_key: SecretKey = Field( description='The secret that stores the API key used to authenticate requests to the AI Provider API.', - examples=[RawSecretKey(secret='ab7-************-A1IV4B')] + examples=[RawSecretKey(secret='ab7-************-A1IV4B')], ) deployment_name: str = Field( description='The deployment name you chose when you deployed the model.', @@ -55,3 +55,7 @@ class AzureOpenAIEMSetting(BaseEMSetting): description='The API version to use for this operation.', examples=['2023-05-15'], ) + number_of_chunk_per_request: int = Field( + description='The number of chunks sent per request, take care of your rate limits. Default value is 50', + default=50, + ) diff --git a/gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/models/em/openai/openai_em_setting.py b/gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/models/em/openai/openai_em_setting.py index ad71e485da..bb8c9ea977 100644 --- a/gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/models/em/openai/openai_em_setting.py +++ b/gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/models/em/openai/openai_em_setting.py @@ -37,11 +37,15 @@ class OpenAIEMSetting(BaseEMSetting): ) api_key: SecretKey = Field( description='The secret that stores the API key used to authenticate requests to the AI Provider API.', - examples=[RawSecretKey(secret='ab7-************-A1IV4B')] + examples=[RawSecretKey(secret='ab7-************-A1IV4B')], ) model: str = Field(description='The model id', examples=['text-embedding-ada-002']) base_url: str = Field( description='The OpenAI endpoint base URL', examples=['https://api.openai.com/v1'], - default='https://api.openai.com/v1' - ) \ No newline at end of file + default='https://api.openai.com/v1', + ) + number_of_chunk_per_request: int = Field( + description='The number of chunks sent per request, take care of your rate limits. Default value is 50.', + default=50, + ) diff --git a/gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/services/langchain/factories/em/azure_openai_em_factory.py b/gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/services/langchain/factories/em/azure_openai_em_factory.py index 623247c2a3..9af4086848 100644 --- a/gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/services/langchain/factories/em/azure_openai_em_factory.py +++ b/gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/services/langchain/factories/em/azure_openai_em_factory.py @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Credit Mutuel Arkea +# Copyright (C) 2023-2025 Credit Mutuel Arkea # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -47,8 +47,9 @@ def get_embedding_model(self) -> Embeddings: azure_endpoint=str(self.setting.api_base), azure_deployment=self.setting.deployment_name, # the model is not Nullable, it has a default value - model=self.setting.model or OpenAIEmbeddings.__fields__["model"].default, + model=self.setting.model or OpenAIEmbeddings.__fields__['model'].default, timeout=application_settings.em_provider_timeout, + chunk_size=self.setting.number_of_chunk_per_request, ) @openai_exception_handler(provider='AzureOpenAIService') diff --git a/gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/services/langchain/factories/em/openai_em_factory.py b/gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/services/langchain/factories/em/openai_em_factory.py index 7d031db73e..1a46d6ca32 100644 --- a/gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/services/langchain/factories/em/openai_em_factory.py +++ b/gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/services/langchain/factories/em/openai_em_factory.py @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Credit Mutuel Arkea +# Copyright (C) 2023-2025 Credit Mutuel Arkea # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -50,6 +50,7 @@ def get_embedding_model(self) -> Embeddings: base_url=self.setting.base_url, model=self.setting.model, timeout=application_settings.em_provider_timeout, + chunk_size=self.setting.chunk_size, ) @openai_exception_handler(provider='OpenAI')