Skip to content

Commit

Permalink
#67: Started to connect EmbedRouter into the system
Browse files Browse the repository at this point in the history
  • Loading branch information
roma-glushko committed Aug 12, 2024
1 parent d1659d3 commit e526611
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 6 deletions.
9 changes: 9 additions & 0 deletions pkg/api/schemas/embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package schemas

type EmbedRequest struct {
// TODO: implement
}

type EmbedResponse struct {
// TODO: implement
}
4 changes: 2 additions & 2 deletions pkg/router/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ func DefaultConfig() Config {

// RoutersConfig defines a config for a set of supported router types
type RoutersConfig struct {
LanguageRouters LangRoutersConfig `yaml:"language" validate:"required,dive"` // the list of language routers
// EmbeddingRouters []EmbeddingRouterConfig `yaml:"embedding" validate:"required,dive"`
LanguageRouters LangRoutersConfig `yaml:"language" validate:"required,dive"` // the list of language routers
EmbeddingRouters EmbedRoutersConfig `yaml:"embedding" validate:"required,dive"`
}
45 changes: 44 additions & 1 deletion pkg/router/embed_config.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,59 @@
package router

import (
"fmt"

"github.com/EinStack/glide/pkg/extmodel"
"github.com/EinStack/glide/pkg/provider"
"github.com/EinStack/glide/pkg/telemetry"
"go.uber.org/multierr"
"go.uber.org/zap"
)

type (
EmbedModelConfig = extmodel.Config[*provider.Config]
EmbedModelPoolConfig = []EmbedModelConfig
)

type EmbeddingRouterConfig struct {
type EmbedRouterConfig struct {
Config
Models EmbedModelPoolConfig `yaml:"models" json:"models" validate:"required,min=1,dive"` // the list of models that could handle requests
}

type EmbedRoutersConfig []EmbedRouterConfig

func (c EmbedRoutersConfig) Build(tel *telemetry.Telemetry) ([]*EmbedRouter, error) {
seenIDs := make(map[string]bool, len(c))
routers := make([]*EmbedRouter, 0, len(c))

var errs error

for idx, routerConfig := range c {
if _, ok := seenIDs[routerConfig.ID]; ok {
return nil, fmt.Errorf("ID \"%v\" is specified for more than one router while each ID should be unique", routerConfig.ID)
}

seenIDs[routerConfig.ID] = true

if !routerConfig.Enabled {
tel.L().Info(fmt.Sprintf("Embed router \"%v\" is disabled, skipping", routerConfig.ID))
continue
}

tel.L().Debug("Init router", zap.String("routerID", routerConfig.ID))

r, err := NewEmbedRouter(&c[idx], tel)
if err != nil {
errs = multierr.Append(errs, err)
continue
}

routers = append(routers, r)
}

if errs != nil {
return nil, errs
}

return routers, nil
}
19 changes: 16 additions & 3 deletions pkg/router/embed_router.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
package router

type EmbeddingRouter struct {
import (
"context"

"github.com/EinStack/glide/pkg/api/schemas"
"github.com/EinStack/glide/pkg/telemetry"
)

type EmbedRouter struct {
// routerID lang.RouterID
// Config *LangRouterConfig
// retry *retry.ExpRetry
// tel *telemetry.Telemetry
// logger *zap.Logger
}

//func (r *EmbeddingRouter) Embed(ctx context.Context, req *schemas.EmbedRequest) (*schemas.EmbedResponse, error) {
//}
func NewEmbedRouter(_ *EmbedRouterConfig, _ *telemetry.Telemetry) (*EmbedRouter, error) {
// TODO: implement
return &EmbedRouter{}, nil
}

func (r *EmbedRouter) Embed(ctx context.Context, req *schemas.EmbedRequest) (*schemas.EmbedResponse, error) {
// TODO: implement
}

Check failure on line 25 in pkg/router/embed_router.go

View workflow job for this annotation

GitHub Actions / Build

missing return

Check failure on line 25 in pkg/router/embed_router.go

View workflow job for this annotation

GitHub Actions / Vulnerability Check

missing return

Check failure on line 25 in pkg/router/embed_router.go

View workflow job for this annotation

GitHub Actions / Lint

missing return

Check failure on line 25 in pkg/router/embed_router.go

View workflow job for this annotation

GitHub Actions / Tests

missing return

0 comments on commit e526611

Please sign in to comment.