Skip to content

Commit 22579bc

Browse files
committed
debug
1 parent 4491c88 commit 22579bc

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

core/http/app.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,26 @@ func App(cl *config.BackendConfigLoader, ml *model.ModelLoader, appConfig *confi
179179
Browse: true,
180180
}))
181181

182-
app.Use("/ws", func(c *fiber.Ctx) error {
183-
// IsWebSocketUpgrade returns true if the client
184-
// requested upgrade to the WebSocket protocol.
182+
app.Use(func(c *fiber.Ctx) error {
185183
if websocket.IsWebSocketUpgrade(c) {
186-
c.Locals("allowed", true)
187-
return c.Next()
184+
// Returns true if the client requested upgrade to the WebSocket protocol
185+
c.Next()
188186
}
189-
return fiber.ErrUpgradeRequired
187+
188+
return nil
190189
})
191190

191+
// app.Use("/v1/realtime", func(c *fiber.Ctx) error {
192+
// fmt.Println("Hit upgrade from http")
193+
// // IsWebSocketUpgrade returns true if the client
194+
// // requested upgrade to the WebSocket protocol.
195+
// if websocket.IsWebSocketUpgrade(c) {
196+
// c.Locals("allowed", true)
197+
// return c.Next()
198+
// }
199+
// return fiber.ErrUpgradeRequired
200+
// })
201+
192202
// Define a custom 404 handler
193203
// Note: keep this at the bottom!
194204
app.Use(notFoundHandler)

core/http/endpoints/openai/realtime.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,16 @@ var sessionLock sync.Mutex
106106

107107
func RegisterRealtime(cl *config.BackendConfigLoader, ml *model.ModelLoader, appConfig *config.ApplicationConfig) func(c *websocket.Conn) {
108108
return func(c *websocket.Conn) {
109+
110+
log.Debug().Msgf("WebSocket connection established with '%s'", c.RemoteAddr().String())
111+
109112
// Generate a unique session ID
110113
sessionID := generateSessionID()
111114

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-
}
115+
// modelFile, input, err := readWSRequest(c, cl, ml, appConfig, true)
116+
// if err != nil {
117+
// return fmt.Errorf("failed reading parameters from request:%w", err)
118+
// }
116119

117120
session := &Session{
118121
ID: sessionID,

core/http/endpoints/openai/request.go

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

88
"github.com/gofiber/fiber/v2"
9-
"github.com/gofiber/websocket/v2"
109
"github.com/google/uuid"
1110
"github.com/mudler/LocalAI/core/config"
1211
fiberContext "github.com/mudler/LocalAI/core/http/ctx"
@@ -49,24 +48,24 @@ func readRequest(c *fiber.Ctx, cl *config.BackendConfigLoader, ml *model.ModelLo
4948
return modelFile, input, err
5049
}
5150

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)
51+
// func readWSRequest(c *websocket.Conn, cl *config.BackendConfigLoader, ml *model.ModelLoader, o *config.ApplicationConfig, firstModel bool) (string, *schema.OpenAIRequest, error) {
52+
// input := new(schema.OpenAIRequest)
5453

55-
input.Model = c.Query("name")
54+
// input.Model = c.Query("name")
5655

57-
received, _ := json.Marshal(input)
56+
// received, _ := json.Marshal(input)
5857

59-
ctx, cancel := context.WithCancel(o.Context)
58+
// ctx, cancel := context.WithCancel(o.Context)
6059

61-
input.Context = ctx
62-
input.Cancel = cancel
60+
// input.Context = ctx
61+
// input.Cancel = cancel
6362

64-
log.Debug().Msgf("Request received: %s", string(received))
63+
// log.Debug().Msgf("Request received: %s", string(received))
6564

66-
modelFile, err := fiberContext.ModelFromContext(c, cl, ml, input.Model, firstModel)
65+
// modelFile, err := fiberContext.ModelFromContext(c, cl, ml, input.Model, firstModel)
6766

68-
return modelFile, input, err
69-
}
67+
// return modelFile, input, err
68+
// }
7069

7170
func updateRequestConfig(config *config.BackendConfig, input *schema.OpenAIRequest) {
7271
if input.Echo {

0 commit comments

Comments
 (0)