Skip to content
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

Compatibility with AzureOpenAI #67

Merged
merged 48 commits into from
Aug 23, 2024
Merged

Conversation

NP4567-dev
Copy link
Collaborator

@NP4567-dev NP4567-dev commented Jul 31, 2024

Adressing: #60

Context:
Though the wrapped class is the same for Azure OpenAI, there is a difference in the model names: azure does not use dots in the name (chatgpt-3.5 in openai API becomes chatgpt-35 in azure).

Impacts:
Rework of the find_model method in two steps

  • the method checks if the name with deleted dots matches a name in the provider's models' names or if the provided name matches one of the provider's name
  • if there was no match in the first step the matching is done again to check if any of the provider's model name contains the provided name
    This prevents gpt-4-turbo matching gtp-4 for example.

The choice was made not to add azure as a provider and to consider a model running on either azure or openai infrastructure has the same impacts, this could be discussed.

Side effects:
As of right now, there is no side effects (no false positive matching) but further down the line too many provider specific matching rules could become a hassle to maintain.

  • added docs: example using AzureOpenAI client
  • added unit test checking that the names used in azure now match model name in the csv file

@samuelrince
Copy link
Member

Thanks for this work @NP4567-dev, I'll be reviewing it next week! 🙏

Copy link
Member

@samuelrince samuelrince left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before merging, can you add some tests for AzureOpenAI clients?

You can copy and adapt the tests from test_openai.py and add them to the same file. The objective is to make sure that we stay compatible with Azure's client as well.

To create the test, you will need an Azure account, which I assume you have. Add your API key and endpoint as environment variables AZURE_OPENAI_API_KEY and AZURE_OPENAI_ENDPOINT. Also add fake env var in conftest.py. Run the tests with make test-record as stated in the newly added contribution docs.

Don't hesitate to comment if you have issues adding these tests! 🤗

Comment on lines 39 to 46
for model in self.__models:
# To handle specific LiteLLM calling (e.g., mistral/mistral-small)
if model.provider == provider and model.name in model_name:
return model
return None
provider_models = [model for model in self.__models if model.provider == provider]
return next(
(
model
for model in provider_models
if (model.name == model_name or model.name.replace(".", "") == model_name)
),
next((model for model in provider_models if model.name in model_name), None),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of changing this function, I would rather add the models to the models.csv file. For instance, gpt-35-turbo will be a duplicated line of gpt-3.5-turbo. We plan to refactor the model repository to introduce aliases in the future.

Copy link
Collaborator Author

@NP4567-dev NP4567-dev Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok perfect, adding some kind of aliases mechanic was something I tought of but felt was a bit overkill for just azure.

This function still needs to be changed at some point though. Currently it seems like gpt-4-turbo and gpt-o match with gpt-4. (I can move this to another PR/open an issue if needed as this is a separated problem). Or aliases can fix this too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I think this bug was introduced when adding litellm, will get it fixed in the next release for sure! 🙏

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the tests is proving to be a bit more complicated than I anticipated.

Python-recording or the underlying vcrpy seems to always be trying to overwrite some cassettes.
Running "make test" raises vcr.errors.CannotOverwriteExistingCassetteExceptionon on google, huggingface and litellm tests. Even after cloning and reinstalling from scratch this still happens.

I did manage to generate a cassette for azure openai, but whenever I try to run the tests using it, the same error is raised.

Any idea on how to solve this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks for letting me know. That is indeed a strange behavior... Can you push your code as it is right now? So I can try on my side, see if I have the same issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NP4567-dev I think I have found your work on your fork (branch feature/azure-tests).

The issue you have is probably because the name of the tests you've added for Azure OpenAI are equal to the tests for OpenAI.

Meaning that if you change the function names from test_openai_chat to test_azure_openai_chat in the test_azure_openai.py file, it should work properly. :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this was another problem I had already fixed locally.
I did find the issue though, we have a proxy that prevented url matching on the cassettes, hence the recording attempt.
It is fixed now, I just have a few final verification to make and it should be ready to merge

ycouble and others added 2 commits August 22, 2024 09:28
* revert: roll back find_model and deleted related tests, updated data csv

* feat: review changes

* feat: added tests and slight fix

* fix: removed extra csv rows

* fix: rolled back env specific changes

* fix: rolled back env specific changes
@NP4567-dev NP4567-dev requested a review from samuelrince August 23, 2024 10:06
@samuelrince samuelrince merged commit 8000592 into genai-impact:main Aug 23, 2024
2 checks passed
@samuelrince samuelrince mentioned this pull request Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants