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 icons to model providers #783

Merged
Merged
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
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.

15 changes: 14 additions & 1 deletion ui/admin/app/components/model-providers/ModelProviderLists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BoxesIcon, CircleCheckIcon, CircleSlashIcon } from "lucide-react";
import useSWR from "swr";

import { ModelProviderApiService } from "~/lib/service/api/modelProviderApiService";
import { cn } from "~/lib/utils";

import { ModelProviderConfigure } from "~/components/model-providers/ModelProviderConfigure";
import { Card, CardContent, CardHeader } from "~/components/ui/card";
Expand All @@ -25,7 +26,19 @@ export function ModelProviderList() {
</CardHeader>
<CardContent className="flex flex-col items-center gap-4">
<div className="w-16 h-16">
<BoxesIcon className="w-16 h-16 color-primary" />
{modelProvider.icon ? (
<img
src={modelProvider.icon}
alt={modelProvider.name}
className={cn("w-16 h-16", {
"dark:invert":
modelProvider.name !==
"Azure OpenAI",
})}
/>
) : (
<BoxesIcon className="w-16 h-16 color-primary" />
)}
</div>
<div className="text-lg font-semibold">
{modelProvider.name}
Expand Down
1 change: 1 addition & 0 deletions ui/admin/app/lib/model/modelProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EntityMeta } from "~/lib/model/primitives";

export type ModelProviderStatus = {
configured: boolean;
icon?: string;
requiredConfigurationParameters?: string[];
missingConfigurationParameters?: string[];
};
Expand Down
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.