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

Implement a JSON responding OpenAI LLM as JSONOpenAILLM #331

Merged

Conversation

burtenshaw
Copy link
Contributor

This pr implements a new class in distilabel.llm.openai named JSONOpenAILLM.

The class uses the json_response feature from Open AI and validates that the model selected is present in a hard coded list of models that support this feature.

@burtenshaw burtenshaw self-assigned this Feb 6, 2024
Copy link
Contributor

@plaguss plaguss left a comment

Choose a reason for hiding this comment

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

Thanks @burtenshaw! I left some comments, also we use pytest for the tests instead of unittest (other than using the mock module), if you could update those. Once the tests pass, looks good to me

src/distilabel/llm/openai.py Outdated Show resolved Hide resolved
tests/llm/test_openai.py Outdated Show resolved Hide resolved
src/distilabel/llm/openai.py Outdated Show resolved Hide resolved
Comment on lines 270 to 277
self.json_supporting_models = [
"gpt-4-0125-preview",
"gpt-4-turbo-preview",
"gpt-4-1106-preview",
"gpt-3.5-turbo-1106",
]
assert model in self.json_supporting_models, f"Provided `model` does not support JSON input, \
available models are {self.json_supporting_models}"
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it's just better to override the available_models property instead?

Copy link
Member

Choose a reason for hiding this comment

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

i.e. pull the models from OpenAI and filter the default models so that just those are used, and keep the fine-tunes, as we're unsure about those

Copy link
Member

Choose a reason for hiding this comment

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

Meaning the same property as available_models within OpenAILLM but with a slight filtering on the proprietary models offered by OpenAI

Copy link
Contributor Author

@burtenshaw burtenshaw Feb 6, 2024

Choose a reason for hiding this comment

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

@alvarobartt Thanks for your feedback.

like this?

    @cached_property
    def available_models(self) -> List[str]:
        """Returns the list of available models in your OpenAI account."""
        all_available_models = super().available_models
        json_supporting_models = [
            "gpt-4-0125-preview",
            "gpt-4-turbo-preview",
            "gpt-4-1106-preview",
            "gpt-3.5-turbo-1106",
        ]
        return list(set(all_available_models) & set(json_supporting_models))

It makes sense to combine the functionality. I'm just worried about making the logging clear when the model name is wrong.

In the situation where the user gives an incorrect model name, we should make it clear to the user whether it's incorrect because it doesn't support JSON or it isn't available on their account.

Copy link
Contributor Author

@burtenshaw burtenshaw Feb 6, 2024

Choose a reason for hiding this comment

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

I initially went for the separate approach because the account is asserted, then JSON compatibility is asserted.

🤔 I can of course just log in the available_models method if there are no JSON compatible model in the account's models.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm fair I get your point now :/ Then you can leave it as is for the moment, and if any issue arises we can revisit, but the current is fine too!

@plaguss
Copy link
Contributor

plaguss commented Feb 7, 2024

Would close #328

@burtenshaw burtenshaw merged commit d9e54e9 into argilla-io:main Feb 7, 2024
4 checks passed
jphme pushed a commit to jphme/distilabel that referenced this pull request Feb 20, 2024
* Implement JSON OpenAILLM by inheriting from OpenAILLM

* mock and test JSONOPenAILLM

* refactor test to decouple available models

* add documentation for JSONOpenAILLM

* expose JSONOpenAILLM in distilabel.llms

* sort and format

* sort and format

* Update tests/llm/test_openai.py

Co-authored-by: Agus <agustin.piqueres@gmail.com>

* switch testing from unittest to pytest

* sorting

* extra assert in test_generate

* format

* refactor tests to mock out OpenAI client

* Update src/distilabel/llm/openai.py

Co-authored-by: Alvaro Bartolome <alvarobartt@gmail.com>

* combine available models method

* use mocked openai in tests

* testing: move assert raise catch to fixture

* test: refactor fixture to not use globals

* refactor mocking for simplicity share assertion

---------

Co-authored-by: Agus <agustin.piqueres@gmail.com>
Co-authored-by: Alvaro Bartolome <alvarobartt@gmail.com>
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.

None yet

3 participants