Skip to content

Commit

Permalink
Various improvements in server
Browse files Browse the repository at this point in the history
  • Loading branch information
synw committed Jan 18, 2025
1 parent 0049437 commit 03f55e5
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
3 changes: 3 additions & 0 deletions server/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func InitConf() types.Conf {
viper.AddConfigPath(".")
viper.SetDefault("origins", []string{"localhost"})
viper.SetDefault("cmd_api_key", nil)
viper.SetDefault("models", map[string]string{})
viper.SetDefault("features", []string{})
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
Expand All @@ -25,12 +26,14 @@ func InitConf() types.Conf {
or := viper.GetStringSlice("origins")
ak := viper.GetString("api_key")
cmdak := viper.GetString("cmd_api_key")
models := viper.GetStringMapString("models")
ft := viper.GetStringSlice("features")
return types.Conf{
Origins: or,
ApiKey: ak,
CmdApiKey: &cmdak,
Features: ft,
Models: models,
}
}

Expand Down
8 changes: 6 additions & 2 deletions server/httpserver/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ func ExecuteTaskHandler(c echo.Context) error {
}
return c.NoContent(http.StatusBadRequest)
}
ok, task, err := files.ReadTask(tp, state.ModelSize)
ms, ok := state.ModelsConf[taskName]
if !ok {
ms = "default"
}
ok, task, err := files.ReadTask(tp, ms)
if err != nil {
log.Println(err)
return c.NoContent(http.StatusInternalServerError)
Expand All @@ -66,7 +70,7 @@ func ExecuteTaskHandler(c echo.Context) error {
select {
case res, ok := <-ch:
if ok {
if state.IsVerbose {
if state.IsDebug {
fmt.Println("-------- result ----------")
for key, value := range res.Data {
fmt.Printf("%s: %v\n", key, value)
Expand Down
10 changes: 6 additions & 4 deletions server/lm/infer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,21 @@ func InferTask(
MsgType: types.ErrorMsgType,
}
}
if state.IsVerbose {
if state.IsDebug {
//fmt.Println("Inference params:")
//fmt.Println(params)
fmt.Println("---------- prompt ----------")
fmt.Println(finalPrompt)
fmt.Println("----------------------------")
fmt.Println("Thinking ..")
}
if state.IsVerbose {
fmt.Println("Ingesting prompt ..")
}
if state.IsDebug {
fmt.Println("Inference params:")
fmt.Printf("%+v\n\n", task.InferParams)
fmt.Printf("%+v\n", task.InferParams)
}
fmt.Println("Stop", stop)
//fmt.Println("Stop", stop)
for _, s := range stop {
st, ok := task.InferParams["stop"]
if st == nil || !ok {
Expand Down
4 changes: 2 additions & 2 deletions server/lm/ollama.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func ollamaInfer(
thinkingElapsed = time.Since(startThinking)
if state.IsVerbose {
fmt.Println("Thinking time:", thinkingElapsed)
fmt.Println("Emitting ..")
fmt.Println("Emitting ..\n")
}
smsg := types.StreamedMessage{
Num: ntokens,
Expand Down Expand Up @@ -99,7 +99,7 @@ func ollamaInfer(
// the inference was not aborted
emittingElapsed := time.Since(startEmitting)
if state.IsVerbose {
fmt.Println("Emitting time:", emittingElapsed)
fmt.Println("\n\nEmitting time:", emittingElapsed)
}
tpsRaw := float64(ntokens) / emittingElapsed.Seconds()
s := fmt.Sprintf("%.2f", tpsRaw)
Expand Down
2 changes: 1 addition & 1 deletion server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func main() {
}
state.IsVerbose = !*quiet
config := conf.InitConf()
err := state.Init(config.Features)
err := state.Init(config.Features, config.Models)
if err != nil {
log.Fatal("Error initializing state", err)
}
Expand Down
5 changes: 3 additions & 2 deletions server/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ var ContinueInferingController = true
var IsInfering = false

// models
var ModelSize = "xsmall"
var ModelsConf = make((map[string]string))

var Tasks = map[string]string{}

func Init(features []string) error {
func Init(features []string, models map[string]string) error {
ModelsConf = models
ts, err := files.InitTasks(features)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions server/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type Conf struct {
ApiKey string
CmdApiKey *string
Features []string
Models map[string]string
}

// ModelConf represents the configuration for a language model.
Expand Down

0 comments on commit 03f55e5

Please sign in to comment.