Skip to content

Commit

Permalink
feat: add the ability to explicitly deconfigure a model provider
Browse files Browse the repository at this point in the history
Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams authored and cjellick committed Dec 26, 2024
1 parent 432d39a commit 6ce2501
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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

0 comments on commit 6ce2501

Please sign in to comment.