openai / openai-python

The official Python library for the OpenAI API
https://pypi.org/project/openai/
Apache License 2.0
23k stars 3.23k forks source link

Descrepancy results AsyncAzureOpenAI.azure_deployment and client.chat.completions.create(model) #1868

Open woutkonings opened 2 days ago

woutkonings commented 2 days ago

Confirm this is an issue with the Python library and not an underlying OpenAI API

Describe the bug

When running the AzureOpenAI service with azure_deployment gpt-4o 2024-05-13 I get very different completion results when I enter model='gpt-4' and model='gpt-4o'. I would expect the model parameter not to matter in this case, as there is only one model to choose from the given deployment.

To Reproduce

Run and observe stream:

async with AsyncAzureOpenAI(
        api_key=openai_api_key,
        azure_deployment=deployment_model,
        azure_endpoint=openai_azure_endpoint,
        api_version="2023-12-01-preview"
    ) as client:
        openai_stream = await client.chat.completions.create(
            model=model_name,
            messages=messages,
            temperature=0.2,
            max_tokens=1200,
            top_p=0.45,
            frequency_penalty=0,
            presence_penalty=0,
            stop=None,
            stream=True
        )

twice:

The first deployment will give markdown heavy response, structured with bold titles etc., while the second response will give solely paragraphs.

Code snippets

No response

OS

python:3.12-slim

Python version

python v.3.12

Library version

openai v.1.51.2

kristapratico commented 2 days ago

@woutkonings when passing azure_deployment into the AsyncAzureOpenAI constructor, the client will use that deployment for all requests. Any value provided for model will be ignored.

For chat completions, you can try adjusting temperature or provide a seed to get more deterministic results, but it is not guaranteed. Here's some docs that explain those two parameters: https://learn.microsoft.com/azure/ai-services/openai/reference-preview#createchatcompletionrequest