Skip to content

Commit

Permalink
feat: add default model aliases
Browse files Browse the repository at this point in the history
Default model aliases replace the concept of a model being a default.
Now, a user can set up their default model aliases and tools can use
those to interact with the default models without needing to worry about
which model they are actually using.

This change extends to knowledge so that knowledge will always use the
same text-embedding model for a give knowledge set.

Another minor change here: renaming agent usage to llm.

Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams committed Nov 24, 2024
1 parent 043d1c8 commit d05210b
Show file tree
Hide file tree
Showing 33 changed files with 1,220 additions and 119 deletions.
5 changes: 3 additions & 2 deletions apiclient/types/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
type Agent struct {
Metadata
AgentManifest
AliasAssigned bool `json:"aliasAssigned,omitempty"`
AuthStatus map[string]OAuthAppLoginAuthStatus `json:"authStatus,omitempty"`
AliasAssigned bool `json:"aliasAssigned,omitempty"`
AuthStatus map[string]OAuthAppLoginAuthStatus `json:"authStatus,omitempty"`
TextEmbeddingModel string `json:"textEmbeddingModel,omitempty"`
}

type AgentList List[Agent]
Expand Down
21 changes: 21 additions & 0 deletions apiclient/types/defaultmodelalias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package types

type DefaultModelAliasType string

const (
DefaultModelAliasTypeTextEmbedding DefaultModelAliasType = "text-embedding"
DefaultModelAliasTypeLLM DefaultModelAliasType = "llm"
DefaultModelAliasTypeLLMMini DefaultModelAliasType = "llm-mini"
DefaultModelAliasTypeImageGeneration DefaultModelAliasType = "image-generation"
)

type DefaultModelAlias struct {
DefaultModelAliasManifest
}

type DefaultModelAliasManifest struct {
Alias string `json:"alias"`
Model string `json:"model"`
}

type DefaultModelAliasList List[DefaultModelAlias]
3 changes: 1 addition & 2 deletions apiclient/types/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type ModelManifest struct {
ModelProvider string `json:"modelProvider,omitempty"`
Alias string `json:"alias,omitempty"`
Active bool `json:"active"`
Default bool `json:"default"`
Usage ModelUsage `json:"usage,omitempty"`
}

Expand All @@ -31,7 +30,7 @@ type ModelProviderStatus struct {
type ModelUsage string

const (
ModelUsageAgent ModelUsage = "agent"
ModelUsageLLM ModelUsage = "llm"
ModelUsageEmbedding ModelUsage = "text-embedding"
ModelUsageImage ModelUsage = "image-generation"
)
5 changes: 3 additions & 2 deletions apiclient/types/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import "strings"
type Workflow struct {
Metadata
WorkflowManifest
AliasAssigned bool `json:"aliasAssigned,omitempty"`
AuthStatus map[string]OAuthAppLoginAuthStatus `json:"authStatus,omitempty"`
AliasAssigned bool `json:"aliasAssigned,omitempty"`
AuthStatus map[string]OAuthAppLoginAuthStatus `json:"authStatus,omitempty"`
TextEmbeddingModel string `json:"textEmbeddingModel,omitempty"`
}

type WorkflowList List[Workflow]
Expand Down
161 changes: 161 additions & 0 deletions apiclient/types/zz_generated.deepcopy.go

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

38 changes: 38 additions & 0 deletions pkg/alias/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,44 @@ func Get(ctx context.Context, c kclient.Client, obj v1.Aliasable, namespace stri
return c.Get(ctx, router.Key(alias.Spec.TargetNamespace, alias.Spec.TargetName), obj.(kclient.Object))
}

func GetFromScope(ctx context.Context, c kclient.Client, scope, namespace, name string) (kclient.Object, error) {
gvk := schema.GroupVersionKind{
Group: v1.SchemeGroupVersion.Group,
Version: v1.Version,
Kind: scope,
}

obj, err := c.Scheme().New(gvk)
if err != nil {
return nil, apierrors.NewNotFound(schema.GroupResource{
Group: gvk.Group,
Resource: gvk.Kind,
}, name)
}

cObj := obj.(kclient.Object)

var alias v1.Alias
if err := c.Get(ctx, router.Key("", KeyFromScopeID(scope, name)), &alias); apierrors.IsNotFound(err) {
return cObj, c.Get(ctx, router.Key(namespace, name), cObj)
} else if err != nil {
return nil, err
}

gvk.Kind = alias.Spec.TargetKind
obj, err = c.Scheme().New(gvk)
if err != nil {
return nil, apierrors.NewNotFound(schema.GroupResource{
Group: gvk.Group,
Resource: gvk.Kind,
}, name)
}

cObj = obj.(kclient.Object)

return cObj, c.Get(ctx, router.Key(alias.Spec.TargetNamespace, alias.Spec.TargetName), cObj)
}

func KeyFromScopeID(scope, id string) string {
return system.AliasPrefix + hash.String(name.SafeHashConcatName(id, scope))[:8]
}
Expand Down
Loading

0 comments on commit d05210b

Please sign in to comment.