Skip to content

Commit

Permalink
feat: add icons to model providers
Browse files Browse the repository at this point in the history
The icons are added through the tool reference.

Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams committed Dec 5, 2024
1 parent a23826b commit 9645fad
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions apiclient/types/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type ModelStatus struct {
}

type ModelProviderStatus struct {
Icon string `json:"icon,omitempty"`
Configured bool `json:"configured"`
RequiredConfigurationParameters []string `json:"requiredConfigurationParameters,omitempty"`
MissingConfigurationParameters []string `json:"missingConfigurationParameters,omitempty"`
Expand Down
28 changes: 17 additions & 11 deletions pkg/api/handlers/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,25 +188,31 @@ func convertModel(ctx context.Context, c kclient.Client, gClient *gptscript.GPTS
func convertModelProviderToolRef(ctx context.Context, gptscript *gptscript.GPTScript, toolRef v1.ToolReference) (*types.ModelProviderStatus, error) {
var (
requiredEnvVars, missingEnvVars []string
icon string
)
if toolRef.Status.Tool != nil && toolRef.Status.Tool.Metadata["envVars"] != "" {
cred, err := gptscript.RevealCredential(ctx, []string{string(toolRef.UID)}, toolRef.Name)
if err != nil && !strings.HasSuffix(err.Error(), "credential not found") {
return nil, fmt.Errorf("failed to reveal credential for model provider %q: %w", toolRef.Name, err)
}

if toolRef.Status.Tool != nil {
if toolRef.Status.Tool.Metadata["envVars"] != "" {
requiredEnvVars = strings.Split(toolRef.Status.Tool.Metadata["envVars"], ",")
}
cred, err := gptscript.RevealCredential(ctx, []string{string(toolRef.UID)}, toolRef.Name)
if err != nil && !strings.HasSuffix(err.Error(), "credential not found") {
return nil, fmt.Errorf("failed to reveal credential for model provider %q: %w", toolRef.Name, err)
}

for _, envVar := range requiredEnvVars {
if cred.Env[envVar] == "" {
missingEnvVars = append(missingEnvVars, envVar)
if toolRef.Status.Tool.Metadata["envVars"] != "" {
requiredEnvVars = strings.Split(toolRef.Status.Tool.Metadata["envVars"], ",")
}

for _, envVar := range requiredEnvVars {
if cred.Env[envVar] == "" {
missingEnvVars = append(missingEnvVars, envVar)
}
}
}

icon = toolRef.Status.Tool.Metadata["icon"]
}

return &types.ModelProviderStatus{
Icon: icon,
Configured: toolRef.Status.Tool != nil && len(missingEnvVars) == 0,
RequiredConfigurationParameters: requiredEnvVars,
MissingConfigurationParameters: missingEnvVars,
Expand Down
6 changes: 6 additions & 0 deletions pkg/storage/openapi/generated/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions ui/admin/public/assets/anthropic_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions ui/admin/public/assets/azure_openai_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9645fad

Please sign in to comment.