Skip to content

Commit

Permalink
feat: add alias to models
Browse files Browse the repository at this point in the history
Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams committed Nov 20, 2024
1 parent a332ded commit f7bc187
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 11 deletions.
8 changes: 7 additions & 1 deletion apiclient/types/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@ package types
type Model struct {
Metadata
ModelManifest
ModelProviderStatus
ModelStatus
}

type ModelManifest struct {
Name string `json:"name,omitempty"`
TargetModel string `json:"targetModel,omitempty"`
ModelProvider string `json:"modelProvider,omitempty"`
Alias string `json:"alias,omitempty"`
Active bool `json:"active"`
Default bool `json:"default"`
Usage ModelUsage `json:"usage,omitempty"`
}

type ModelList List[Model]

type ModelStatus struct {
ModelProviderStatus
AliasAssigned bool `json:"aliasAssigned,omitempty"`
}

type ModelProviderStatus struct {
Configured bool `json:"configured"`
MissingEnvVars []string `json:"missingEnvVars,omitempty"`
Expand Down
18 changes: 17 additions & 1 deletion apiclient/types/zz_generated.deepcopy.go

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

9 changes: 6 additions & 3 deletions pkg/api/handlers/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,12 @@ func convertModel(ctx context.Context, c kclient.Client, model v1.Model) (types.
}

return types.Model{
Metadata: MetadataFrom(&model),
ModelManifest: model.Spec.Manifest,
ModelProviderStatus: *convertModelProviderToolRef(toolRef),
Metadata: MetadataFrom(&model),
ModelManifest: model.Spec.Manifest,
ModelStatus: types.ModelStatus{
ModelProviderStatus: *convertModelProviderToolRef(toolRef),
AliasAssigned: model.Status.AliasAssigned,
},
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/controller/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (c *Controller) setupRoutes() error {
// Reference
root.Type(&v1.Agent{}).HandlerFunc(alias.AssignAlias)
root.Type(&v1.Workflow{}).HandlerFunc(alias.AssignAlias)
root.Type(&v1.Model{}).HandlerFunc(alias.AssignAlias)

// Knowledge files
root.Type(&v1.KnowledgeFile{}).HandlerFunc(cleanup.Cleanup)
Expand Down
3 changes: 2 additions & 1 deletion pkg/gateway/server/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"sync"

"github.com/gptscript-ai/gptscript/pkg/engine"
"github.com/otto8-ai/otto8/pkg/alias"
"github.com/otto8-ai/otto8/pkg/invoke"
v1 "github.com/otto8-ai/otto8/pkg/storage/apis/otto.otto8.ai/v1"
"github.com/otto8-ai/otto8/pkg/system"
Expand Down Expand Up @@ -82,7 +83,7 @@ func (d *Dispatcher) TransformRequest(req *http.Request, namespace string) error

func (d *Dispatcher) getModelProviderForModel(ctx context.Context, namespace, model string) (*v1.Model, error) {
var m v1.Model
if err := d.client.Get(ctx, kclient.ObjectKey{Namespace: namespace, Name: model}, &m); err != nil {
if err := alias.Get(ctx, d.client, &m, namespace, model); err != nil {
return nil, err
}

Expand Down
16 changes: 15 additions & 1 deletion pkg/storage/apis/otto.otto8.ai/v1/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ type Model struct {
Status ModelStatus `json:"status,omitempty"`
}

func (m *Model) IsAssigned() bool {
return m.Status.AliasAssigned
}

func (m *Model) GetAliasName() string {
return m.Spec.Manifest.Alias
}

func (m *Model) SetAssigned(assigned bool) {
m.Status.AliasAssigned = assigned
}

func (m *Model) Has(field string) bool {
return m.Get(field) != ""
}
Expand All @@ -44,7 +56,9 @@ type ModelSpec struct {
Manifest types.ModelManifest `json:"manifest,omitempty"`
}

type ModelStatus struct{}
type ModelStatus struct {
AliasAssigned bool `json:"aliasAssigned,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down
56 changes: 52 additions & 4 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.

0 comments on commit f7bc187

Please sign in to comment.