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

pass ModelConfigInfo down to client.Get() for self-hosted-models#63739

Merged
emidoots merged 7 commits into
mainfrom
sg/self-hosted-models
Jul 9, 2024
Merged

pass ModelConfigInfo down to client.Get() for self-hosted-models#63739
emidoots merged 7 commits into
mainfrom
sg/self-hosted-models

Conversation

@emidoots

@emidoots emidoots commented Jul 9, 2024

Copy link
Copy Markdown
Member

This PR has a single goal: pass a new ModelConfigInfo type, which has the Provider and Model we should use to serve a completions request, down into client.Get()

This PR explicitly only handles the case we care about for Self-hosted models, and all pieces of logic that I expect will be replaced/superseded by your work @chrsmith are annotated with // TODO(slimsag): self-hosted-models: comments so we can easily find and remove them when your work is ready.

Every location I have modified has been carefully wrapped in an if statement like if conf.Get().SiteConfig().ModelConfiguration != nil to ensure that this change only affects people who set the new "modelConfiguration" site config property.

Test plan

  1. Configured "modelConfiguration" and removed "completions" in my dev instances' site config.
  2. Used VS Code chat to confirm I see this codepath is connected end-to-end and I get a TODO error back:

image

Changelog

N/A

Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
@emidoots emidoots requested a review from chrsmith July 9, 2024 21:13
@cla-bot cla-bot Bot added the cla-signed label Jul 9, 2024
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
// Using the new "modelConfiguration" site config
// TODO(slimsag): self-hosted-models: this logic only handles Cody Enterprise with Self-hosted models
// Only in this case do we have modelConfigInfo != nil
return nil, errors.Newf("TODO: implement self-hosted-models")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is all in service of having modelConfigInfo right here.

@chrsmith chrsmith left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have suggestions for how we can rewrite the logic within getModel to be clearer. But given that I'll rewrite the function entirely in XX hours, I wouldn't worry too much about it. :D

if modelConfig := conf.Get().SiteConfig().ModelConfiguration; modelConfig != nil {
// Using new "modelConfiguration" site config.
// TODO(slimsag): self-hosted-models: currently this logic only handles Cody Enterprise with Self-hosted models
if err := modelconfig.ValidateModelRef(modelconfigtypes.ModelRef(requestParams.Model)); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This code seems a little hard to follow since you're essentially adding fallback options in case there is an error. So what do you think about inverting the error condition so this is a little easier to follow, e.g.:

// WDYT of using 'modelconfigSDK' rather than 'modelconfigtypes'?
import modelconfigSDK ".../types"

// Check if the user supplied a valid ModelRef.
if requestParams.Model != "" {
    mref := modelconfigSDK.ModelRef(requestParams.Model)
    if err := modelconfig.ValidateModelRef(mref); err == nil {
        return requestParams.Model, nil
    }
}

// Fallback to using the default models as per the configuration.
modelConfig, err := frontendmodelconfig.Get().Get()
if err != nil {
    return "", err
}
return string(modelConfig.DefaultModels.CodeCompletion), nil

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

👍 on modelconfigSDK

Comment thread cmd/frontend/internal/httpapi/completions/get_model.go Outdated
modelConfig, err := modelconfig.Get().Get()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For both of these 500 return paths, we use logger.Error(...). Since otherwise it'll be a pain to debug or troubleshoot any issues users run into.

Stephen Gutekanst added 5 commits July 9, 2024 14:55
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
@emidoots emidoots merged commit bd3baef into main Jul 9, 2024
@emidoots emidoots deleted the sg/self-hosted-models branch July 9, 2024 22:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants