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

change azure engine config to modelMapper #306

Merged
merged 12 commits into from
May 10, 2023

Conversation

GargantuaX
Copy link
Contributor

"azure engine" refers to the deployment name, and each deployment name can only deploy one model.
This means that if I use multiple models, I need to configure multiple engines.
Since a client can only configure one engine, I have to maintain many clients, which is not easy.

I submitted a pull request that uses a modelMapper to map the model to the deployment name. By default, the Azure deployment name uses the model name, it can work without any engine configuration.

@codecov
Copy link

codecov bot commented May 9, 2023

Codecov Report

Merging #306 (20f9762) into master (5f4ff3e) will increase coverage by 0.11%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #306      +/-   ##
==========================================
+ Coverage   92.52%   92.63%   +0.11%     
==========================================
  Files          22       22              
  Lines         669      679      +10     
==========================================
+ Hits          619      629      +10     
  Misses         37       37              
  Partials       13       13              
Impacted Files Coverage Δ
audio.go 81.53% <100.00%> (ø)
chat.go 100.00% <100.00%> (ø)
chat_stream.go 89.28% <100.00%> (ø)
client.go 91.96% <100.00%> (+0.61%) ⬆️
completion.go 100.00% <100.00%> (ø)
config.go 92.85% <100.00%> (+0.54%) ⬆️
edits.go 100.00% <100.00%> (ø)
embeddings.go 100.00% <100.00%> (ø)
moderation.go 100.00% <100.00%> (ø)
stream.go 90.62% <100.00%> (ø)

@sashabaranov
Copy link
Owner

Wow, thank you so much for such a great work!

client.go Outdated
// fullURL returns full URL for request.
// If API type is Azure, model is required to get deployment name.
// If API type is OpenAI, model will be ignored.
func (c *Client) fullURL(suffix, model string) string {
Copy link
Owner

Choose a reason for hiding this comment

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

As a suggestion: do we want to use variadic options here instead of the required model argument? That would require fewer changes to other parts of the library. https://gobyexample.com/variadic-functions

We didn't adopt this pattern for the whole library in #278, but it seems useful in the context of the fullURL method.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, I would be happy to do this job.

config.go Outdated
@@ -50,14 +50,21 @@ func DefaultConfig(authToken string) ClientConfig {
}
}

func DefaultAzureConfig(apiKey, baseURL, engine string) ClientConfig {
func DefaultAzureConfig(apiKey, baseURL string, modelMapper map[string]string) ClientConfig {
Copy link
Owner

Choose a reason for hiding this comment

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

I suggest we remove modelMapper argument here as it doesn't really fit the "default" config. Let's allow modifying it afterward.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

config.go Outdated
func DefaultAzureConfig(apiKey, baseURL string, modelMapper map[string]string) ClientConfig {
if len(modelMapper) == 0 {
modelMapper = map[string]string{
GPT3Dot5Turbo0301: "gpt-35-turbo-0301",
Copy link
Owner

Choose a reason for hiding this comment

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

What if modelMapper would be just a function that user can provide?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your suggestion is great, I tried to make those changes, the code become more concise and has better extensibility. I will submit the new code later.

@GargantuaX
Copy link
Contributor Author

Please review the code,thx

@wuhuizuo
Copy link

It's not compatible, it should not release in patch version!

Ref:

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