Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Ettore Di Giacinto <[email protected]>
  • Loading branch information
mudler committed Oct 13, 2024
1 parent 2660e07 commit 35b4053
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)

Check failure on line 112 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / tests-linux (1.21.x)

declared and not used: modelFile

Check failure on line 112 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / tests-linux (1.21.x)

declared and not used: input

Check failure on line 112 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / tests-linux (1.21.x)

other declaration of err

Check failure on line 112 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / build-macOS-arm64

declared and not used: modelFile

Check failure on line 112 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / build-macOS-arm64

declared and not used: input

Check failure on line 112 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / build-macOS-arm64

other declaration of err

Check failure on line 112 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / build-linux-arm

declared and not used: modelFile

Check failure on line 112 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / build-linux-arm

declared and not used: input

Check failure on line 112 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / build-linux-arm

other declaration of err

Check failure on line 112 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / build-macOS-x86_64

declared and not used: modelFile

Check failure on line 112 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / build-macOS-x86_64

declared and not used: input

Check failure on line 112 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / build-macOS-x86_64

other declaration of err

Check failure on line 112 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / build-linux

declared and not used: modelFile

Check failure on line 112 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / build-linux

declared and not used: input

Check failure on line 112 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / build-linux

other declaration of err
if err != nil {
return fmt.Errorf("failed reading parameters from request:%w", err)

Check failure on line 114 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / tests-linux (1.21.x)

too many return values

Check failure on line 114 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / build-macOS-arm64

too many return values

Check failure on line 114 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / build-linux-arm

too many return values

Check failure on line 114 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / build-macOS-x86_64

too many return values

Check failure on line 114 in core/http/endpoints/openai/realtime.go

View workflow job for this annotation

GitHub Actions / build-linux

too many return values
}

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)

Check failure on line 66 in core/http/endpoints/openai/request.go

View workflow job for this annotation

GitHub Actions / tests-linux (1.21.x)

cannot use c (variable of type *"github.com/gofiber/websocket/v2".Conn) as *fiber.Ctx value in argument to fiberContext.ModelFromContext

Check failure on line 66 in core/http/endpoints/openai/request.go

View workflow job for this annotation

GitHub Actions / build-macOS-arm64

cannot use c (variable of type *"github.com/gofiber/websocket/v2".Conn) as *fiber.Ctx value in argument to fiberContext.ModelFromContext

Check failure on line 66 in core/http/endpoints/openai/request.go

View workflow job for this annotation

GitHub Actions / build-linux-arm

cannot use c (variable of type *"github.com/gofiber/websocket/v2".Conn) as *fiber.Ctx value in argument to fiberContext.ModelFromContext

Check failure on line 66 in core/http/endpoints/openai/request.go

View workflow job for this annotation

GitHub Actions / build-macOS-x86_64

cannot use c (variable of type *"github.com/gofiber/websocket/v2".Conn) as *fiber.Ctx value in argument to fiberContext.ModelFromContext

Check failure on line 66 in core/http/endpoints/openai/request.go

View workflow job for this annotation

GitHub Actions / build-linux

cannot use c (variable of type *"github.com/gofiber/websocket/v2".Conn) as *fiber.Ctx value in argument to fiberContext.ModelFromContext

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 35b4053

Please sign in to comment.