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

Custom Model Client support #1345

Merged
merged 55 commits into from
Feb 2, 2024
Merged

Custom Model Client support #1345

merged 55 commits into from
Feb 2, 2024

Conversation

olgavrou
Copy link
Contributor

@olgavrou olgavrou commented Jan 19, 2024

Why are these changes needed?

This PR adds support for custom client calls to be made. The idea is that the user can specify their own custom client class and load it into the configuration (e.g. for loading local models). As long as they adhere to the Client class's interface and response protocol then everything should work fine with only this addition to the config (full usage shown in the unit test):

So if we have the class CustomClient the class name (as a string) needs to be set as the api_type in the config:

config_list = [
    {
        "model": "local_model_name",
        "model_client_cls" = "CustomClient",
        "device": "cuda",
        "params": {
            "max_length": 1000,
            "temperature": 1.1,
            [other params that will be consumed in the Custom Client so user has full control over what is set and what is consumed]
        }
    }
]

Then once an agent is created the custom client can be registered:

agent.register_custom_client(CustomClient, [optional other args for the constuctor of CustomClient])

Notes:
Ideally the client interface would not live under a directory called oai and the client wrapper wouldn't be called OpenAIWrapper but something more generic, but that can be examined at a later date

Related PR

Replaces #831 and has less refactoring done so that the change is more contained

Checks

@codecov-commenter
Copy link

codecov-commenter commented Jan 19, 2024

Codecov Report

Attention: 97 lines in your changes are missing coverage. Please review.

Comparison is base (b0c1f8d) 33.12% compared to head (1ea55cc) 46.59%.

❗ Current head 1ea55cc differs from pull request most recent head 479696c. Consider uploading reports for the commit 479696c to get more accurate results

Files Patch % Lines
autogen/oai/client.py 39.62% 88 Missing and 8 partials ⚠️
autogen/agentchat/conversable_agent.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1345       +/-   ##
===========================================
+ Coverage   33.12%   46.59%   +13.47%     
===========================================
  Files          42       42               
  Lines        5051     5112       +61     
  Branches     1157     1239       +82     
===========================================
+ Hits         1673     2382      +709     
+ Misses       3250     2530      -720     
- Partials      128      200       +72     
Flag Coverage Δ
unittests 46.53% <40.49%> (+13.45%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sonichi sonichi enabled auto-merge February 2, 2024 17:18
@sonichi sonichi added this pull request to the merge queue Feb 2, 2024
Merged via the queue into microsoft:main with commit 00417ed Feb 2, 2024
53 checks passed
@ekzhu
Copy link
Collaborator

ekzhu commented Feb 3, 2024

Just want to say I am so happy it is merged finally!

@marklysze
Copy link
Collaborator

Fantastic work, thank you

@olgavrou olgavrou mentioned this pull request Feb 5, 2024
3 tasks
whiskyboy pushed a commit to whiskyboy/autogen that referenced this pull request Apr 17, 2024
* add client interface, response protocol, and move code into openai client class

* add ability to register custom client

* tidy up code

* adding checks and errors, and more unit tests

* remove code

* fix error msg

* add use_docer False in notebook

* better error message

* add another example to custom model notebook

* rename and have register_client take model name too

* make Client protocol and remove inheritance

* renames

* update notebook

* add link

* rename and more error checking for registered agents

* adding message retrieval to client protocol for more flexible response

* fix failing openai test

* api_type req made model_client_cls requirement

* notebook cleanup and added blog

* remove raise error if client list is empty - client list will never be empty it will have placeholders

* rename Client -> ModelClient

* add forgotten file

* fix test by fetching internal client

* Update autogen/oai/client.py

Co-authored-by: Eric Zhu <[email protected]>

* don't add retrieval function to cache

* added placeholder cllient class during initial client init, and rewrote registration

* fix spelling

* Update autogen/agentchat/conversable_agent.py

Co-authored-by: Chi Wang <[email protected]>

* type hints, small fixes, docstr comment

* fix api type checking

---------

Co-authored-by: Eric Zhu <[email protected]>
Co-authored-by: Chi Wang <[email protected]>
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.

8 participants