Skip to content

Commit 35b4053

Browse files
committed
WIP
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 2660e07 commit 35b4053

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Diff for: core/http/endpoints/openai/realtime.go

+6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ func RegisterRealtime(cl *config.BackendConfigLoader, ml *model.ModelLoader, app
108108
return func(c *websocket.Conn) {
109109
// Generate a unique session ID
110110
sessionID := generateSessionID()
111+
112+
modelFile, input, err := readWSRequest(c, cl, ml, appConfig, true)
113+
if err != nil {
114+
return fmt.Errorf("failed reading parameters from request:%w", err)
115+
}
116+
111117
session := &Session{
112118
ID: sessionID,
113119
Model: "gpt-4o", // default model

Diff for: core/http/endpoints/openai/request.go

+20
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77

88
"github.com/gofiber/fiber/v2"
9+
"github.com/gofiber/websocket/v2"
910
"github.com/google/uuid"
1011
"github.com/mudler/LocalAI/core/config"
1112
fiberContext "github.com/mudler/LocalAI/core/http/ctx"
@@ -48,6 +49,25 @@ func readRequest(c *fiber.Ctx, cl *config.BackendConfigLoader, ml *model.ModelLo
4849
return modelFile, input, err
4950
}
5051

52+
func readWSRequest(c *websocket.Conn, cl *config.BackendConfigLoader, ml *model.ModelLoader, o *config.ApplicationConfig, firstModel bool) (string, *schema.OpenAIRequest, error) {
53+
input := new(schema.OpenAIRequest)
54+
55+
input.Model = c.Query("name")
56+
57+
received, _ := json.Marshal(input)
58+
59+
ctx, cancel := context.WithCancel(o.Context)
60+
61+
input.Context = ctx
62+
input.Cancel = cancel
63+
64+
log.Debug().Msgf("Request received: %s", string(received))
65+
66+
modelFile, err := fiberContext.ModelFromContext(c, cl, ml, input.Model, firstModel)
67+
68+
return modelFile, input, err
69+
}
70+
5171
func updateRequestConfig(config *config.BackendConfig, input *schema.OpenAIRequest) {
5272
if input.Echo {
5373
config.Echo = input.Echo

0 commit comments

Comments
 (0)