MQTT Startup Refactoring Part 1: core/ packages part 1 (#1728)

This PR specifically introduces a `core` folder and moves the following packages over, without any other changes:

- `api/backend`
- `api/config`
- `api/options`
- `api/schema`

Once this is merged and we confirm there's no regressions, I can migrate over the remaining changes piece by piece to split up application startup, backend services, http, and mqtt as was the goal of the earlier PRs!
This commit is contained in:
Dave 2024-02-20 20:21:19 -05:00 committed by GitHub
parent 594eb468df
commit 255748bcba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
38 changed files with 93 additions and 90 deletions

View File

@ -5,10 +5,10 @@ import (
"fmt" "fmt"
"strings" "strings"
config "github.com/go-skynet/LocalAI/api/config" config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/pkg/grpc/proto" "github.com/go-skynet/LocalAI/pkg/grpc/proto"
"github.com/go-skynet/LocalAI/api/options" "github.com/go-skynet/LocalAI/core/options"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"

View File

@ -11,7 +11,7 @@ import (
json "github.com/json-iterator/go" json "github.com/json-iterator/go"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
config "github.com/go-skynet/LocalAI/api/config" config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/pkg/gallery" "github.com/go-skynet/LocalAI/pkg/gallery"
"github.com/go-skynet/LocalAI/pkg/utils" "github.com/go-skynet/LocalAI/pkg/utils"

View File

@ -1,12 +1,12 @@
package localai package localai
import ( import (
"github.com/go-skynet/LocalAI/api/backend"
config "github.com/go-skynet/LocalAI/api/config"
fiberContext "github.com/go-skynet/LocalAI/api/ctx" fiberContext "github.com/go-skynet/LocalAI/api/ctx"
"github.com/go-skynet/LocalAI/core/backend"
config "github.com/go-skynet/LocalAI/core/config"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/go-skynet/LocalAI/api/options" "github.com/go-skynet/LocalAI/core/options"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )

View File

@ -8,10 +8,10 @@ import (
"strings" "strings"
"time" "time"
"github.com/go-skynet/LocalAI/api/backend" "github.com/go-skynet/LocalAI/core/backend"
config "github.com/go-skynet/LocalAI/api/config" config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/api/options" "github.com/go-skynet/LocalAI/core/options"
"github.com/go-skynet/LocalAI/api/schema" "github.com/go-skynet/LocalAI/core/schema"
"github.com/go-skynet/LocalAI/pkg/grammar" "github.com/go-skynet/LocalAI/pkg/grammar"
model "github.com/go-skynet/LocalAI/pkg/model" model "github.com/go-skynet/LocalAI/pkg/model"
"github.com/go-skynet/LocalAI/pkg/utils" "github.com/go-skynet/LocalAI/pkg/utils"

View File

@ -8,10 +8,10 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/go-skynet/LocalAI/api/backend" "github.com/go-skynet/LocalAI/core/backend"
config "github.com/go-skynet/LocalAI/api/config" config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/api/options" "github.com/go-skynet/LocalAI/core/options"
"github.com/go-skynet/LocalAI/api/schema" "github.com/go-skynet/LocalAI/core/schema"
"github.com/go-skynet/LocalAI/pkg/grammar" "github.com/go-skynet/LocalAI/pkg/grammar"
model "github.com/go-skynet/LocalAI/pkg/model" model "github.com/go-skynet/LocalAI/pkg/model"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"

View File

@ -5,10 +5,10 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/go-skynet/LocalAI/api/backend" "github.com/go-skynet/LocalAI/core/backend"
config "github.com/go-skynet/LocalAI/api/config" config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/api/options" "github.com/go-skynet/LocalAI/core/options"
"github.com/go-skynet/LocalAI/api/schema" "github.com/go-skynet/LocalAI/core/schema"
model "github.com/go-skynet/LocalAI/pkg/model" model "github.com/go-skynet/LocalAI/pkg/model"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/google/uuid" "github.com/google/uuid"

View File

@ -5,12 +5,12 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/go-skynet/LocalAI/api/backend" "github.com/go-skynet/LocalAI/core/backend"
config "github.com/go-skynet/LocalAI/api/config" config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/api/schema" "github.com/go-skynet/LocalAI/core/schema"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/go-skynet/LocalAI/api/options" "github.com/go-skynet/LocalAI/core/options"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )

View File

@ -4,14 +4,15 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
config "github.com/go-skynet/LocalAI/api/config"
"github.com/go-skynet/LocalAI/api/options"
"github.com/go-skynet/LocalAI/pkg/utils"
"github.com/gofiber/fiber/v2"
"github.com/rs/zerolog/log"
"os" "os"
"path/filepath" "path/filepath"
"time" "time"
config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/core/options"
"github.com/go-skynet/LocalAI/pkg/utils"
"github.com/gofiber/fiber/v2"
"github.com/rs/zerolog/log"
) )
var uploadedFiles []File var uploadedFiles []File

View File

@ -3,11 +3,6 @@ package openai
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
config "github.com/go-skynet/LocalAI/api/config"
"github.com/go-skynet/LocalAI/api/options"
utils2 "github.com/go-skynet/LocalAI/pkg/utils"
"github.com/gofiber/fiber/v2"
"github.com/stretchr/testify/assert"
"io" "io"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
@ -16,6 +11,12 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/core/options"
utils2 "github.com/go-skynet/LocalAI/pkg/utils"
"github.com/gofiber/fiber/v2"
"github.com/stretchr/testify/assert"
"testing" "testing"
) )

View File

@ -13,12 +13,12 @@ import (
"strings" "strings"
"time" "time"
"github.com/go-skynet/LocalAI/api/schema" "github.com/go-skynet/LocalAI/core/schema"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/go-skynet/LocalAI/api/backend" "github.com/go-skynet/LocalAI/core/backend"
config "github.com/go-skynet/LocalAI/api/config" config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/api/options" "github.com/go-skynet/LocalAI/core/options"
model "github.com/go-skynet/LocalAI/pkg/model" model "github.com/go-skynet/LocalAI/pkg/model"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"

View File

@ -1,10 +1,10 @@
package openai package openai
import ( import (
"github.com/go-skynet/LocalAI/api/backend" "github.com/go-skynet/LocalAI/core/backend"
config "github.com/go-skynet/LocalAI/api/config" config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/api/options" "github.com/go-skynet/LocalAI/core/options"
"github.com/go-skynet/LocalAI/api/schema" "github.com/go-skynet/LocalAI/core/schema"
model "github.com/go-skynet/LocalAI/pkg/model" model "github.com/go-skynet/LocalAI/pkg/model"
) )

View File

@ -3,8 +3,8 @@ package openai
import ( import (
"regexp" "regexp"
config "github.com/go-skynet/LocalAI/api/config" config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/api/schema" "github.com/go-skynet/LocalAI/core/schema"
model "github.com/go-skynet/LocalAI/pkg/model" model "github.com/go-skynet/LocalAI/pkg/model"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )

View File

@ -9,10 +9,10 @@ import (
"net/http" "net/http"
"strings" "strings"
config "github.com/go-skynet/LocalAI/api/config"
fiberContext "github.com/go-skynet/LocalAI/api/ctx" fiberContext "github.com/go-skynet/LocalAI/api/ctx"
options "github.com/go-skynet/LocalAI/api/options" config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/api/schema" options "github.com/go-skynet/LocalAI/core/options"
"github.com/go-skynet/LocalAI/core/schema"
"github.com/go-skynet/LocalAI/pkg/grammar" "github.com/go-skynet/LocalAI/pkg/grammar"
model "github.com/go-skynet/LocalAI/pkg/model" model "github.com/go-skynet/LocalAI/pkg/model"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"

View File

@ -8,9 +8,9 @@ import (
"path" "path"
"path/filepath" "path/filepath"
"github.com/go-skynet/LocalAI/api/backend" "github.com/go-skynet/LocalAI/core/backend"
config "github.com/go-skynet/LocalAI/api/config" config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/api/options" "github.com/go-skynet/LocalAI/core/options"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"

View File

@ -8,7 +8,7 @@ import (
"github.com/ggerganov/whisper.cpp/bindings/go/pkg/whisper" "github.com/ggerganov/whisper.cpp/bindings/go/pkg/whisper"
"github.com/go-audio/wav" "github.com/go-audio/wav"
"github.com/go-skynet/LocalAI/api/schema" "github.com/go-skynet/LocalAI/core/schema"
) )
func sh(c string) (string, error) { func sh(c string) (string, error) {

View File

@ -4,7 +4,7 @@ package main
// It is meant to be used by the main executable that is the server for the specific backend type (falcon, gpt3, etc) // It is meant to be used by the main executable that is the server for the specific backend type (falcon, gpt3, etc)
import ( import (
"github.com/ggerganov/whisper.cpp/bindings/go/pkg/whisper" "github.com/ggerganov/whisper.cpp/bindings/go/pkg/whisper"
"github.com/go-skynet/LocalAI/api/schema" "github.com/go-skynet/LocalAI/core/schema"
"github.com/go-skynet/LocalAI/pkg/grpc/base" "github.com/go-skynet/LocalAI/pkg/grpc/base"
pb "github.com/go-skynet/LocalAI/pkg/grpc/proto" pb "github.com/go-skynet/LocalAI/pkg/grpc/proto"
) )

View File

@ -3,8 +3,8 @@ package backend
import ( import (
"fmt" "fmt"
config "github.com/go-skynet/LocalAI/api/config" config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/api/options" "github.com/go-skynet/LocalAI/core/options"
"github.com/go-skynet/LocalAI/pkg/grpc" "github.com/go-skynet/LocalAI/pkg/grpc"
model "github.com/go-skynet/LocalAI/pkg/model" model "github.com/go-skynet/LocalAI/pkg/model"
) )

View File

@ -1,8 +1,8 @@
package backend package backend
import ( import (
config "github.com/go-skynet/LocalAI/api/config" config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/api/options" "github.com/go-skynet/LocalAI/core/options"
"github.com/go-skynet/LocalAI/pkg/grpc/proto" "github.com/go-skynet/LocalAI/pkg/grpc/proto"
model "github.com/go-skynet/LocalAI/pkg/model" model "github.com/go-skynet/LocalAI/pkg/model"
) )

View File

@ -8,8 +8,8 @@ import (
"sync" "sync"
"unicode/utf8" "unicode/utf8"
config "github.com/go-skynet/LocalAI/api/config" config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/api/options" "github.com/go-skynet/LocalAI/core/options"
"github.com/go-skynet/LocalAI/pkg/gallery" "github.com/go-skynet/LocalAI/pkg/gallery"
"github.com/go-skynet/LocalAI/pkg/grpc" "github.com/go-skynet/LocalAI/pkg/grpc"
model "github.com/go-skynet/LocalAI/pkg/model" model "github.com/go-skynet/LocalAI/pkg/model"

View File

@ -7,8 +7,8 @@ import (
pb "github.com/go-skynet/LocalAI/pkg/grpc/proto" pb "github.com/go-skynet/LocalAI/pkg/grpc/proto"
model "github.com/go-skynet/LocalAI/pkg/model" model "github.com/go-skynet/LocalAI/pkg/model"
config "github.com/go-skynet/LocalAI/api/config" config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/api/options" "github.com/go-skynet/LocalAI/core/options"
) )
func modelOpts(c config.Config, o *options.Option, opts []model.Option) []model.Option { func modelOpts(c config.Config, o *options.Option, opts []model.Option) []model.Option {

View File

@ -4,10 +4,10 @@ import (
"context" "context"
"fmt" "fmt"
config "github.com/go-skynet/LocalAI/api/config" config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/api/schema" "github.com/go-skynet/LocalAI/core/schema"
"github.com/go-skynet/LocalAI/api/options" "github.com/go-skynet/LocalAI/core/options"
"github.com/go-skynet/LocalAI/pkg/grpc/proto" "github.com/go-skynet/LocalAI/pkg/grpc/proto"
model "github.com/go-skynet/LocalAI/pkg/model" model "github.com/go-skynet/LocalAI/pkg/model"
) )

View File

@ -6,9 +6,8 @@ import (
"os" "os"
"path/filepath" "path/filepath"
api_config "github.com/go-skynet/LocalAI/api/config" config "github.com/go-skynet/LocalAI/core/config"
config "github.com/go-skynet/LocalAI/api/config" "github.com/go-skynet/LocalAI/core/options"
"github.com/go-skynet/LocalAI/api/options"
"github.com/go-skynet/LocalAI/pkg/grpc/proto" "github.com/go-skynet/LocalAI/pkg/grpc/proto"
model "github.com/go-skynet/LocalAI/pkg/model" model "github.com/go-skynet/LocalAI/pkg/model"
"github.com/go-skynet/LocalAI/pkg/utils" "github.com/go-skynet/LocalAI/pkg/utils"
@ -38,7 +37,7 @@ func ModelTTS(backend, text, modelFile string, loader *model.ModelLoader, o *opt
grpcOpts := gRPCModelOpts(c) grpcOpts := gRPCModelOpts(c)
opts := modelOpts(api_config.Config{}, o, []model.Option{ opts := modelOpts(config.Config{}, o, []model.Option{
model.WithBackendString(bb), model.WithBackendString(bb),
model.WithModel(modelFile), model.WithModel(modelFile),
model.WithContext(o.Context), model.WithContext(o.Context),

View File

@ -1,4 +1,4 @@
package api_config package config
import ( import (
"errors" "errors"

View File

@ -1,10 +1,10 @@
package api_config_test package config_test
import ( import (
"os" "os"
. "github.com/go-skynet/LocalAI/api/config" . "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/api/options" "github.com/go-skynet/LocalAI/core/options"
"github.com/go-skynet/LocalAI/pkg/model" "github.com/go-skynet/LocalAI/pkg/model"
. "github.com/onsi/ginkgo/v2" . "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"

View File

@ -1,4 +1,4 @@
package api_config package config
type PredictionOptions struct { type PredictionOptions struct {

View File

@ -1,4 +1,4 @@
package api package http
import ( import (
"encoding/json" "encoding/json"
@ -7,11 +7,11 @@ import (
"os" "os"
"strings" "strings"
config "github.com/go-skynet/LocalAI/api/config"
"github.com/go-skynet/LocalAI/api/localai" "github.com/go-skynet/LocalAI/api/localai"
"github.com/go-skynet/LocalAI/api/openai" "github.com/go-skynet/LocalAI/api/openai"
"github.com/go-skynet/LocalAI/api/options" config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/api/schema" "github.com/go-skynet/LocalAI/core/options"
"github.com/go-skynet/LocalAI/core/schema"
"github.com/go-skynet/LocalAI/internal" "github.com/go-skynet/LocalAI/internal"
"github.com/go-skynet/LocalAI/metrics" "github.com/go-skynet/LocalAI/metrics"
"github.com/go-skynet/LocalAI/pkg/assets" "github.com/go-skynet/LocalAI/pkg/assets"

View File

@ -1,4 +1,4 @@
package api_test package http_test
import ( import (
"bytes" "bytes"
@ -13,8 +13,8 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
. "github.com/go-skynet/LocalAI/api" . "github.com/go-skynet/LocalAI/core/http"
"github.com/go-skynet/LocalAI/api/options" "github.com/go-skynet/LocalAI/core/options"
"github.com/go-skynet/LocalAI/metrics" "github.com/go-skynet/LocalAI/metrics"
"github.com/go-skynet/LocalAI/pkg/downloader" "github.com/go-skynet/LocalAI/pkg/downloader"
"github.com/go-skynet/LocalAI/pkg/gallery" "github.com/go-skynet/LocalAI/pkg/gallery"

View File

@ -1,4 +1,4 @@
package api_test package http_test
import ( import (
"testing" "testing"

View File

@ -3,7 +3,7 @@ package schema
import ( import (
"context" "context"
config "github.com/go-skynet/LocalAI/api/config" config "github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/pkg/grammar" "github.com/go-skynet/LocalAI/pkg/grammar"
) )

View File

@ -12,10 +12,10 @@ import (
"syscall" "syscall"
"time" "time"
api "github.com/go-skynet/LocalAI/api" "github.com/go-skynet/LocalAI/core/backend"
"github.com/go-skynet/LocalAI/api/backend" config "github.com/go-skynet/LocalAI/core/config"
config "github.com/go-skynet/LocalAI/api/config" api "github.com/go-skynet/LocalAI/core/http"
"github.com/go-skynet/LocalAI/api/options" "github.com/go-skynet/LocalAI/core/options"
"github.com/go-skynet/LocalAI/internal" "github.com/go-skynet/LocalAI/internal"
"github.com/go-skynet/LocalAI/metrics" "github.com/go-skynet/LocalAI/metrics"
"github.com/go-skynet/LocalAI/pkg/gallery" "github.com/go-skynet/LocalAI/pkg/gallery"

View File

@ -2,7 +2,8 @@ package grpc
import ( import (
"context" "context"
"github.com/go-skynet/LocalAI/api/schema"
"github.com/go-skynet/LocalAI/core/schema"
pb "github.com/go-skynet/LocalAI/pkg/grpc/proto" pb "github.com/go-skynet/LocalAI/pkg/grpc/proto"
"google.golang.org/grpc" "google.golang.org/grpc"
) )

View File

@ -6,7 +6,7 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/go-skynet/LocalAI/api/schema" "github.com/go-skynet/LocalAI/core/schema"
pb "github.com/go-skynet/LocalAI/pkg/grpc/proto" pb "github.com/go-skynet/LocalAI/pkg/grpc/proto"
gopsutil "github.com/shirou/gopsutil/v3/process" gopsutil "github.com/shirou/gopsutil/v3/process"
) )

View File

@ -7,7 +7,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/go-skynet/LocalAI/api/schema" "github.com/go-skynet/LocalAI/core/schema"
pb "github.com/go-skynet/LocalAI/pkg/grpc/proto" pb "github.com/go-skynet/LocalAI/pkg/grpc/proto"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/credentials/insecure"

View File

@ -2,11 +2,12 @@ package grpc
import ( import (
"context" "context"
"github.com/go-skynet/LocalAI/api/schema" "time"
"github.com/go-skynet/LocalAI/core/schema"
pb "github.com/go-skynet/LocalAI/pkg/grpc/proto" pb "github.com/go-skynet/LocalAI/pkg/grpc/proto"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/metadata" "google.golang.org/grpc/metadata"
"time"
) )
var _ Backend = new(embedBackend) var _ Backend = new(embedBackend)

View File

@ -1,7 +1,7 @@
package grpc package grpc
import ( import (
"github.com/go-skynet/LocalAI/api/schema" "github.com/go-skynet/LocalAI/core/schema"
pb "github.com/go-skynet/LocalAI/pkg/grpc/proto" pb "github.com/go-skynet/LocalAI/pkg/grpc/proto"
) )

View File

@ -3,7 +3,7 @@ package integration_test
import ( import (
"reflect" "reflect"
config "github.com/go-skynet/LocalAI/api/config" config "github.com/go-skynet/LocalAI/core/config"
model "github.com/go-skynet/LocalAI/pkg/model" model "github.com/go-skynet/LocalAI/pkg/model"
. "github.com/onsi/ginkgo/v2" . "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"