From b3c2a3c25793da020c1a7504766f2598fc44a022 Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 24 Jul 2025 09:03:41 -0400 Subject: [PATCH] fix: untangle pkg and core (#5896) * migrate core/system to pkg/system - it has no dependencies FROM core, and IS USED in pkg Signed-off-by: Dave Lee * move pkg/templates up to core/templates -- nothing in pkg references it, but it does reference core. Signed-off-by: Dave Lee * remove extra check, len of nil is 0 Signed-off-by: Dave Lee * move pkg/startup to core/startup -- it does have important and unfixable dependencies on core Signed-off-by: Dave Lee --------- Signed-off-by: Dave Lee --- core/application/application.go | 2 +- core/application/startup.go | 6 ++-- core/cli/backends.go | 2 +- core/cli/models.go | 2 +- core/cli/util.go | 2 +- core/gallery/backend_types.go | 2 +- core/gallery/backends.go | 2 +- core/gallery/backends_test.go | 2 +- core/gallery/models.go | 2 +- core/http/endpoints/openai/chat.go | 4 +-- core/http/endpoints/openai/completion.go | 2 +- core/http/endpoints/openai/edit.go | 2 +- core/http/endpoints/openai/realtime.go | 30 +++++++++---------- core/http/middleware/request.go | 2 +- core/services/backends.go | 2 +- core/services/gallery.go | 2 +- core/services/models.go | 2 +- {pkg => core}/startup/backend_preload.go | 2 +- {pkg => core}/startup/model_preload.go | 2 +- {pkg => core}/startup/model_preload_test.go | 2 +- {pkg => core}/startup/startup_suite_test.go | 0 {pkg => core}/templates/cache.go | 0 {pkg => core}/templates/evaluator.go | 0 {pkg => core}/templates/evaluator_test.go | 2 +- {pkg => core}/templates/multimodal.go | 0 {pkg => core}/templates/multimodal_test.go | 2 +- .../templates/templates_suite_test.go | 0 {core => pkg}/system/capabilities.go | 0 28 files changed, 39 insertions(+), 39 deletions(-) rename {pkg => core}/startup/backend_preload.go (97%) rename {pkg => core}/startup/model_preload.go (99%) rename {pkg => core}/startup/model_preload_test.go (96%) rename {pkg => core}/startup/startup_suite_test.go (100%) rename {pkg => core}/templates/cache.go (100%) rename {pkg => core}/templates/evaluator.go (100%) rename {pkg => core}/templates/evaluator_test.go (99%) rename {pkg => core}/templates/multimodal.go (100%) rename {pkg => core}/templates/multimodal_test.go (97%) rename {pkg => core}/templates/templates_suite_test.go (100%) rename {core => pkg}/system/capabilities.go (100%) diff --git a/core/application/application.go b/core/application/application.go index 8c9842d94..a99086601 100644 --- a/core/application/application.go +++ b/core/application/application.go @@ -2,8 +2,8 @@ package application import ( "github.com/mudler/LocalAI/core/config" + "github.com/mudler/LocalAI/core/templates" "github.com/mudler/LocalAI/pkg/model" - "github.com/mudler/LocalAI/pkg/templates" ) type Application struct { diff --git a/core/application/startup.go b/core/application/startup.go index 59003799b..983807bb2 100644 --- a/core/application/startup.go +++ b/core/application/startup.go @@ -10,8 +10,8 @@ import ( "github.com/mudler/LocalAI/core/services" "github.com/mudler/LocalAI/internal" + coreStartup "github.com/mudler/LocalAI/core/startup" "github.com/mudler/LocalAI/pkg/model" - pkgStartup "github.com/mudler/LocalAI/pkg/startup" "github.com/mudler/LocalAI/pkg/xsysinfo" "github.com/rs/zerolog/log" ) @@ -55,11 +55,11 @@ func New(opts ...config.AppOption) (*Application, error) { } } - if err := pkgStartup.InstallModels(options.Galleries, options.BackendGalleries, options.ModelPath, options.BackendsPath, options.EnforcePredownloadScans, options.AutoloadBackendGalleries, nil, options.ModelsURL...); err != nil { + if err := coreStartup.InstallModels(options.Galleries, options.BackendGalleries, options.ModelPath, options.BackendsPath, options.EnforcePredownloadScans, options.AutoloadBackendGalleries, nil, options.ModelsURL...); err != nil { log.Error().Err(err).Msg("error installing models") } - if err := pkgStartup.InstallExternalBackends(options.BackendGalleries, options.BackendsPath, nil, options.ExternalBackends...); err != nil { + if err := coreStartup.InstallExternalBackends(options.BackendGalleries, options.BackendsPath, nil, options.ExternalBackends...); err != nil { log.Error().Err(err).Msg("error installing external backends") } diff --git a/core/cli/backends.go b/core/cli/backends.go index 480d68901..d5fa84878 100644 --- a/core/cli/backends.go +++ b/core/cli/backends.go @@ -8,7 +8,7 @@ import ( "github.com/mudler/LocalAI/core/config" "github.com/mudler/LocalAI/core/gallery" - "github.com/mudler/LocalAI/pkg/startup" + "github.com/mudler/LocalAI/core/startup" "github.com/rs/zerolog/log" "github.com/schollz/progressbar/v3" ) diff --git a/core/cli/models.go b/core/cli/models.go index 94a838961..1dc018572 100644 --- a/core/cli/models.go +++ b/core/cli/models.go @@ -9,8 +9,8 @@ import ( "github.com/mudler/LocalAI/core/config" "github.com/mudler/LocalAI/core/gallery" + "github.com/mudler/LocalAI/core/startup" "github.com/mudler/LocalAI/pkg/downloader" - "github.com/mudler/LocalAI/pkg/startup" "github.com/rs/zerolog/log" "github.com/schollz/progressbar/v3" ) diff --git a/core/cli/util.go b/core/cli/util.go index a13a11590..4e01ea2c2 100644 --- a/core/cli/util.go +++ b/core/cli/util.go @@ -72,7 +72,7 @@ func (u *CreateOCIImageCMD) Run(ctx *cliContext.Context) error { } func (u *GGUFInfoCMD) Run(ctx *cliContext.Context) error { - if u.Args == nil || len(u.Args) == 0 { + if len(u.Args) == 0 { return fmt.Errorf("no GGUF file provided") } // We try to guess only if we don't have a template defined already diff --git a/core/gallery/backend_types.go b/core/gallery/backend_types.go index e45b8c7c3..439355a46 100644 --- a/core/gallery/backend_types.go +++ b/core/gallery/backend_types.go @@ -2,7 +2,7 @@ package gallery import ( "github.com/mudler/LocalAI/core/config" - "github.com/mudler/LocalAI/core/system" + "github.com/mudler/LocalAI/pkg/system" ) // BackendMetadata represents the metadata stored in a JSON file for each installed backend diff --git a/core/gallery/backends.go b/core/gallery/backends.go index e696072ed..1f26c56e0 100644 --- a/core/gallery/backends.go +++ b/core/gallery/backends.go @@ -8,9 +8,9 @@ import ( "time" "github.com/mudler/LocalAI/core/config" - "github.com/mudler/LocalAI/core/system" "github.com/mudler/LocalAI/pkg/downloader" "github.com/mudler/LocalAI/pkg/model" + "github.com/mudler/LocalAI/pkg/system" "github.com/rs/zerolog/log" ) diff --git a/core/gallery/backends_test.go b/core/gallery/backends_test.go index 3e4df40f7..460677706 100644 --- a/core/gallery/backends_test.go +++ b/core/gallery/backends_test.go @@ -7,7 +7,7 @@ import ( "runtime" "github.com/mudler/LocalAI/core/config" - "github.com/mudler/LocalAI/core/system" + "github.com/mudler/LocalAI/pkg/system" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "gopkg.in/yaml.v2" diff --git a/core/gallery/models.go b/core/gallery/models.go index 30ec2908e..54afbfdfd 100644 --- a/core/gallery/models.go +++ b/core/gallery/models.go @@ -10,8 +10,8 @@ import ( "dario.cat/mergo" "github.com/mudler/LocalAI/core/config" lconfig "github.com/mudler/LocalAI/core/config" - "github.com/mudler/LocalAI/core/system" "github.com/mudler/LocalAI/pkg/downloader" + "github.com/mudler/LocalAI/pkg/system" "github.com/mudler/LocalAI/pkg/utils" "github.com/rs/zerolog/log" diff --git a/core/http/endpoints/openai/chat.go b/core/http/endpoints/openai/chat.go index 1e33c977b..f43254c15 100644 --- a/core/http/endpoints/openai/chat.go +++ b/core/http/endpoints/openai/chat.go @@ -15,8 +15,8 @@ import ( "github.com/mudler/LocalAI/core/schema" "github.com/mudler/LocalAI/pkg/functions" + "github.com/mudler/LocalAI/core/templates" "github.com/mudler/LocalAI/pkg/model" - "github.com/mudler/LocalAI/pkg/templates" "github.com/rs/zerolog/log" "github.com/valyala/fasthttp" @@ -175,7 +175,7 @@ func ChatEndpoint(cl *config.BackendConfigLoader, ml *model.ModelLoader, evaluat textContentToReturn = "" id = uuid.New().String() created = int(time.Now().Unix()) - + input, ok := c.Locals(middleware.CONTEXT_LOCALS_KEY_LOCALAI_REQUEST).(*schema.OpenAIRequest) if !ok || input.Model == "" { return fiber.ErrBadRequest diff --git a/core/http/endpoints/openai/completion.go b/core/http/endpoints/openai/completion.go index 9620d2c12..7dec8ca7e 100644 --- a/core/http/endpoints/openai/completion.go +++ b/core/http/endpoints/openai/completion.go @@ -15,9 +15,9 @@ import ( "github.com/gofiber/fiber/v2" "github.com/google/uuid" "github.com/mudler/LocalAI/core/schema" + "github.com/mudler/LocalAI/core/templates" "github.com/mudler/LocalAI/pkg/functions" "github.com/mudler/LocalAI/pkg/model" - "github.com/mudler/LocalAI/pkg/templates" "github.com/rs/zerolog/log" "github.com/valyala/fasthttp" ) diff --git a/core/http/endpoints/openai/edit.go b/core/http/endpoints/openai/edit.go index c4cb5e19c..5b29b1c9c 100644 --- a/core/http/endpoints/openai/edit.go +++ b/core/http/endpoints/openai/edit.go @@ -12,8 +12,8 @@ import ( "github.com/google/uuid" "github.com/mudler/LocalAI/core/schema" + "github.com/mudler/LocalAI/core/templates" "github.com/mudler/LocalAI/pkg/model" - "github.com/mudler/LocalAI/pkg/templates" "github.com/rs/zerolog/log" ) diff --git a/core/http/endpoints/openai/realtime.go b/core/http/endpoints/openai/realtime.go index b3e756bd8..4c4adef6f 100644 --- a/core/http/endpoints/openai/realtime.go +++ b/core/http/endpoints/openai/realtime.go @@ -16,12 +16,12 @@ import ( "github.com/mudler/LocalAI/core/application" "github.com/mudler/LocalAI/core/config" "github.com/mudler/LocalAI/core/http/endpoints/openai/types" + "github.com/mudler/LocalAI/core/templates" laudio "github.com/mudler/LocalAI/pkg/audio" "github.com/mudler/LocalAI/pkg/functions" "github.com/mudler/LocalAI/pkg/grpc/proto" model "github.com/mudler/LocalAI/pkg/model" "github.com/mudler/LocalAI/pkg/sound" - "github.com/mudler/LocalAI/pkg/templates" "google.golang.org/grpc" @@ -29,8 +29,8 @@ import ( ) const ( - localSampleRate = 16000 - remoteSampleRate = 24000 + localSampleRate = 16000 + remoteSampleRate = 24000 ) // A model can be "emulated" that is: transcribe audio to text -> feed text to the LLM -> generate audio as result @@ -210,9 +210,9 @@ func registerRealtime(application *application.Application) func(c *websocket.Co // TODO: Need some way to pass this to the backend Threshold: 0.5, // TODO: This is ignored and the amount of padding is random at present - PrefixPaddingMs: 30, + PrefixPaddingMs: 30, SilenceDurationMs: 500, - CreateResponse: func() *bool { t := true; return &t }(), + CreateResponse: func() *bool { t := true; return &t }(), }, }, InputAudioTranscription: &types.InputAudioTranscription{ @@ -233,7 +233,7 @@ func registerRealtime(application *application.Application) func(c *websocket.Co // TODO: The API has no way to configure the VAD model or other models that make up a pipeline to fake any-to-any // So possibly we could have a way to configure a composite model that can be used in situations where any-to-any is expected pipeline := config.Pipeline{ - VAD: "silero-vad", + VAD: "silero-vad", Transcription: session.InputAudioTranscription.Model, } @@ -567,8 +567,8 @@ func updateTransSession(session *Session, update *types.ClientSession, cl *confi trCur := session.InputAudioTranscription if trUpd != nil && trUpd.Model != "" && trUpd.Model != trCur.Model { - pipeline := config.Pipeline { - VAD: "silero-vad", + pipeline := config.Pipeline{ + VAD: "silero-vad", Transcription: trUpd.Model, } @@ -684,7 +684,7 @@ func handleVAD(cfg *config.BackendConfig, evaluator *templates.Evaluator, sessio sendEvent(c, types.InputAudioBufferClearedEvent{ ServerEventBase: types.ServerEventBase{ EventID: "event_TODO", - Type: types.ServerEventTypeInputAudioBufferCleared, + Type: types.ServerEventTypeInputAudioBufferCleared, }, }) @@ -697,7 +697,7 @@ func handleVAD(cfg *config.BackendConfig, evaluator *templates.Evaluator, sessio sendEvent(c, types.InputAudioBufferSpeechStartedEvent{ ServerEventBase: types.ServerEventBase{ EventID: "event_TODO", - Type: types.ServerEventTypeInputAudioBufferSpeechStarted, + Type: types.ServerEventTypeInputAudioBufferSpeechStarted, }, AudioStartMs: time.Now().Sub(startTime).Milliseconds(), }) @@ -719,7 +719,7 @@ func handleVAD(cfg *config.BackendConfig, evaluator *templates.Evaluator, sessio sendEvent(c, types.InputAudioBufferSpeechStoppedEvent{ ServerEventBase: types.ServerEventBase{ EventID: "event_TODO", - Type: types.ServerEventTypeInputAudioBufferSpeechStopped, + Type: types.ServerEventTypeInputAudioBufferSpeechStopped, }, AudioEndMs: time.Now().Sub(startTime).Milliseconds(), }) @@ -728,9 +728,9 @@ func handleVAD(cfg *config.BackendConfig, evaluator *templates.Evaluator, sessio sendEvent(c, types.InputAudioBufferCommittedEvent{ ServerEventBase: types.ServerEventBase{ EventID: "event_TODO", - Type: types.ServerEventTypeInputAudioBufferCommitted, + Type: types.ServerEventTypeInputAudioBufferCommitted, }, - ItemID: generateItemID(), + ItemID: generateItemID(), PreviousItemID: "TODO", }) @@ -833,9 +833,9 @@ func commitUtterance(ctx context.Context, utt []byte, cfg *config.BackendConfig, func runVAD(ctx context.Context, session *Session, adata []int16) ([]*proto.VADSegment, error) { soundIntBuffer := &audio.IntBuffer{ - Format: &audio.Format{SampleRate: localSampleRate, NumChannels: 1}, + Format: &audio.Format{SampleRate: localSampleRate, NumChannels: 1}, SourceBitDepth: 16, - Data: sound.ConvertInt16ToInt(adata), + Data: sound.ConvertInt16ToInt(adata), } float32Data := soundIntBuffer.AsFloat32Buffer().Data diff --git a/core/http/middleware/request.go b/core/http/middleware/request.go index 3a9177f51..dccf55a0c 100644 --- a/core/http/middleware/request.go +++ b/core/http/middleware/request.go @@ -11,9 +11,9 @@ import ( "github.com/mudler/LocalAI/core/config" "github.com/mudler/LocalAI/core/schema" "github.com/mudler/LocalAI/core/services" + "github.com/mudler/LocalAI/core/templates" "github.com/mudler/LocalAI/pkg/functions" "github.com/mudler/LocalAI/pkg/model" - "github.com/mudler/LocalAI/pkg/templates" "github.com/mudler/LocalAI/pkg/utils" "github.com/gofiber/fiber/v2" diff --git a/core/services/backends.go b/core/services/backends.go index 855d1c0ad..fe6446b55 100644 --- a/core/services/backends.go +++ b/core/services/backends.go @@ -2,7 +2,7 @@ package services import ( "github.com/mudler/LocalAI/core/gallery" - "github.com/mudler/LocalAI/core/system" + "github.com/mudler/LocalAI/pkg/system" "github.com/mudler/LocalAI/pkg/utils" "github.com/rs/zerolog/log" diff --git a/core/services/gallery.go b/core/services/gallery.go index b8306b30e..cace4c152 100644 --- a/core/services/gallery.go +++ b/core/services/gallery.go @@ -7,8 +7,8 @@ import ( "github.com/mudler/LocalAI/core/config" "github.com/mudler/LocalAI/core/gallery" - "github.com/mudler/LocalAI/core/system" "github.com/mudler/LocalAI/pkg/model" + "github.com/mudler/LocalAI/pkg/system" "github.com/rs/zerolog/log" ) diff --git a/core/services/models.go b/core/services/models.go index beb981c8e..98b2ddc8d 100644 --- a/core/services/models.go +++ b/core/services/models.go @@ -7,7 +7,7 @@ import ( "github.com/mudler/LocalAI/core/config" "github.com/mudler/LocalAI/core/gallery" - "github.com/mudler/LocalAI/core/system" + "github.com/mudler/LocalAI/pkg/system" "github.com/mudler/LocalAI/pkg/utils" "gopkg.in/yaml.v2" ) diff --git a/pkg/startup/backend_preload.go b/core/startup/backend_preload.go similarity index 97% rename from pkg/startup/backend_preload.go rename to core/startup/backend_preload.go index 37ca911d8..4eb57deea 100644 --- a/pkg/startup/backend_preload.go +++ b/core/startup/backend_preload.go @@ -8,8 +8,8 @@ import ( "github.com/mudler/LocalAI/core/config" "github.com/mudler/LocalAI/core/gallery" - "github.com/mudler/LocalAI/core/system" "github.com/mudler/LocalAI/pkg/downloader" + "github.com/mudler/LocalAI/pkg/system" "github.com/rs/zerolog/log" ) diff --git a/pkg/startup/model_preload.go b/core/startup/model_preload.go similarity index 99% rename from pkg/startup/model_preload.go rename to core/startup/model_preload.go index 1b2e88cde..78214eede 100644 --- a/pkg/startup/model_preload.go +++ b/core/startup/model_preload.go @@ -10,8 +10,8 @@ import ( "github.com/mudler/LocalAI/core/config" "github.com/mudler/LocalAI/core/gallery" - "github.com/mudler/LocalAI/core/system" "github.com/mudler/LocalAI/pkg/downloader" + "github.com/mudler/LocalAI/pkg/system" "github.com/mudler/LocalAI/pkg/utils" "github.com/rs/zerolog/log" "gopkg.in/yaml.v2" diff --git a/pkg/startup/model_preload_test.go b/core/startup/model_preload_test.go similarity index 96% rename from pkg/startup/model_preload_test.go rename to core/startup/model_preload_test.go index d8e257d7a..b99544d28 100644 --- a/pkg/startup/model_preload_test.go +++ b/core/startup/model_preload_test.go @@ -6,7 +6,7 @@ import ( "path/filepath" "github.com/mudler/LocalAI/core/config" - . "github.com/mudler/LocalAI/pkg/startup" + . "github.com/mudler/LocalAI/core/startup" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/pkg/startup/startup_suite_test.go b/core/startup/startup_suite_test.go similarity index 100% rename from pkg/startup/startup_suite_test.go rename to core/startup/startup_suite_test.go diff --git a/pkg/templates/cache.go b/core/templates/cache.go similarity index 100% rename from pkg/templates/cache.go rename to core/templates/cache.go diff --git a/pkg/templates/evaluator.go b/core/templates/evaluator.go similarity index 100% rename from pkg/templates/evaluator.go rename to core/templates/evaluator.go diff --git a/pkg/templates/evaluator_test.go b/core/templates/evaluator_test.go similarity index 99% rename from pkg/templates/evaluator_test.go rename to core/templates/evaluator_test.go index b58dd40ba..04ef48d6e 100644 --- a/pkg/templates/evaluator_test.go +++ b/core/templates/evaluator_test.go @@ -3,8 +3,8 @@ package templates_test import ( "github.com/mudler/LocalAI/core/config" "github.com/mudler/LocalAI/core/schema" + . "github.com/mudler/LocalAI/core/templates" "github.com/mudler/LocalAI/pkg/functions" - . "github.com/mudler/LocalAI/pkg/templates" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/pkg/templates/multimodal.go b/core/templates/multimodal.go similarity index 100% rename from pkg/templates/multimodal.go rename to core/templates/multimodal.go diff --git a/pkg/templates/multimodal_test.go b/core/templates/multimodal_test.go similarity index 97% rename from pkg/templates/multimodal_test.go rename to core/templates/multimodal_test.go index adea6b524..b8c009e9d 100644 --- a/pkg/templates/multimodal_test.go +++ b/core/templates/multimodal_test.go @@ -1,7 +1,7 @@ package templates_test import ( - . "github.com/mudler/LocalAI/pkg/templates" // Update with your module path + . "github.com/mudler/LocalAI/core/templates" // Update with your module path // Update with your module path . "github.com/onsi/ginkgo/v2" diff --git a/pkg/templates/templates_suite_test.go b/core/templates/templates_suite_test.go similarity index 100% rename from pkg/templates/templates_suite_test.go rename to core/templates/templates_suite_test.go diff --git a/core/system/capabilities.go b/pkg/system/capabilities.go similarity index 100% rename from core/system/capabilities.go rename to pkg/system/capabilities.go