Cody: Update Azure OpenAI client and force api-version to a stable one#61005
Conversation
ad1d72e to
24044a1
Compare
There was a problem hiding this comment.
in case we update the client again, could it be that their response parser breaks if it doesn't support that version anymore?
Not a blocker, this is still a good change, just a little scared.
Maybe we could use our HTTP recorder tests here to ensure that a newer version of the library is still able to parse the response alright?
There was a problem hiding this comment.
I see this ClientOptions struct has a field called APIVersion - I assume this is not useful for us?
There was a problem hiding this comment.
I see this ClientOptions struct has a field called
APIVersion- I assume this is not useful for us?
Correct assumption: Request failed: this client doesn't support overriding its API version
There was a problem hiding this comment.
Ah, unfortunate :( if the method looked like this, it would be configurable by us :(
// NewClientWithKeyCredential creates a new instance of Client that connects to an Azure OpenAI endpoint.
// - endpoint - Azure OpenAI service endpoint, for example: https://{your-resource-name}.openai.azure.com
// - credential - used to authorize requests with an API Key credential
// - options - client options, pass nil to accept the default values.
func NewClientWithKeyCredential(endpoint string, credential *azcore.KeyCredential, options *ClientOptions) (*Client, error) {
if options == nil {
options = &ClientOptions{
// NEW:
ClientOptions: azcore.ClientOptions{
APIVersion: "2023-09-23",
},
}
}
authPolicy := runtime.NewKeyCredentialPolicy(credential, "api-key", nil)
azcoreClient, err := azcore.NewClient(clientName, version, runtime.PipelineOptions{
// NEW:
APIVersion: runtime.APIVersionOptions{Location: runtime.APIVersionLocationQueryParam, Name: "api-version"},
PerRetry: []policy.Policy{authPolicy},
}, &options.ClientOptions)
if err != nil {
return nil, err
}
return &Client{
internal: azcoreClient,
clientData: clientData{
endpoint: endpoint,
azure: true,
},
}, nil
}There was a problem hiding this comment.
in case we update the client again, could it be that their response parser breaks if it doesn't support that version anymore?
Totally this is far from ideal but better then reimplementing service principals, workload identity and the others. I'll add a backlog item to add a recorder test, it's a bit of a pain to get the format of the events.
0208c82 to
e98bbc5
Compare
| Transport: &apiVersionRoundTripper{ | ||
| rt: azureClientDefaultTransport, | ||
| apiVersion: apiVersion, | ||
| }, |
There was a problem hiding this comment.
one last thing, since this doesn't wrap our httpcli transport, these requests won't be counted accordingly and cannot appear in the outgoing request logs. Not a blocker for now, but would be nice to wrap that in here.
There was a problem hiding this comment.
Not adding for now since it's not a regression i'll add to the follow up issue along with parsing tests.
|
Follow up issues to improve solution https://github.com/sourcegraph/sourcegraph/issues/61031 |
|
The backport to To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-5.3 5.3
# Navigate to the new working tree
cd .worktrees/backport-5.3
# Create a new branch
git switch --create backport-61005-to-5.3
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 aa36a51eb76b0fa039ee3a0dda01743c726ac953
# Push it to GitHub
git push --set-upstream origin backport-61005-to-5.3
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-5.3If you encouter conflict, first resolve the conflict and stage all files, then run the commands below: git cherry-pick --continue
# Push it to GitHub
git push --set-upstream origin backport-61005-to-5.3
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-5.3
|
This updates the Azure OpenAI client and also overrides the round tripper to force it to use the stable 2023-05-15 api version instead of the default which uses preview versions that keep being retired.
closes https://github.com/sourcegraph/sourcegraph/issues/60934
Test plan
Verify chat works and uses correct api version:
Verify autocomplete works and uses correct api version