@@ -19,7 +19,6 @@ package main
1919import (
2020 "context"
2121 "errors"
22- "fmt"
2322 "net/http"
2423 "os"
2524 "os/signal"
@@ -34,8 +33,8 @@ import (
3433 "github.com/llm-d/llm-d-router/pkg/coordinator/config"
3534 "github.com/llm-d/llm-d-router/pkg/coordinator/gateway"
3635 "github.com/llm-d/llm-d-router/pkg/coordinator/pipeline"
36+ "github.com/llm-d/llm-d-router/pkg/coordinator/pipeline/builder"
3737 "github.com/llm-d/llm-d-router/pkg/coordinator/server"
38- "github.com/llm-d/llm-d-router/pkg/coordinator/steps"
3938)
4039
4140func main () {
@@ -82,7 +81,7 @@ func main() {
8281
8382 gwClient := gateway .New (cfg .Gateway )
8483
85- steps , err := buildPipeline (cfg , gwClient )
84+ steps , err := builder . Build (cfg , gwClient )
8685 if err != nil {
8786 log .Error (err , "failed to build pipeline" )
8887 os .Exit (1 )
@@ -128,53 +127,3 @@ func serveUntilSignal(srv *server.Server, shutdownTimeout time.Duration) error {
128127 }
129128 return nil
130129}
131-
132- // validatePipeline rejects configurations that cannot work before any step runs.
133- // The tokens-in format (use_openai_format=false) sends token IDs that only the
134- // render step produces, so it requires a render step in the pipeline.
135- func validatePipeline (p config.PipelineConfig ) error {
136- if p .UseOpenAIFormat {
137- return nil
138- }
139- for _ , s := range p .Steps {
140- if s .Type == steps .RenderStepName {
141- return nil
142- }
143- }
144- return fmt .Errorf ("pipeline.use_openai_format=false requires a %q step (the tokens-in format sends token IDs that render produces)" , steps .RenderStepName )
145- }
146-
147- func mergeConnectorDefaults (params map [string ]any , kvConnector , ecConnector string ) map [string ]any {
148- out := make (map [string ]any , len (params ))
149- for k , v := range params {
150- out [k ] = v
151- }
152- if _ , ok := out [steps .ParamKVConnector ]; ! ok && kvConnector != "" {
153- out [steps .ParamKVConnector ] = kvConnector
154- }
155- if _ , ok := out [steps .ParamECConnector ]; ! ok && ecConnector != "" {
156- out [steps .ParamECConnector ] = ecConnector
157- }
158- return out
159- }
160-
161- func buildPipeline (cfg * config.Config , gwClient * gateway.Client ) ([]pipeline.Step , error ) {
162- if err := validatePipeline (cfg .Pipeline ); err != nil {
163- return nil , err
164- }
165-
166- var steps []pipeline.Step
167- for _ , stepCfg := range cfg .Pipeline .Steps {
168- params := mergeConnectorDefaults (stepCfg .Params , cfg .Pipeline .KVConnector , cfg .Pipeline .ECConnector )
169- if _ , ok := params ["use_openai_format" ]; ! ok {
170- params ["use_openai_format" ] = cfg .Pipeline .UseOpenAIFormat
171- }
172- step , err := pipeline .Build (stepCfg .Type , gwClient , params )
173- if err != nil {
174- return nil , err
175- }
176-
177- steps = append (steps , step )
178- }
179- return steps , nil
180- }
0 commit comments