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

feat: add the ability to explicitly deconfigure a model provider #1018

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pkg/api/handlers/modelprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,26 @@ func (mp *ModelProviderHandler) Configure(req api.Context) error {
return req.Update(&ref)
}

func (mp *ModelProviderHandler) Deconfigure(req api.Context) error {
var ref v1.ToolReference
if err := req.Get(&ref, req.PathValue("id")); err != nil {
return err
}

if ref.Spec.Type != types.ToolReferenceTypeModelProvider {
return types.NewErrBadRequest("%q is not a model provider", ref.Name)
}

if err := mp.gptscript.DeleteCredential(req.Context(), string(ref.UID), ref.Name); err != nil && !strings.HasSuffix(err.Error(), "credential not found") {
return fmt.Errorf("failed to update credential: %w", err)
}

// Stop the model provider so that the credential is completely removed from the system.
mp.dispatcher.StopModelProvider(ref.Namespace, ref.Name)

return nil
}

func (mp *ModelProviderHandler) Reveal(req api.Context) error {
var ref v1.ToolReference
if err := req.Get(&ref, req.PathValue("id")); err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/api/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func Router(services *services.Services) (http.Handler, error) {
mux.HandleFunc("GET /api/model-providers", modelProviders.List)
mux.HandleFunc("GET /api/model-providers/{id}", modelProviders.ByID)
mux.HandleFunc("POST /api/model-providers/{id}/configure", modelProviders.Configure)
mux.HandleFunc("POST /api/model-providers/{id}/deconfigure", modelProviders.Deconfigure)
mux.HandleFunc("POST /api/model-providers/{id}/reveal", modelProviders.Reveal)
mux.HandleFunc("POST /api/model-providers/{id}/refresh-models", modelProviders.RefreshModels)

Expand Down