Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
  • Loading branch information
mudler committed Oct 18, 2024
1 parent 066e041 commit 4491c88
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/http/endpoints/openai/realtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ func RegisterRealtime(cl *config.BackendConfigLoader, ml *model.ModelLoader, app
return func(c *websocket.Conn) {
// Generate a unique session ID
sessionID := generateSessionID()

modelFile, input, err := readWSRequest(c, cl, ml, appConfig, true)
if err != nil {
return fmt.Errorf("failed reading parameters from request:%w", err)
}

session := &Session{
ID: sessionID,
Model: "gpt-4o", // default model
Expand Down
20 changes: 20 additions & 0 deletions core/http/endpoints/openai/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"

"github.com/gofiber/fiber/v2"
"github.com/gofiber/websocket/v2"
"github.com/google/uuid"
"github.com/mudler/LocalAI/core/config"
fiberContext "github.com/mudler/LocalAI/core/http/ctx"
Expand Down Expand Up @@ -48,6 +49,25 @@ func readRequest(c *fiber.Ctx, cl *config.BackendConfigLoader, ml *model.ModelLo
return modelFile, input, err
}

func readWSRequest(c *websocket.Conn, cl *config.BackendConfigLoader, ml *model.ModelLoader, o *config.ApplicationConfig, firstModel bool) (string, *schema.OpenAIRequest, error) {
input := new(schema.OpenAIRequest)

input.Model = c.Query("name")

received, _ := json.Marshal(input)

ctx, cancel := context.WithCancel(o.Context)

input.Context = ctx
input.Cancel = cancel

log.Debug().Msgf("Request received: %s", string(received))

modelFile, err := fiberContext.ModelFromContext(c, cl, ml, input.Model, firstModel)

return modelFile, input, err
}

func updateRequestConfig(config *config.BackendConfig, input *schema.OpenAIRequest) {
if input.Echo {
config.Echo = input.Echo
Expand Down

0 comments on commit 4491c88

Please sign in to comment.