Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Fix azure completions api#63491

Merged
arafatkatze merged 2 commits into
mainfrom
fix-azure-completions-api
Jun 28, 2024
Merged

Fix azure completions api#63491
arafatkatze merged 2 commits into
mainfrom
fix-azure-completions-api

Conversation

@arafatkatze

@arafatkatze arafatkatze commented Jun 26, 2024

Copy link
Copy Markdown
Contributor

Linear Issue

The purpose of this PR is to make a backwords compatible solution such that the completions logic in our codebase for azure supports both the completions API(which is old) and also supports the chat/completions API which is new. This way we can use models from both of them with autocomplete.

NOTe: Since we can't figure out which model we are using because azure has the deployment name instead of model name and because of that we can't decide which API to use for which model we try with both of the APIs and then the API that works is cached for that model and then we used the cached API logic to choose the api to make subsequent completion calls this way we can choose either of the APIs and not have added latency with completions.

Test plan

I used the azure keys to try out different deployment models that we have both with the old and the new api.
Old API -> Completions (gpt-3.5-turbo-instruct, gpt-3.5-turbo(301), gpt-3.5-turbo(613))
New API -> Chat Completions(gpt-3.5-turbo(301), gpt-4o, gpt-3.5-turbo(613), gpt-3.5-turbo-16k)

NOTE both of the set of models work seamless with this PR.

Changelog

@cla-bot cla-bot Bot added the cla-signed label Jun 26, 2024
@arafatkatze arafatkatze requested a review from emidoots June 26, 2024 15:21
@arafatkatze arafatkatze marked this pull request as ready for review June 26, 2024 15:37
@emidoots

Copy link
Copy Markdown
Member

@arafatkatze Instead of this 'try both APIs and cache which one works' approach in code (which is kind of scary); can you go with one of these options instead:

  1. Land https://github.com/sourcegraph/sourcegraph/pull/63100 first - which would give us an azureChatModel field as part of the site config which you could rely on to detect models which require the old API.
  2. Just add a site config knob like how you added azureChatModel in the other PR, but this time named "azureUseDeprecatedCompletionsAPIForOldModels": true, or something to that effect.

Either of these would work. I think I prefer (2) but I am find with either option.

@arafatkatze

Copy link
Copy Markdown
Contributor Author

Okay Stephen I would go with option 2 great recommendation.

@arafatkatze arafatkatze force-pushed the fix-azure-completions-api branch from 24810b7 to 4af5394 Compare June 27, 2024 12:06
@arafatkatze

Copy link
Copy Markdown
Contributor Author

@slimsag Can you take a look again please?

}

// Streaming with ChatCompletions API
func tryStreamChatCompletionsAPI(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you can rename these tryFooBar functions to doFooBar that'd be nice.

@emidoots emidoots left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems reasonable now, thanks for the update!

@arafatkatze arafatkatze enabled auto-merge (squash) June 27, 2024 16:37
@arafatkatze arafatkatze disabled auto-merge June 27, 2024 16:37
@arafatkatze arafatkatze force-pushed the fix-azure-completions-api branch from 96b040e to 0835f3f Compare June 28, 2024 11:40
@arafatkatze arafatkatze force-pushed the fix-azure-completions-api branch from a40f2b4 to 39f7ee6 Compare June 28, 2024 12:44
@arafatkatze arafatkatze enabled auto-merge (squash) June 28, 2024 12:48
auto-merge was automatically disabled June 28, 2024 19:31

Pull Request is not mergeable

@arafatkatze arafatkatze enabled auto-merge (squash) June 28, 2024 19:35
@arafatkatze arafatkatze merged commit f5d5dec into main Jun 28, 2024
@arafatkatze arafatkatze deleted the fix-azure-completions-api branch June 28, 2024 19:41
@sourcegraph-release-bot sourcegraph-release-bot added backports release-blocker Prevents us from releasing: https://about.sourcegraph.com/handbook/engineering/releases failed-backport-to-5.3.3 labels Jun 28, 2024
@DaedalusG DaedalusG added backport 5.3.x and removed release-blocker Prevents us from releasing: https://about.sourcegraph.com/handbook/engineering/releases backports failed-backport-to-5.3.3 labels Jun 28, 2024
@sourcegraph-release-bot

Copy link
Copy Markdown
Collaborator

The backport to 5.3.x failed at https://github.com/sourcegraph/sourcegraph/actions/runs/9718247704:

The process '/usr/bin/git' failed with exit code 1

To backport this PR manually, you can either:

Via the sg tool

Use the sg backport command to backport your commit to the release branch.

sg backport -r 5.3.x -p 63491
Via your terminal

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.x 5.3.x
# Navigate to the new working tree
cd .worktrees/backport-5.3.x
# Create a new branch
git switch --create backport-63491-to-5.3.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 f5d5deceb0cfe6a6094f5619786a7ad2f890b2c2
# Push it to GitHub
git push --set-upstream origin backport-63491-to-5.3.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-5.3.x

If 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-63491-to-5.3.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-5.3.x
  • Follow above instructions to backport the commit.
  • Create a pull request where the base branch is 5.3.x and the compare/head branch is backport-63491-to-5.3.x., click here to create the pull request.

Once the pull request has been created, please ensure the following:

  • Make sure to tag @sourcegraph/release in the pull request description.

  • kindly remove the release-blocker from this pull request.

@sourcegraph-release-bot sourcegraph-release-bot added backports release-blocker Prevents us from releasing: https://about.sourcegraph.com/handbook/engineering/releases failed-backport-to-5.3.x labels Jun 28, 2024
@DaedalusG

Copy link
Copy Markdown
Contributor

@arafatkatze messed around to see if the backport bot would work here but it looks like its got some kinks still, also, these v5.3.x branches are a new thing so maybe the HEAD's not right or something like that

arafatkatze added a commit that referenced this pull request Jun 29, 2024
[Linear Issue

](https://linear.app/sourcegraph/issue/CODY-2586/fix-completions-models-api-for-azure-to-use-the-right-model-with-the)

The purpose of this PR is to make a backwords compatible solution such
that the completions logic in our codebase for azure supports both the
completions API(which is old) and also supports the chat/completions API
which is new. This way we can use models from both of them with
autocomplete.

NOTe: Since we can't figure out which model we are using because azure
has the deployment name instead of model name and because of that we
can't decide which API to use for which model we try with both of the
APIs and then the API that works is cached for that model and then we
used the cached API logic to choose the api to make subsequent
completion calls this way we can choose either of the APIs and not have
added latency with completions.

I used the azure keys to try out different deployment models that we
have both with the old and the new api.
Old API -> Completions (gpt-3.5-turbo-instruct, gpt-3.5-turbo(301),
gpt-3.5-turbo(613))
New API -> Chat Completions(gpt-3.5-turbo(301), gpt-4o,
gpt-3.5-turbo(613), gpt-3.5-turbo-16k)

NOTE both of the set of models work seamless with this PR.

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->

(cherry picked from commit f5d5dec)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

backports cla-signed failed-backport-to-5.3.x release-blocker Prevents us from releasing: https://about.sourcegraph.com/handbook/engineering/releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants