Skip to content

max_retries param is wrongly initialized in AzureOpenAIGenerator and AzureOpenAIChatGenerator #9127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
danielescaramuzzi opened this issue Mar 27, 2025 · 3 comments · Fixed by #9128
Labels
Contributions wanted! Looking for external contributions good first issue Good for newcomers

Comments

@danielescaramuzzi
Copy link
Contributor

danielescaramuzzi commented Mar 27, 2025

Describe the bug

AzureOpenAIGenerator and AzureOpenAIChatGenerator init methods do:

self.max_retries = max_retries or int(os.environ.get("OPENAI_MAX_RETRIES", 5))

it means that if max_retries == 0, than self.max_retries = 5 (bacause max_retries evaluates to False ).

To Reproduce

from haystack import Pipeline
from haystack.components.generators.azure import AzureOpenAIGenerator

pipeline = Pipeline()

pipeline.add_component("generator", AzureOpenAIGenerator(max_retries=0))

print(pipeline.dumps())

Output:

components:
  generator:
    init_parameters:
      api_key:
        env_vars:
        - AZURE_OPENAI_API_KEY
        strict: false
        type: env_var
      api_version: '2023-05-15'
      azure_ad_token:
        env_vars:
        - AZURE_OPENAI_AD_TOKEN
        strict: false
        type: env_var
      azure_deployment: gpt-4o-mini
      azure_endpoint: ***
      default_headers: {}
      generation_kwargs: {}
      max_retries: 5
      organization: null
      streaming_callback: null
      system_prompt: null
      timeout: 30.0
    type: haystack.components.generators.azure.AzureOpenAIGenerator
connection_type_validation: true
connections: []
max_runs_per_component: 100
metadata: {}

Expected behavior
Output of example should be:

components:
  generator:
    init_parameters:
      api_key:
        env_vars:
        - AZURE_OPENAI_API_KEY
        strict: false
        type: env_var
      api_version: '2023-05-15'
      azure_ad_token:
        env_vars:
        - AZURE_OPENAI_AD_TOKEN
        strict: false
        type: env_var
      azure_deployment: gpt-4o-mini
      azure_endpoint: ***
      default_headers: {}
      generation_kwargs: {}
      max_retries: 0
      organization: null
      streaming_callback: null
      system_prompt: null
      timeout: 30.0
    type: haystack.components.generators.azure.AzureOpenAIGenerator
connection_type_validation: true
connections: []
max_runs_per_component: 100
metadata: {}
@julian-risch
Copy link
Member

julian-risch commented Mar 27, 2025

Hello @danielescaramuzzi and thank you for reporting this issue. I think this could be a good first issue for someone to contribute to Haystack. In case you or someone else wants to work on small fix just let us now and follow our contributing guide to open PR.
Otherwise we'll pick it up in one of our next sprints. We should also double check if other (Chat)Generators are affected by this use of max_retries.

@julian-risch
Copy link
Member

julian-risch commented Mar 27, 2025

A fix could be as simple as changing the line to

self.max_retries = max_retries if max_retries is not None else int(os.environ.get("OPENAI_MAX_RETRIES", 5))

and we should add a new unit test or extend an existing one.

@danielescaramuzzi
Copy link
Contributor Author

I'll work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Contributions wanted! Looking for external contributions good first issue Good for newcomers
Projects
2 participants