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

01.ai Yi Client #3048

Closed
wants to merge 9 commits into from
Closed

01.ai Yi Client #3048

wants to merge 9 commits into from

Conversation

uukuguy
Copy link

@uukuguy uukuguy commented Jun 30, 2024

Why are these changes needed?

To enhance the support of non-OpenAI models with AutoGen. The 01.ai Yi family of models includes yi-large etc.
Developers can utilize the AI capabilities of the Yi series LLMs to perform a variety of tasks, such as text generation, language translation, content summarization, logical reasoning, mathematical calculation, and code generation.

  • Pricing Implemented
  • API Checks
  • Create
  • Tool calls
  • get_usage

Checks

@uukuguy
Copy link
Author

uukuguy commented Jun 30, 2024

@microsoft-github-policy-service agree

Copy link
Collaborator

@Hk669 Hk669 left a comment

Choose a reason for hiding this comment

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

I couldn't find the pricing as well. please feel free to share some references. Thanks

api_key
), "Please include the api_key in your config list entry for Yi or set the YI_API_KEY env variable."

self._oai_client = OpenAI(api_key=api_key, base_url=base_url)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand, why are we initializing an OpenAI client again? can you please explain this.

Copy link
Author

Choose a reason for hiding this comment

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

According to the official documentation, 01.AI provides an HTTP request interface highly compatible with OpenAI API, but no SDKs for Python or other languages have been found so far.
I'm undecided, so I'll first use the method of the OpenAI API client that I usually use. Other possible implementations include:

  • Using requests
  • Inheriting the autogen.oai.OpenAIClient
    Any suggestions?
Copy link
Collaborator

@Hk669 Hk669 Jul 1, 2024

Choose a reason for hiding this comment

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

i think this looks good. please let us know the status of the tests using the model. a notebook/ tutorial on this is appreciated. thanks @uukuguy

cc @marklysze @qingyun-wu

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible just to use base_url and api_key on a standard config and use the normal OpenAI client rather than use a specific class for Yi.

Copy link
Author

Choose a reason for hiding this comment

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

I also agree with directly using the OpenAI client to access the Yi API. The only major difference is that the Yi API can only use some of the parameters from the OpenAI API. So, still need Yi client?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, that's a good point and I think it's useful to be able to handle client specific parameters. Okay, we move forward with testing then.

@qingyun-wu or @sonichi, let us know if you think this okay to proceed with or if there's another approach.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@uukuguy, @marklysze thanks for the discussion! Yes, it's okay to proceed with the current approach!


# Cost per thousand tokens - Input / Output (NOTE: Convert $/Million to $/K)
YI_PRICING_1K = {
"yi-large": (0.003, 0.003),
Copy link
Collaborator

Choose a reason for hiding this comment

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

are these models not open sourced? do they have a separate client that could be accessed with the OpenAI python SDK and API key?

Copy link
Author

Choose a reason for hiding this comment

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

According to the official documentation, 01.AI provides an HTTP request interface highly compatible with OpenAI API, but no SDKs for Python or other languages have been found so far.

Copy link
Collaborator

Choose a reason for hiding this comment

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

According to the official documentation, 01.AI provides an HTTP request interface highly compatible with OpenAI API, but no SDKs for Python or other languages have been found so far.

How should we run and test the client? Can you provide a code sample?

Copy link
Author

@uukuguy uukuguy Jul 1, 2024

Choose a reason for hiding this comment

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

# You can get an account with a $5 free credit at https://platform.01.ai/apikeys to create your own YI_API_KEY.

# Use openai client
import os
from openai import OpenAI
client = OpenAI(api_key=os.getenv("YI_API_KEY"), base_url=os.getenv("YI_BASE_URL", "https://api.01.ai/v1"))

# Use autogen.oai client
from autogen.oai.yi import YiClient
client = YiClient(api_key=os.getenv("YI_API_KEY"))
Copy link
Collaborator

@marklysze marklysze Jul 1, 2024

Choose a reason for hiding this comment

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

Thanks, are you able to test it with these sample autogen scripts?

https://github.com/marklysze/AutoGenCodeTesting

I use them when developing client classes.

@marklysze
Copy link
Collaborator

Hey @uukuguy, thanks so much for putting this together. In line with @Hk669's questions, can you describe how you use this client?

I can see there's an official Yi API but it's limited to Beta Testers - is this designed to use that?

I'd love to test it but I'm not sure how to get started and whether I need an account somewhere.

@uukuguy
Copy link
Author

uukuguy commented Jul 1, 2024

Hey @uukuguy, thanks so much for putting this together. In line with @Hk669's questions, can you describe how you use this client?

I can see there's an official Yi API but it's limited to Beta Testers - is this designed to use that?

I'd love to test it but I'm not sure how to get started and whether I need an account somewhere.

01.AI's LLM API is located at https://platform.01.ai/, currently featuring only the yi-large model, with plans to deliver multiple models such as yi-large-turbo, yi-medium, and yi-vision. The Yi series of open-source models can be found at https://huggingface.co/01-ai, including several popular models like Yi-1.5-34B.

According to the official documentation, 01.AI provides an HTTP request interface highly compatible with OpenAI API, but no SDKs for Python or other languages have been found so far.

@uukuguy
Copy link
Author

uukuguy commented Jul 1, 2024

I couldn't find the pricing as well. please feel free to share some references. Thanks

@Hk669 https://platform.01.ai/docs#models-and-pricing

@qingyun-wu
Copy link
Collaborator

@uukuguy thanks the the amzing PR. It seems there are some format issues. Could you help fix those by running pre-commit? Thanks!

@qingyun-wu
Copy link
Collaborator

@uukuguy, I am wondering what's the status of this PR. Could you fix conflicts and also the code format issues? Thank you!

@yiranwu0
Copy link
Collaborator

yiranwu0 commented Jul 8, 2024

If 01.ai is highly compatible with openai, this PR might not be need. For example, deepinfra support openai's format, and we only need to pass in an additional base_url. Can you check if it works this way?

{
        # using DeepInfra
        "model": "meta-llama/Meta-Llama-3-70B-Instruct",
        "api_key": "YOUR_API_KEY",
        "base_url": "https://api.deepinfra.com/v1/openai" # need to specify the base_url
 }
@Hk669
Copy link
Collaborator

Hk669 commented Jul 14, 2024

@uukuguy i believe we can close this PR, as @yiranwu0 mentioned, it should work just with passing an extra argument base_url and is highly compatible with openai. update us with the status. thanks

cc @marklysze @qingyun-wu please share your thoughts on this. thanks

@qingyun-wu qingyun-wu closed this Jul 16, 2024
@marklysze
Copy link
Collaborator

@uukuguy i believe we can close this PR, as @yiranwu0 mentioned, it should work just with passing an extra argument base_url and is highly compatible with openai. update us with the status. thanks

cc @marklysze @qingyun-wu please share your thoughts on this. thanks

Thanks @Hk669, yes I didn't get a response from Yi about function calling either, so this can be revisited perhaps if they update their API to differentiate or provide more capability than just the OpenAI API compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants