Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(application): introduce application global state #2072

Merged
merged 52 commits into from
Apr 29, 2024

Conversation

dave-gray101
Copy link
Collaborator

@dave-gray101 dave-gray101 commented Apr 18, 2024

In order to make #2062 less intimidating to review, I am going to create some smaller PRs to merge safe code over and get it out of the way!

This PR brings back over the following elements of #1963 ::

  • pkg/utils/base64.go and a brand-new test file pkg/utils/base64_test.go - tests aren't fabulous but better than nothing.
  • core/state.go - Not actually used yet, major sections commented out. Will be easier to bring over later splits if this is in place now though!
  • Rename of BackendMonitorService and schema/whisper.go to schema/transcription.go and Result struct to TranscriptionResult
  • core/config/backend_config_loader.go - this code was formerly in core/config/backend_config.go, split apart without changes at this time. That file is a bit large and covers two distinct responsibilities of the per-backend configuration struct and the singleton loader service. I think it's much cleaner in two distinct files, and as a bonus it's easier to read them both in separate tabs at once this way 👍
  • core/services/list_models.go - this is the lowest-risk and least-changed service, so pull it over in this PR [for build / CI test reasons]
    • Note that the tmpLMS variable will be removed in the next split - temporary artifact before core/state.go is migrated in the next PR - which will focus on moving services and wiring them up.

Copy link

netlify bot commented Apr 18, 2024

Deploy Preview for localai canceled.

Name Link
🔨 Latest commit 6dd72f7
🔍 Latest deploy log https://app.netlify.com/sites/localai/deploys/662fcc4bf0cfd200089ca840

@dave-gray101 dave-gray101 enabled auto-merge (squash) April 18, 2024 23:59
@mudler
Copy link
Owner

mudler commented Apr 20, 2024

cool! I think splitting brings benefits already, it's much easier to review the code :)

backend/go/transcribe/transcript.go Outdated Show resolved Hide resolved
core/http/app.go Show resolved Hide resolved
core/http/app.go Show resolved Hide resolved
core/services/backend_monitor.go Outdated Show resolved Hide resolved
core/startup/startup.go Outdated Show resolved Hide resolved
Signed-off-by: Dave Lee <[email protected]>
@mudler
Copy link
Owner

mudler commented Apr 22, 2024

@dave-gray101 sorry to circle back late, what I mean is that you can have a channel of e.g. Jobs that executes something, and the Job results containing channels for the results. In the example below (which is a pattern that I end up using heavily) channels are used to signal that the work has been finished, but can be expanded easily : https://go.dev/play/p/6b0n5ISuYp-

package main

import (
	"fmt"
	"sync"
)

// Job represents a task that needs to be processed.
type Job struct {
	ID      int
	JobData string
}

// JobResult holds the result of a job, along with a channel to signal completion.
type JobResult struct {
	Result string
	done   chan struct{}
	mu     sync.Mutex
}

// NewJobResult initializes a new JobResult.
func NewJobResult() *JobResult {
	return &JobResult{
		done: make(chan struct{}),
	}
}

// SetResult sets the result of a Job and signals that it's ready.
func (jr *JobResult) SetResult(result string) {
	jr.mu.Lock()
	defer jr.mu.Unlock()
	jr.Result = result
	close(jr.done) // Signal that the result is ready
}

// Wait blocks until the result is ready and then returns the result.
func (jr *JobResult) Wait() string {
	<-jr.done // Wait for the result to be ready
	jr.mu.Lock()
	defer jr.mu.Unlock()
	return jr.Result
}

func worker(jobs <-chan Job, results map[int]*JobResult) {
	for job := range jobs {
		go func(job Job) {
			// Simulate some work
			processResult := fmt.Sprintf("Processed Job: %d with data: %s", job.ID, job.JobData)
			results[job.ID].SetResult(processResult)
		}(job)
	}
}

func submitJob(jobs chan<- Job, results map[int]*JobResult, id int, data string) *JobResult {
	job := Job{ID: id, JobData: data}
	result := NewJobResult()
	results[job.ID] = result
	jobs <- job
	return result
}

func main() {
	jobs := make(chan Job, 5)
	results := make(map[int]*JobResult)

	// Start the worker
	go worker(jobs, results)

	// Submit jobs and get results immediately
	jobResults := []*JobResult{}
	for i := 0; i < 3; i++ {
		res := submitJob(jobs, results, i+1, fmt.Sprintf("data%d", i+1))
		jobResults = append(jobResults, res)
	}
	close(jobs)

	// Wait and print the results of each job
	for _, res := range jobResults {
		fmt.Println(res.Wait())
	}
}

core/state.go Outdated Show resolved Hide resolved
appConfig *config.ApplicationConfig
}

func NewListModelsService(ml *model.ModelLoader, bcl *config.BackendConfigLoader, appConfig *config.ApplicationConfig) *ListModelsService {
Copy link
Owner

@mudler mudler Apr 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small design nit: as we are refactoring, I wonder if this shouldn't just be a handler for the application, or just a function instead? It does not seem to be a long-living service, having it inside services makes me wonder if this is something that lives e.g. in a go routine

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to address any design concerns here in the next PR unless you consider it a blocker - wiring up the services will be the focus of that one

@mudler mudler changed the title refactor: Channel Refactor Split 1 refactor(application): introduce application global state Apr 27, 2024
@mudler mudler requested a review from cryptk April 27, 2024 16:44
@mudler
Copy link
Owner

mudler commented Apr 27, 2024

Some small nits from my side, but overall looks good - as we are refactoring and this changeset shouldn't introduce regressions, maybe makes sense to tackle some of the small nits now?

@mudler
Copy link
Owner

mudler commented Apr 29, 2024

Looks good! nice cleanup!

@mudler mudler disabled auto-merge April 29, 2024 16:35
@mudler mudler enabled auto-merge (squash) April 29, 2024 16:35
@mudler mudler merged commit c4f958e into mudler:master Apr 29, 2024
39 checks passed
@mudler mudler added the enhancement New feature or request label May 2, 2024
truecharts-admin added a commit to truecharts/charts that referenced this pull request May 5, 2024
…4.0 by renovate (#21605)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [docker.io/localai/localai](https://togithub.com/mudler/LocalAI) |
minor | `v2.13.0-cublas-cuda11-ffmpeg-core` ->
`v2.14.0-cublas-cuda11-ffmpeg-core` |
| [docker.io/localai/localai](https://togithub.com/mudler/LocalAI) |
minor | `v2.13.0-cublas-cuda11-core` -> `v2.14.0-cublas-cuda11-core` |
| [docker.io/localai/localai](https://togithub.com/mudler/LocalAI) |
minor | `v2.13.0-cublas-cuda12-ffmpeg-core` ->
`v2.14.0-cublas-cuda12-ffmpeg-core` |
| [docker.io/localai/localai](https://togithub.com/mudler/LocalAI) |
minor | `v2.13.0-cublas-cuda12-core` -> `v2.14.0-cublas-cuda12-core` |
| [docker.io/localai/localai](https://togithub.com/mudler/LocalAI) |
minor | `v2.13.0-ffmpeg-core` -> `v2.14.0-ffmpeg-core` |
| [docker.io/localai/localai](https://togithub.com/mudler/LocalAI) |
minor | `v2.13.0` -> `v2.14.0` |

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>mudler/LocalAI (docker.io/localai/localai)</summary>

###
[`v2.14.0`](https://togithub.com/mudler/LocalAI/releases/tag/v2.14.0)

[Compare
Source](https://togithub.com/mudler/LocalAI/compare/v2.13.0...v2.14.0)

##### 🚀  AIO Image Update: llama3 has landed!

We're excited to announce that our AIO image has been upgraded with the
latest LLM model, llama3, enhancing our capabilities with more accurate
and dynamic responses. Behind the scenes uses
https://huggingface.co/NousResearch/Hermes-2-Pro-Llama-3-8B-GGUF which
is ready for function call, yay!

##### 💬 WebUI enhancements: Updates in Chat, Image Generation, and TTS

|Chat  | TTS | Image gen |
|------------|----------------|-------------|
|
![chatui](https://togithub.com/mudler/LocalAI/assets/2420543/ff71ad02-841d-48a9-99a7-30f024ae3331)
|
![ttsui](https://togithub.com/mudler/LocalAI/assets/2420543/0c137ba5-cb35-426d-ae5d-390679432cf0)
|
![image](https://togithub.com/mudler/LocalAI/assets/2420543/88f8ef30-e06a-454f-b01a-08fcd6917188)
|

Our interfaces for Chat, Text-to-Speech (TTS), and Image Generation have
finally landed. Enjoy streamlined and simple interactions thanks to the
efforts of our team, led by
[@&#8203;mudler](https://togithub.com/mudler), who have worked
tirelessly to enhance your experience. The WebUI interface serves as a
quick way to debug and assess models loaded in LocalAI - there is much
to improve, but we have now a small, hackable interface!

##### 🖼️ Many new models in the model gallery!

|
![local-ai-gallery](https://togithub.com/mudler/LocalAI/assets/2420543/06a06d3c-b91a-472b-892a-a1b69ddc8c56)
|
|------------|

The model gallery has received a substantial upgrade with numerous new
models, including Einstein v6.1, SOVL, and several specialized Llama3
iterations. These additions are designed to cater to a broader range of
tasks , making LocalAI more versatile than ever. Kudos to
[@&#8203;mudler](https://togithub.com/mudler) for spearheading these
exciting updates - now you can select with a couple of click the model
you like!

##### 🛠️ Robust Fixes and Optimizations

This update brings a series of crucial bug fixes and security
enhancements to ensure our platform remains secure and efficient.
Special thanks to
[@&#8203;dave-gray101](https://togithub.com/dave-gray101),
[@&#8203;cryptk](https://togithub.com/cryptk), and
[@&#8203;fakezeta](https://togithub.com/fakezeta) for their diligent
work in rooting out and resolving these issues 🤗

##### ✨ OpenVINO and more

We're introducing OpenVINO acceleration, and many OpenVINO models in the
gallery. You can now enjoy fast-as-hell speed on Intel CPU and GPUs.
Applause to [@&#8203;fakezeta](https://togithub.com/fakezeta) for the
contributions!

##### 📚 Documentation and Dependency Upgrades

We've updated our documentation and dependencies to keep you equipped
with the latest tools and knowledge. These updates ensure that LocalAI
remains a robust and dependable platform.

##### 👥 A Community Effort

A special shout-out to our new contributors,
[@&#8203;QuinnPiers](https://togithub.com/QuinnPiers) and
[@&#8203;LeonSijiaLu](https://togithub.com/LeonSijiaLu), who have
enriched our community with their first contributions. Welcome aboard,
and thank you for your dedication and fresh insights!

Each update in this release not only enhances our platform's
capabilities but also ensures a safer and more user-friendly experience.
We are excited to see how our users leverage these new features in their
projects, freel free to hit a line on Twitter or in any other social,
we'd be happy to hear how you use LocalAI!

##### 📣 Spread the word!

First off, a massive thank you (again!) to each and every one of you
who've chipped in to squash bugs and suggest cool new features for
LocalAI. Your help, kind words, and brilliant ideas are truly
appreciated - more than words can say!

And to those of you who've been heros, giving up your own time to help
out fellow users on Discord and in our repo, you're absolutely amazing.
We couldn't have asked for a better community.

Just so you know, LocalAI doesn't have the luxury of big corporate
sponsors behind it. It's all us, folks. So, if you've found value in
what we're building together and want to keep the momentum going,
consider showing your support. A little shoutout on your favorite social
platforms using @&#8203;LocalAI_OSS and @&#8203;mudler_it or joining our
sponsors can make a big difference.

Also, if you haven't yet joined our Discord, come on over! Here's the
link: https://discord.gg/uJAeKSAGDy

Every bit of support, every mention, and every star adds up and helps us
keep this ship sailing. Let's keep making LocalAI awesome together!

Thanks a ton, and.. exciting times ahead with LocalAI!

##### What's Changed

##### Bug fixes 🐛

- fix: `config_file_watcher.go` - root all file reads for safety by
[@&#8203;dave-gray101](https://togithub.com/dave-gray101) in
[mudler/LocalAI#2144
- fix: github bump_docs.sh regex to drop emoji and other text by
[@&#8203;dave-gray101](https://togithub.com/dave-gray101) in
[mudler/LocalAI#2180
- fix: undefined symbol: iJIT_NotifyEvent in import torch
#[#&#8203;2153](https://togithub.com/mudler/LocalAI/issues/2153) by
[@&#8203;fakezeta](https://togithub.com/fakezeta) in
[mudler/LocalAI#2179
- fix: security scanner warning noise: error handlers part 2 by
[@&#8203;dave-gray101](https://togithub.com/dave-gray101) in
[mudler/LocalAI#2145
- fix: ensure GNUMake jobserver is passed through to whisper.cpp build
by [@&#8203;cryptk](https://togithub.com/cryptk) in
[mudler/LocalAI#2187
- fix: bring everything onto the same GRPC version to fix tests by
[@&#8203;cryptk](https://togithub.com/cryptk) in
[mudler/LocalAI#2199

##### Exciting New Features 🎉

- feat(gallery): display job status also during navigation by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2151
- feat: cleanup Dockerfile and make final image a little smaller by
[@&#8203;cryptk](https://togithub.com/cryptk) in
[mudler/LocalAI#2146
- fix: swap to WHISPER_CUDA per deprecation message from whisper.cpp by
[@&#8203;cryptk](https://togithub.com/cryptk) in
[mudler/LocalAI#2170
- feat: only keep the build artifacts from the grpc build by
[@&#8203;cryptk](https://togithub.com/cryptk) in
[mudler/LocalAI#2172
- feat(gallery): support model deletion by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2173
- refactor(application): introduce application global state by
[@&#8203;dave-gray101](https://togithub.com/dave-gray101) in
[mudler/LocalAI#2072
- feat: organize Dockerfile into distinct sections by
[@&#8203;cryptk](https://togithub.com/cryptk) in
[mudler/LocalAI#2181
- feat: OpenVINO acceleration for embeddings in transformer backend by
[@&#8203;fakezeta](https://togithub.com/fakezeta) in
[mudler/LocalAI#2190
- chore: update go-stablediffusion to latest commit with Make jobserver
fix by [@&#8203;cryptk](https://togithub.com/cryptk) in
[mudler/LocalAI#2197
- feat: user defined inference device for CUDA and OpenVINO by
[@&#8203;fakezeta](https://togithub.com/fakezeta) in
[mudler/LocalAI#2212
- feat(ux): Add chat, tts, and image-gen pages to the WebUI by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2222
- feat(aio): switch to llama3-based for LLM by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2225
- feat(ui): support multilineand style `ul` by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2226

##### 🧠 Models

- models(gallery): add Einstein v6.1 by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2152
- models(gallery): add SOVL by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2154
- models(gallery): add average_normie by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2155
- models(gallery): add solana by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2157
- models(gallery): add poppy porpoise by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2158
- models(gallery): add Undi95/Llama-3-LewdPlay-8B-evo-GGUF by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2160
- models(gallery): add biomistral-7b by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2161
- models(gallery): add llama3-32k by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2183
- models(gallery): add openvino models by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2184
- models(gallery): add lexifun by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2193
- models(gallery): add suzume-llama-3-8B-multilingual-gguf by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2194
- models(gallery): add guillaumetell by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2195
- models(gallery): add wizardlm2 by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2209
- models(gallery): Add Hermes-2-Pro-Llama-3-8B-GGUF by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2218

##### 📖 Documentation and examples

- ⬆️ Update docs version mudler/LocalAI by
[@&#8203;localai-bot](https://togithub.com/localai-bot) in
[mudler/LocalAI#2149
- draft:Update model-gallery.md with correct gallery file by
[@&#8203;QuinnPiers](https://togithub.com/QuinnPiers) in
[mudler/LocalAI#2163
- docs: update gallery, add rerankers by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2166
- docs: enhance and condense few sections by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2178
- \[Documentations] Removed invalid numberings from `troubleshooting
mac` by [@&#8203;LeonSijiaLu](https://togithub.com/LeonSijiaLu) in
[mudler/LocalAI#2174

##### 👒 Dependencies

- ⬆️ Update ggerganov/llama.cpp by
[@&#8203;localai-bot](https://togithub.com/localai-bot) in
[mudler/LocalAI#2150
- ⬆️ Update ggerganov/llama.cpp by
[@&#8203;localai-bot](https://togithub.com/localai-bot) in
[mudler/LocalAI#2159
- ⬆️ Update ggerganov/llama.cpp by
[@&#8203;localai-bot](https://togithub.com/localai-bot) in
[mudler/LocalAI#2176
- ⬆️ Update ggerganov/whisper.cpp by
[@&#8203;localai-bot](https://togithub.com/localai-bot) in
[mudler/LocalAI#2177
- update go-tinydream to latest commit by
[@&#8203;cryptk](https://togithub.com/cryptk) in
[mudler/LocalAI#2182
- build(deps): bump dependabot/fetch-metadata from 2.0.0 to 2.1.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[mudler/LocalAI#2186
- ⬆️ Update ggerganov/llama.cpp by
[@&#8203;localai-bot](https://togithub.com/localai-bot) in
[mudler/LocalAI#2189
- ⬆️ Update ggerganov/whisper.cpp by
[@&#8203;localai-bot](https://togithub.com/localai-bot) in
[mudler/LocalAI#2188
- ⬆️ Update ggerganov/llama.cpp by
[@&#8203;localai-bot](https://togithub.com/localai-bot) in
[mudler/LocalAI#2203
- ⬆️ Update ggerganov/llama.cpp by
[@&#8203;localai-bot](https://togithub.com/localai-bot) in
[mudler/LocalAI#2213

##### Other Changes

- Revert ":arrow_up: Update docs version mudler/LocalAI" by
[@&#8203;mudler](https://togithub.com/mudler) in
[mudler/LocalAI#2165
- Issue-1720: Updated `Build on mac` documentations by
[@&#8203;LeonSijiaLu](https://togithub.com/LeonSijiaLu) in
[mudler/LocalAI#2171
- ⬆️ Update ggerganov/llama.cpp by
[@&#8203;localai-bot](https://togithub.com/localai-bot) in
[mudler/LocalAI#2224

##### New Contributors

- [@&#8203;QuinnPiers](https://togithub.com/QuinnPiers) made their first
contribution in
[mudler/LocalAI#2163
- [@&#8203;LeonSijiaLu](https://togithub.com/LeonSijiaLu) made their
first contribution in
[mudler/LocalAI#2171

**Full Changelog**:
mudler/LocalAI@v2.13.0...v2.14.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these
updates again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zNDEuMCIsInVwZGF0ZWRJblZlciI6IjM3LjM0MS4wIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbImF1dG9tZXJnZSIsInVwZGF0ZS9kb2NrZXIvZ2VuZXJhbC9ub24tbWFqb3IiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants