LocalAI is the free, Open Source OpenAI alternative. LocalAI act as a drop-in replacement REST API that’s compatible with OpenAI API specifications for local inferencing. It allows you to run LLMs, generate images, audio (and not only) locally or on-prem with consumer grade hardware, supporting multiple model families that are compatible with the ggml format. Does not require GPU. It is maintained by mudler.
Follow LocalAI
Connect with the Creator
Share LocalAI Repository
In a nutshell:
Local, OpenAI drop-in alternative REST API. You own your data.
NO GPU required. NO Internet access is required either
Optional, GPU Acceleration is available in llama.cpp-compatible LLMs. See also the build section.
Supports multiple models
π Once loaded the first time, it keep models loaded in memory for faster inference
β‘ Doesn’t shell-out, but uses C++ bindings for a faster inference and better performance.
LocalAI was created by Ettore Di Giacinto and is a community-driven project, focused on making the AI accessible to anyone. Any contribution, feedback and PR is welcome!
Note that this started just as a fun weekend project in order to try to create the necessary pieces for a full AI assistant like ChatGPT: the community is growing fast and we are working hard to make it better and more stable. If you want to help, please consider contributing (see below)!
LocalAI is an API written in Go that serves as an OpenAI shim, enabling software already developed with OpenAI SDKs to seamlessly integrate with LocalAI. It can be effortlessly implemented as a substitute, even on consumer-grade hardware. This capability is achieved by employing various C++ backends, including ggml, to perform inference on LLMs using both CPU and, if desired, GPU. Internally LocalAI backends are just gRPC server, indeed you can specify and build your own gRPC server and extend LocalAI in runtime as well. It is possible to specify external gRPC server and/or binaries that LocalAI will manage internally.
LocalAI uses a mixture of backends written in various languages (C++, Golang, Python, …). You can check the model compatibility table to learn about all the components of LocalAI.
Contribute and help
To help the project you can:
If you have technological skills and want to contribute to development, have a look at the open issues. If you are new you can have a look at the good-first-issue and help-wanted labels.
If you don’t have technological skills you can still help improving documentation or add examples or share your user-stories with our community, any help and contribution is welcome!
As much as typical open source projects starts, I, mudler, was fiddling around with llama.cpp over my long nights and wanted to have a way to call it from go, as I am a Golang developer and use it extensively. So I’ve created LocalAI (or what was initially known as llama-cli) and added an API to it.
But guess what? The more I dived into this rabbit hole, the more I realized that I had stumbled upon something big. With all the fantastic C++ projects floating around the community, it dawned on me that I could piece them together to create a full-fledged OpenAI replacement. So, ta-da! LocalAI was born, and it quickly overshadowed its humble origins.
Now, why did I choose to go with C++ bindings, you ask? Well, I wanted to keep LocalAI snappy and lightweight, allowing it to run like a champ on any system and avoid any Golang penalties of the GC, and, most importantly built on shoulders of giants like llama.cpp. Go is good at backends and API and is easy to maintain. And hey, don’t forget that I’m all about sharing the love. That’s why I made LocalAI MIT licensed, so everyone can hop on board and benefit from it.
As if that wasn’t exciting enough, as the project gained traction, mkellerman and Aisuko jumped in to lend a hand. mkellerman helped set up some killer examples, while Aisuko is becoming our community maestro. The community now is growing even more with new contributors and users, and I couldn’t be happier about it!
Oh, and let’s not forget the real MVP hereβllama.cpp. Without this extraordinary piece of software, LocalAI wouldn’t even exist. So, a big shoutout to the community for making this magic happen!
π€ Contributors
This is a community project, a special thanks to our contributors! π€
Subsections of LocalAI
Getting started
LocalAI is available as a container image and binary. It can be used with docker, podman, kubernetes and any container engine. You can check out all the available images with corresponding tags here.
See also our How to section for end-to-end guided examples curated by the community.
# Prepare the models into the `model` directorymkdir models
# copy your models to itcp your-model.gguf models/
# run the LocalAI containerdocker run -p 8080:8080 -v $PWD/models:/models -ti --rm quay.io/go-skynet/local-ai:latest --models-path /models --context-size 700 --threads 4# You should see:# # βββββββββββββββββββββββββββββββββββββββββββββββββββββ# β Fiber v2.42.0 β# β http://127.0.0.1:8080 β# β (bound on host 0.0.0.0 and port 8080) β# β β# β Handlers ............. 1 Processes ........... 1 β# β Prefork ....... Disabled PID ................. 1 β# βββββββββββββββββββββββββββββββββββββββββββββββββββββ# Try the endpoint with curlcurl http://localhost:8080/v1/completions -H "Content-Type: application/json" -d '{
"model": "your-model.gguf",
"prompt": "A long time ago in a galaxy far, far away",
"temperature": 0.7
}'
Note
If running on Apple Silicon (ARM) it is not suggested to run on Docker due to emulation. Follow the build instructions to use Metal acceleration for full GPU support.
If you are running Apple x86_64 you can use docker, there is no additional gain into building it from source.
# Clone LocalAIgit clone https://github.com/go-skynet/LocalAI
cd LocalAI
# (optional) Checkout a specific LocalAI tag# git checkout -b build <TAG># copy your models to models/cp your-model.gguf models/
# (optional) Edit the .env file to set things like context size and threads# vim .env# start with docker composedocker compose up -d --pull always
# or you can build the images with:# docker compose up -d --build# Now API is accessible at localhost:8080curl http://localhost:8080/v1/models
# {"object":"list","data":[{"id":"your-model.gguf","object":"model"}]}curl http://localhost:8080/v1/completions -H "Content-Type: application/json" -d '{
"model": "your-model.gguf",
"prompt": "A long time ago in a galaxy far, far away",
"temperature": 0.7
}'
Note: If you are on Windows, please make sure the project is on the Linux Filesystem, otherwise loading models might be slow. For more Info: Microsoft Docs
For installing LocalAI in Kubernetes, you can use the following helm chart:
# Install the helm repositoryhelm repo add go-skynet https://go-skynet.github.io/helm-charts/
# Update the repositorieshelm repo update
# Get the valueshelm show values go-skynet/local-ai > values.yaml
# Edit the values value if needed# vim values.yaml ...# Install the helm charthelm install local-ai go-skynet/local-ai -f values.yaml
Container images
LocalAI has a set of images to support CUDA, ffmpeg and ‘vanilla’ (CPU-only). The image list is on quay:
master
latest
v2.0.0
v2.0.0-ffmpeg
v2.0.0-ffmpeg-core
Core Images - Smaller images without predownload python dependencies
master-cublas-cuda11
master-cublas-cuda11-core
v2.0.0-cublas-cuda11
v2.0.0-cublas-cuda11-core
v2.0.0-cublas-cuda11-ffmpeg
v2.0.0-cublas-cuda11-ffmpeg-core
Core Images - Smaller images without predownload python dependencies
master-cublas-cuda12
master-cublas-cuda12-core
v2.0.0-cublas-cuda12
v2.0.0-cublas-cuda12-core
v2.0.0-cublas-cuda12-ffmpeg
v2.0.0-cublas-cuda12-ffmpeg-core
Core Images - Smaller images without predownload python dependencies
Example:
Standard (GPT + stablediffusion): quay.io/go-skynet/local-ai:latest
FFmpeg: quay.io/go-skynet/local-ai:v2.0.0-ffmpeg
CUDA 11+FFmpeg: quay.io/go-skynet/local-ai:v2.0.0-cublas-cuda11-ffmpeg
CUDA 12+FFmpeg: quay.io/go-skynet/local-ai:v2.0.0-cublas-cuda12-ffmpeg
Note
Note: the binary inside the image is pre-compiled, and might not suite all CPUs.
To enable CPU optimizations for the execution environment,
the default behavior is to rebuild when starting the container.
To disable this auto-rebuild behavior,
set the environment variable REBUILD to false.
Deploy a single LocalAI pod with 6GB of persistent storage serving up a ggml-gpt4all-j model with custom prompt.
### values.yamlreplicaCount:1deployment:image:quay.io/go-skynet/local-ai:latest##(This is for CPU only, to use GPU change it to a image that supports GPU IE "v2.0.0-cublas-cuda12-core")env:threads:4context_size:512modelsPath:"/models"resources:{}# We usually recommend not to specify default resources and to leave this as a conscious# choice for the user. This also increases chances charts run on environments with little# resources, such as Minikube. If you do want to specify resources, uncomment the following# lines, adjust them as necessary, and remove the curly braces after 'resources:'.# limits:# cpu: 100m# memory: 128Mi# requests:# cpu: 100m# memory: 128Mi# Prompt templates to include# Note: the keys of this map will be the names of the prompt template filespromptTemplates:{}# ggml-gpt4all-j.tmpl: |# The prompt below is a question to answer, a task to complete, or a conversation to respond to; decide which and write an appropriate response.# ### Prompt:# {{.Input}}# ### Response:# Models to download at runtimemodels:# Whether to force download models even if they already existforceDownload:false# The list of URLs to download models from# Note: the name of the file will be the name of the loaded modellist:- url:"https://gpt4all.io/models/ggml-gpt4all-j.bin"# basicAuth: base64EncodedCredentials# Persistent storage for models and prompt templates.# PVC and HostPath are mutually exclusive. If both are enabled,# PVC configuration takes precedence. If neither are enabled, ephemeral# storage is used.persistence:pvc:enabled:falsesize:6GiaccessModes:- ReadWriteOnceannotations:{}# OptionalstorageClass:~hostPath:enabled:falsepath:"/models"service:type:ClusterIPport:80annotations:{}# If using an AWS load balancer, you'll need to override the default 60s load balancer idle timeout# service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: "1200"ingress:enabled:falseclassName:""annotations:{}# kubernetes.io/ingress.class: nginx# kubernetes.io/tls-acme: "true"hosts:- host:chart-example.localpaths:- path:/pathType:ImplementationSpecifictls:[]# - secretName: chart-example-tls# hosts:# - chart-example.localnodeSelector:{}tolerations:[]affinity:{}
Set the OPENAI_API_BASE environment variable, or by code:
importopenaiopenai.api_base="http://localhost:8080/v1"# create a chat completionchat_completion=openai.ChatCompletion.create(model="gpt-3.5-turbo",messages=[{"role":"user","content":"Hello world"}])# print the completionprint(completion.choices[0].message.content)
π What's New
04-12-2023: v2.0.0
This release brings a major overhaul in some backends.
Breaking/important changes:
Backend rename: llama-stable renamed to llama-ggml1287
Prompt template changes:
1254
(extra space in roles)
Watchdog for backends (
1341
). As https://github.com/ggerganov/llama.cpp/issues/3969 is hitting LocalAI’s llama-cpp implementation, we have now a watchdog that can be used to make sure backends are not stalling. This is a generic mechanism that can be enabled for all the backends now.
Due to the python dependencies size of images grew in size.
If you still want to use smaller images without python dependencies, you can use the corresponding images tags ending with -core.
This release now brings the llama-cpp backend which is a c++ backend tied to llama.cpp. It follows more closely and tracks recent versions of llama.cpp. It is not feature compatible with the current llama backend but plans are to sunset the current llama backend in favor of this one. This one will be probably be the latest release containing the older llama backend written in go and c++. The major improvement with this change is that there are less layers that could be expose to potential bugs - and as well it ease out maintenance as well.
Support for ROCm/HIPBLAS
This release bring support for AMD thanks to @65a . See more details in
1100
More CLI commands
Thanks to @jespino now the local-ai binary has more subcommands allowing to manage the gallery or try out directly inferencing, check it out!
This is an exciting LocalAI release! Besides bug-fixes and enhancements this release brings the new backend to a whole new level by extending support to vllm and vall-e-x for audio generation!
Check out the documentation for vllm here and Vall-E-X here
Hey everyone, Ettore here, I’m so happy to share this release out - while this summer is hot apparently doesn’t stop LocalAI development :)
This release brings a lot of new features, bugfixes and updates! Also a big shout out to the community, this was a great release!
Attention π¨
From this release the llama backend supports only gguf files (see
943
). LocalAI however still supports ggml files. We ship a version of llama.cpp before that change in a separate backend, named llama-stable to allow still loading ggml files. If you were specifying the llama backend manually to load ggml files from this release you should use llama-stable instead, or do not specify a backend at all (LocalAI will automatically handle this).
Image generation enhancements
The Diffusers backend got now various enhancements, including support to generate images from images, longer prompts, and support for more kernels schedulers. See the Diffusers documentation for more information.
Lora adapters
Now it’s possible to load lora adapters for llama.cpp. See
955
for more information.
Device management
It is now possible for single-devices with one GPU to specify --single-active-backend to allow only one backend active at the time
925
.
Community spotlight
Resources management
Thanks to the continous community efforts (another cool contribution from
dave-gray101
) now it’s possible to shutdown a backend programmatically via the API.
There is an ongoing effort in the community to better handling of resources. See also the π₯Roadmap.
New how-to section
Thanks to the community efforts now we have a new how-to section with various examples on how to use LocalAI. This is a great starting point for new users! We are currently working on improving it, a huge shout out to
lunamidori5
from the community for the impressive efforts on this!
π‘ More examples!
Open source autopilot? See the new addition by
gruberdev
in our examples on how to use Continue with LocalAI!
feat: pre-configure LocalAI galleries by
mudler
in
886
πΆ Bark
Bark is a text-prompted generative audio model - it combines GPT techniques to generate Audio from text. It is a great addition to LocalAI, and it’s available in the container images by default.
It can also generate music, see the example: lion.webm
π¦ AutoGPTQ
AutoGPTQ is an easy-to-use LLMs quantization package with user-friendly apis, based on GPTQ algorithm.
It is targeted mainly for GPU usage only. Check out the AutoGPTQ documentation for usage.
π¦ Exllama
Exllama is a “A more memory-efficient rewrite of the HF transformers implementation of Llama for use with quantized weights”. It is a faster alternative to run LLaMA models on GPU.Check out the Exllama documentation for usage.
𧨠Diffusers
Diffusers is the go-to library for state-of-the-art pretrained diffusion models for generating images, audio, and even 3D structures of molecules. Currently it is experimental, and supports generation only of images so you might encounter some issues on models which weren’t tested yet. Check out the Diffusers documentation for usage.
π API Keys
Thanks to the community contributions now it’s possible to specify a list of API keys that can be used to gate API requests.
API Keys can be specified with the API_KEY environment variable as a comma-separated list of keys.
πΌοΈ Galleries
Now by default the model-gallery repositories are configured in the container images
π‘ New project
LocalAGI is a simple agent that uses LocalAI functions to have a full locally runnable assistant (with no API keys needed).
See it here in action planning a trip for San Francisco!
feat(llama2): add template for chat messages by
dave-gray101
in
782
Note
From this release to use the OpenAI functions you need to use the llama-grammar backend. It has been added a llama backend for tracking llama.cpp master and llama-grammar for the grammar functionalities that have not been merged yet upstream. See also OpenAI functions. Until the feature is merged we will have two llama backends.
Huggingface embeddings
In this release is now possible to specify to LocalAI external gRPC backends that can be used for inferencing
778
. It is now possible to write internal backends in any language, and a huggingface-embeddings backend is now available in the container image to be used with https://github.com/UKPLab/sentence-transformers. See also Embeddings.
LLaMa 2 has been released!
Thanks to the community effort now LocalAI supports templating for LLaMa2! more at:
782
until we update the model gallery with LLaMa2 models!
The former, ggml-based backend has been renamed to falcon-ggml.
Default pre-compiled binaries
From this release the default behavior of images has changed. Compilation is not triggered on start automatically, to recompile local-ai from scratch on start and switch back to the old behavior, you can set REBUILD=true in the environment variables. Rebuilding can be necessary if your CPU and/or architecture is old and the pre-compiled binaries are not compatible with your platform. See the build section for more information.
Add Text-to-Audio generation with go-piper by
mudler
in
649
See API endpoints in our documentation.
Add gallery repository by
mudler
in
663
. See models for documentation.
Container images
Standard (GPT + stablediffusion): quay.io/go-skynet/local-ai:v1.20.0
FFmpeg: quay.io/go-skynet/local-ai:v1.20.0-ffmpeg
CUDA 11+FFmpeg: quay.io/go-skynet/local-ai:v1.20.0-cublas-cuda11-ffmpeg
CUDA 12+FFmpeg: quay.io/go-skynet/local-ai:v1.20.0-cublas-cuda12-ffmpeg
Updates
Updates to llama.cpp, go-transformers, gpt4all.cpp and rwkv.cpp.
The NUMA option was enabled by
mudler
in
684
, along with many new parameters (mmap,mmlock, ..). See advanced for the full list of parameters.
Gallery repositories
In this release there is support for gallery repositories. These are repositories that contain models, and can be used to install models. The default gallery which contains only freely licensed models is in Github: https://github.com/go-skynet/model-gallery, but you can use your own gallery by setting the GALLERIES environment variable. An automatic index of huggingface models is available as well.
For example, now you can start LocalAI with the following environment variable to use both galleries:
Now LocalAI uses piper and go-piper to generate audio from text. This is an experimental feature, and it requires GO_TAGS=tts to be set during build. It is enabled by default in the pre-built container images.
Full CUDA GPU offload support ( PR by mudler. Thanks to chnyda for handing over the GPU access, and lu-zero to help in debugging )
Full GPU Metal Support is now fully functional. Thanks to Soleblaze to iron out the Metal Apple silicon support!
Container images:
Standard (GPT + stablediffusion): quay.io/go-skynet/local-ai:v1.19.2
FFmpeg: quay.io/go-skynet/local-ai:v1.19.2-ffmpeg
CUDA 11+FFmpeg: quay.io/go-skynet/local-ai:v1.19.2-cublas-cuda11-ffmpeg
CUDA 12+FFmpeg: quay.io/go-skynet/local-ai:v1.19.2-cublas-cuda12-ffmpeg
π₯π₯π₯ 06-06-2023: v1.18.0 π
This LocalAI release is plenty of new features, bugfixes and updates! Thanks to the community for the help, this was a great community release!
We now support a vast variety of models, while being backward compatible with prior quantization formats, this new release allows still to load older formats and new k-quants!
New features
β¨ Added support for falcon-based model families (7b) ( mudler )
β¨ Experimental support for Metal Apple Silicon GPU - ( mudler and thanks to Soleblaze for testing! ). See the build section.
β¨ Support for token stream in the /v1/completions endpoint ( samm81 )
π Bloomz has been updated to the latest ggml changes, including new quantization format ( mudler )
π RWKV has been updated to the new quantization format( mudler )
π k-quants format support for the llama models ( mudler )
π gpt4all has been updated, incorporating upstream changes allowing to load older models, and with different CPU instruction set (AVX only, AVX2) from the same binary! ( mudler )
Generic
π§ Fully Linux static binary releases ( mudler )
π· Stablediffusion has been enabled on container images by default ( mudler )
Note: You can disable container image rebuilds with REBUILD=false
llama.cpp models now can also automatically save the prompt cache state as well by specifying in the model YAML configuration file:
# Enable prompt caching# This is a file that will be used to save/load the cache. relative to the models directory.prompt_cache_path:"alpaca-cache"# Always enable prompt cacheprompt_cache_all:true
23-05-2023: v1.15.0 released. go-gpt2.cpp backend got renamed to go-ggml-transformers.cpp updated including https://github.com/ggerganov/llama.cpp/pull/1508 which breaks compatibility with older models. This impacts RedPajama, GptNeoX, MPT(not gpt4all-mpt), Dolly, GPT2 and Starcoder based models. Binary releases available, various fixes, including
341
.
21-05-2023: v1.14.0 released. Minor updates to the /models/apply endpoint, llama.cpp backend updated including https://github.com/ggerganov/llama.cpp/pull/1508 which breaks compatibility with older models. gpt4all is still compatible with the old format.
19-05-2023: v1.13.0 released! π₯π₯ updates to the gpt4all and llama backend, consolidated CUDA support (
310
thanks to @bubthegreat and @Thireus ), preliminar support for installing models via API.
17-05-2023: v1.12.0 released! π₯π₯ Minor fixes, plus CUDA (
258
) support for llama.cpp-compatible models and image generation (
272
).
16-05-2023: π₯π₯π₯ Experimental support for CUDA (
258
) in the llama.cpp backend and Stable diffusion CPU image generation (
272
) in master.
13-05-2023: v1.11.0 released! π₯ Updated llama.cpp bindings: This update includes a breaking change in the model files ( https://github.com/ggerganov/llama.cpp/pull/1405 ) - old models should still work with the gpt4all-llama backend.
12-05-2023: v1.10.0 released! π₯π₯ Updated gpt4all bindings. Added support for GPTNeox (experimental), RedPajama (experimental), Starcoder (experimental), Replit (experimental), MosaicML MPT. Also now embeddings endpoint supports tokens arrays. See the langchain-chroma example! Note - this update does NOT include https://github.com/ggerganov/llama.cpp/pull/1405 which makes models incompatible.
11-05-2023: v1.9.0 released! π₯ Important whisper updates (
233229
) and extended gpt4all model families support (
232
). Redpajama/dolly experimental (
214
)
10-05-2023: v1.8.0 released! π₯ Added support for fast and accurate embeddings with bert.cpp (
222
)
09-05-2023: Added experimental support for transcriptions endpoint (
211
)
08-05-2023: Support for embeddings with models using the llama.cpp backend (
207
)
02-05-2023: Support for rwkv.cpp models (
158
) and for /edits endpoint
01-05-2023: Support for SSE stream of tokens in llama.cpp backends (
152
)
Features
This section contains the documentation for the features supported by LocalAI.
CUDA 11 tags: master-cublas-cuda11, v1.40.0-cublas-cuda11, …
CUDA 12 tags: master-cublas-cuda12, v1.40.0-cublas-cuda12, …
CUDA 11 + FFmpeg tags: master-cublas-cuda11-ffmpeg, v1.40.0-cublas-cuda11-ffmpeg, …
CUDA 12 + FFmpeg tags: master-cublas-cuda12-ffmpeg, v1.40.0-cublas-cuda12-ffmpeg, …
In addition to the commands to run LocalAI normally, you need to specify --gpus all to docker, for example:
docker run --rm -ti --gpus all -p 8080:8080 -e DEBUG=true -e MODELS_PATH=/models -e THREADS=1 -v $PWD/models:/models quay.io/go-skynet/local-ai:v1.40.0-cublas-cuda12
If the GPU inferencing is working, you should be able to see something like:
5:22PM DBG Loading model in memory from file: /models/open-llama-7b-q4_0.bin
ggml_init_cublas: found 1 CUDA devices:
Device 0: Tesla T4
llama.cpp: loading model from /models/open-llama-7b-q4_0.bin
llama_model_load_internal: format = ggjt v3 (latest)
llama_model_load_internal: n_vocab = 32000
llama_model_load_internal: n_ctx = 1024
llama_model_load_internal: n_embd = 4096
llama_model_load_internal: n_mult = 256
llama_model_load_internal: n_head = 32
llama_model_load_internal: n_layer = 32
llama_model_load_internal: n_rot = 128
llama_model_load_internal: ftype = 2 (mostly Q4_0)
llama_model_load_internal: n_ff = 11008
llama_model_load_internal: n_parts = 1
llama_model_load_internal: model size = 7B
llama_model_load_internal: ggml ctx size = 0.07 MB
llama_model_load_internal: using CUDA for GPU acceleration
llama_model_load_internal: mem required = 4321.77 MB (+ 1026.00 MB per state)
llama_model_load_internal: allocating batch_size x 1 MB = 512 MB VRAM for the scratch buffer
llama_model_load_internal: offloading 10 repeating layers to GPU
llama_model_load_internal: offloaded 10/35 layers to GPU
llama_model_load_internal: total VRAM used: 1598 MB
...................................................................................................
llama_init_from_file: kv self size = 512.00 MB
Model configuration
Depending on the model architecture and backend used, there might be different ways to enable GPU acceleration. It is required to configure the model you intend to use with a YAML config file. For example, for llama.cpp workloads a configuration file might look like this (where gpu_layers is the number of layers to offload to the GPU):
name:my-model-name# Default model parametersparameters:# Relative to the models pathmodel:llama.cpp-model.ggmlv3.q5_K_M.bincontext_size:1024threads:1f16:true# enable with GPU accelerationgpu_layers:22# GPU Layers (only used when built with cublas)
For diffusers instead, it might look like this instead:
To generate an image you can send a POST request to the /v1/images/generations endpoint with the instruction as the request body:
# 512x512 is supported toocurl http://localhost:8080/v1/images/generations -H "Content-Type: application/json" -d '{
"prompt": "A cute baby sea otter",
"size": "256x256"
}'
Available additional parameters: mode, step.
Note: To set a negative prompt, you can split the prompt with |, for instance: a cute baby sea otter|malformed.
curl http://localhost:8080/v1/images/generations -H "Content-Type: application/json" -d '{
"prompt": "floating hair, portrait, ((loli)), ((one girl)), cute face, hidden hands, asymmetrical bangs, beautiful detailed eyes, eye shadow, hair ornament, ribbons, bowties, buttons, pleated skirt, (((masterpiece))), ((best quality)), colorful|((part of the head)), ((((mutated hands and fingers)))), deformed, blurry, bad anatomy, disfigured, poorly drawn face, mutation, mutated, extra limb, ugly, poorly drawn hands, missing limb, blurry, floating limbs, disconnected limbs, malformed hands, blur, out of focus, long neck, long body, Octane renderer, lowres, bad anatomy, bad hands, text",
"size": "256x256"
}'
stablediffusion-cpp
mode=0
mode=1 (winograd/sgemm)
Note: image generator supports images up to 512x512. You can use other tools however to upscale the image, for instance: https://github.com/upscayl/upscayl.
Setup
Note: In order to use the images/generation endpoint with the stablediffusion C++ backend, you need to build LocalAI with GO_TAGS=stablediffusion. If you are using the container images, it is already enabled.
While the API is running, you can install the model by using the /models/apply endpoint and point it to the stablediffusion model in the models-gallery:
This is an extra backend - in the container is already available and there is nothing to do for the setup.
Model setup
The models will be downloaded the first time you use the backend from huggingface automatically.
Create a model configuration file in the models directory, for instance to use Linaqruf/animagine-xl with CPU:
name:animagine-xlparameters:model:Linaqruf/animagine-xlbackend:diffusers# Force CPU usage - set to true for GPUf16:falsediffusers:pipeline_type:StableDiffusionXLPipelinecuda:false# Enable for GPU usage (CUDA)scheduler_type:euler_a
π Text generation (GPT)
LocalAI supports generating text with GPT with llama.cpp and other backends (such as rwkv.cpp as ) see also the Model compatibility for an up-to-date list of the supported model families.
Note:
You can also specify the model name as part of the OpenAI token.
If only one model is available, the API will use it for all the requests.
To generate a completion, you can send a POST request to the /v1/completions endpoint with the instruction as per the request body:
curl http://localhost:8080/v1/completions -H "Content-Type: application/json" -d '{
"model": "ggml-koala-7b-model-q4_0-r2.bin",
"prompt": "A long time ago in a galaxy far, far away",
"temperature": 0.7
}'
Available additional parameters: top_p, top_k, max_tokens
List models
You can list all the models available with:
curl http://localhost:8080/v1/models
π Audio to text
The transcription endpoint allows to convert audio files to text. The endpoint is based on whisper.cpp, a C++ library for audio transcription. The endpoint supports the audio formats supported by ffmpeg.
Usage
Once LocalAI is started and whisper models are installed, you can use the /v1/audio/transcriptions API endpoint.
The transcriptions endpoint then can be tested like so:
## Get an example audio filewget --quiet --show-progress -O gb1.ogg https://upload.wikimedia.org/wikipedia/commons/1/1f/George_W_Bush_Columbia_FINAL.ogg
## Send the example audio file to the transcriptions endpointcurl http://localhost:8080/v1/audio/transcriptions -H "Content-Type: multipart/form-data" -F file="@$PWD/gb1.ogg" -F model="whisper-1"## Result{"text":"My fellow Americans, this day has brought terrible news and great sadness to our country.At nine o'clock this morning, Mission Control in Houston lost contact with our Space ShuttleColumbia.A short time later, debris was seen falling from the skies above Texas.The Columbia's lost.There are no survivors.One board was a crew of seven.Colonel Rick Husband, Lieutenant Colonel Michael Anderson, Commander Laurel Clark, Captain DavidBrown, Commander William McCool, Dr. Kultna Shavla, and Elon Ramon, a colonel in the IsraeliAir Force.These men and women assumed great risk in the service to all humanity.In an age when spaceflight has come to seem almost routine, it is easy to overlook thedangers of travel by rocket and the difficulties of navigating the fierce outer atmosphere ofthe Earth.These astronauts knew the dangers, and they faced them willingly, knowing they had a highand noble purpose in life.Because of their courage and daring and idealism, we will miss them all the more.All Americans today are thinking as well of the families of these men and women who havebeen given this sudden shock and grief.You're not alone.Our entire nation agrees with you, and those you loved will always have the respect andgratitude of this country.The cause in which they died will continue.Mankind has led into the darkness beyond our world by the inspiration of discovery andthe longing to understand.Our journey into space will go on.In the skies today, we saw destruction and tragedy.As farther than we can see, there is comfort and hope.In the words of the prophet Isaiah, \"Lift your eyes and look to the heavens who createdall these, he who brings out the starry hosts one by one and calls them each by name.\"Because of his great power and mighty strength, not one of them is missing.The same creator who names the stars also knows the names of the seven souls we mourntoday.The crew of the shuttle Columbia did not return safely to Earth yet we can pray that all aresafely home.May God bless the grieving families and may God continue to bless America.[BLANK_AUDIO]"}
π₯ OpenAI functions
LocalAI supports running OpenAI functions with llama.cpp compatible models.
π‘ Check out also LocalAGI for an example on how to use LocalAI functions.
Setup
OpenAI functions are available only with ggml or gguf models compatible with llama.cpp.
You don’t need to do anything specific - just use ggml or gguf models.
Usage example
You can configure a model manually with a YAML config file in the models directory, for example:
name:gpt-3.5-turboparameters:# Model file namemodel:ggml-openllama.bintop_p:80top_k:0.9temperature:0.1
To use the functions with the OpenAI client in python:
importopenai# ...# Send the conversation and available functions to GPTmessages=[{"role":"user","content":"What's the weather like in Boston?"}]functions=[{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA",},"unit":{"type":"string","enum":["celsius","fahrenheit"]},},"required":["location"],},}]response=openai.ChatCompletion.create(model="gpt-3.5-turbo",messages=messages,functions=functions,function_call="auto",)# ...
Note
When running the python script, be sure to:
Set OPENAI_API_KEY environment variable to a random string (the OpenAI api key is NOT required!)
Set OPENAI_API_BASE to point to your LocalAI service, for example OPENAI_API_BASE=http://localhost:8080
Advanced
It is possible to also specify the full function signature (for debugging, or to use with other clients).
The chat endpoint accepts the grammar_json_functions additional parameter which takes a JSON schema object.
aplay is a Linux command. You can use other tools to play the audio file.
The model name is the filename with the extension.
The model name is case sensitive.
LocalAI must be compiled with the GO_TAGS=tts flag.
LocalAI also has experimental support for transformers-musicgen for the generation of short musical compositions. Currently, this is implemented via the same requests used for text to speech:
The sentencetransformers backend is an optional backend of LocalAI and uses Python. If you are running LocalAI from the containers you are good to go and should be already configured for use.
If you are running LocalAI manually you must install the python dependencies (make prepare-extra-conda-environments). This requires conda to be installed.
For local execution, you also have to specify the extra backend in the EXTERNAL_GRPC_BACKENDS environment variable.
The sentencetransformers backend does support only embeddings of text, and not of tokens. If you need to embed tokens you can use the bert backend or llama.cpp.
No models are required to be downloaded before using the sentencetransformers backend. The models will be downloaded automatically the first time the API is used.
Llama.cpp embeddings
Embeddings with llama.cpp are supported with the llama backend.
Example that uses LLamaIndex and LocalAI as embedding: here.
βοΈ Constrained grammars
The chat endpoint accepts an additional grammar parameter which takes a BNF defined grammar.
This allows the LLM to constrain the output to a user-defined schema, allowing to generate JSON, YAML, and everything that can be defined with a BNF grammar.
LocalAI will attempt to automatically load models which are not explicitly configured for a specific backend. You can specify the backend to use by configuring a model with a YAML file. See the advanced section for more details.
Hardware requirements
Depending on the model you are attempting to run might need more RAM or CPU resources. Check out also here for gguf based backends. rwkv is less expensive on resources.
Model compatibility table
Besides llama based models, LocalAI is compatible also with other architectures. The table below lists all the compatible models families and the associated binding repository.
Note: You might need to convert some models from older models to the new format, for indications, see the README in llama.cpp for instance to run gpt4all.
Subsections of Model compatibility
RWKV
A full example on how to run a rwkv model is in the examples.
Note: rwkv models needs to specify the backend rwkv in the YAML config files and have an associated tokenizer along that needs to be provided with it:
36464540 -rw-r--r-- 1 mudler mudler 1.2G May 3 10:51 rwkv_small
36464543 -rw-r--r-- 1 mudler mudler 2.4M May 3 10:51 rwkv_small.tokenizer.json
π¦ llama.cpp
llama.cpp is a popular port of Facebook’s LLaMA model in C/C++.
Note
The ggml file format has been deprecated. If you are using ggml models and you are configuring your model with a YAML file, specify, use the llama-stable backend instead. If you are relying in automatic detection of the model, you should be fine. For gguf models, use the llama backend.
Features
The llama.cpp model supports the following features:
Prompt templates are useful for models that are fine-tuned towards a specific prompt.
Automatic setup
LocalAI supports model galleries which are indexes of models. For instance, the huggingface gallery contains a large curated index of models from the huggingface model hub for ggml or gguf models.
For instance, if you have the galleries enabled, you can just start chatting with models in huggingface by running:
curl http://localhost:8080/v1/chat/completions -H "Content-Type: application/json" -d '{
"model": "TheBloke/WizardLM-13B-V1.2-GGML/wizardlm-13b-v1.2.ggmlv3.q2_K.bin",
"messages": [{"role": "user", "content": "Say this is a test!"}],
"temperature": 0.1
}'
LocalAI will automatically download and configure the model in the model directory.
Models can be also preloaded or downloaded on demand. To learn about model galleries, check out the model gallery documentation.
YAML configuration
To use the llama.cpp backend, specify llama as the backend in the YAML file:
name:llamabackend:llamaparameters:# Relative to the models pathmodel:file.gguf.bin
In the example above we specify llama as the backend to restrict loading gguf models only.
For instance, to use the llama-stable backend for ggml models:
name:llamabackend:llama-stableparameters:# Relative to the models pathmodel:file.ggml.bin
Exllama is a “A more memory-efficient rewrite of the HF transformers implementation of Llama for use with quantized weights”
Prerequisites
This is an extra backend - in the container images is already available and there is nothing to do for the setup.
If you are building LocalAI locally, you need to install exllama manually first.
Model setup
Download the model as a folder inside the model directory and create a YAML file specifying the exllama backend. For instance with the TheBloke/WizardLM-7B-uncensored-GPTQ model:
AutoGPTQ is an easy-to-use LLMs quantization package with user-friendly apis, based on GPTQ algorithm.
Prerequisites
This is an extra backend - in the container images is already available and there is nothing to do for the setup.
If you are building LocalAI locally, you need to install AutoGPTQ manually.
Model setup
The models are automatically downloaded from huggingface if not present the first time. It is possible to define models via YAML config file, or just by querying the endpoint with the huggingface repository model name. For example, create a YAML config file in models/:
VALL-E-X is an open source implementation of Microsoft’s VALL-E X zero-shot TTS model.
Setup
The backend will automatically download the required files in order to run the model.
This is an extra backend - in the container is already available and there is nothing to do for the setup. If you are building manually, you need to install Vall-E-X manually first.
Usage
Use the tts endpoint by specifying the vall-e-x backend:
In order to use voice cloning capabilities you must create a YAML configuration file to setup a model:
name:cloned-voicebackend:vall-e-xparameters:model:"cloned-voice"vall-e:# The path to the audio file to be cloned# relative to the models directory audio_path:"path-to-wav-source.wav"
Then you can specify the model name in the requests:
vLLM is a fast and easy-to-use library for LLM inference.
LocalAI has a built-in integration with vLLM, and it can be used to run models. You can check out vllm performance here.
Setup
Create a YAML file for the model you want to use with vllm.
To setup a model, you need to just specify the model name in the YAML config file:
name:vllmbackend:vllmparameters:model:"facebook/opt-125m"# Decomment to specify a quantization method (optional)# quantization: "awq"
The backend will automatically download the required files in order to run the model.
Usage
Use the completions endpoint by specifying the vllm backend:
curl http://localhost:8080/v1/completions -H "Content-Type: application/json" -d '{
"model": "vllm",
"prompt": "Hello, my name is",
"temperature": 0.1, "top_p": 0.1
}'
𧨠Diffusers
Diffusers is the go-to library for state-of-the-art pretrained diffusion models for generating images, audio, and even 3D structures of molecules. LocalAI has a diffusers backend which allows image generation using the diffusers library.
Note: currently only the image generation is supported. It is experimental, so you might encounter some issues on models which weren’t tested yet.
Setup
This is an extra backend - in the container is already available and there is nothing to do for the setup.
Model setup
The models will be downloaded the first time you use the backend from huggingface automatically.
Create a model configuration file in the models directory, for instance to use Linaqruf/animagine-xl with CPU:
name:animagine-xlparameters:model:Linaqruf/animagine-xlbackend:diffusers# Force CPU usage - set to true for GPUf16:falsediffusers:pipeline_type:StableDiffusionXLPipelinecuda:false# Enable for GPU usage (CUDA)scheduler_type:euler_a
Local models
You can also use local models, or modify some parameters like clip_skip, scheduler_type, for instance:
name:stablediffusion-depthparameters:model:stabilityai/stable-diffusion-2-depthbackend:diffusersstep:50# Force CPU usagef16:truediffusers:pipeline_type:StableDiffusionDepth2ImgPipelinecuda:trueenable_parameters:"negative_prompt,num_inference_steps,image"cfg_scale:6
In order to build the LocalAI container image locally you can use docker:
# build the image
docker build -t localai .
docker run localai
Or you can build the manually binary with make:
git clone https://github.com/go-skynet/LocalAI
cd LocalAI
make build
To run: ./local-ai
Note
CPU flagset compatibility
LocalAI uses different backends based on ggml and llama.cpp to run models. If your CPU doesn’t support common instruction sets, you can disable them during build:
CMAKE_ARGS="-DLLAMA_F16C=OFF -DLLAMA_AVX512=OFF -DLLAMA_AVX2=OFF -DLLAMA_AVX=OFF -DLLAMA_FMA=OFF" make build
To have effect on the container image, you need to set REBUILD=true:
make BUILD_TYPE=metal build
# Set `gpu_layers: 1` to your YAML model config file and `f16: true`
# Note: only models quantized with q4_0 are supported!
In order to define default prompts, model parameters (such as custom default top_p or top_k), LocalAI can be configured to serve user-defined models with a set of default parameters and templates.
You can create multiple yaml files in the models path or either specify a single YAML configuration file.
Consider the following models folder in the example/chatbot-ui:
In the gpt-3.5-turbo.yaml file it is defined the gpt-3.5-turbo model which is an alias to use luna-ai-llama2 with pre-defined options.
For instance, consider the following that declares gpt-3.5-turbo backed by the luna-ai-llama2 model:
name:gpt-3.5-turbo# Default model parametersparameters:# Relative to the models pathmodel:luna-ai-llama2-uncensored.ggmlv3.q5_K_M.bin# temperaturetemperature:0.3# all the OpenAI request options here..# Default context sizecontext_size:512threads:10# Define a backend (optional). By default it will try to guess the backend the first time the model is interacted with.backend: llama-stable # available:llama, stablelm, gpt2, gptj rwkv# Enable prompt cachingprompt_cache_path:"alpaca-cache"prompt_cache_all:true# stopwords (if supported by the backend)stopwords:- "HUMAN:"- "### Response:"# define chat rolesroles:assistant:'### Response:'system:'### System Instruction:'user:'### Instruction:'template:# template file ".tmpl" with the prompt template to use by default on the endpoint call. Note there is no extension in the filescompletion:completionchat:chat
Specifying a config-file via CLI allows to declare models in a single file as a list, for instance:
See also chatbot-ui as an example on how to use config files.
Full config model file reference
# Model name.# The model name is used to identify the model in the API calls.name:gpt-3.5-turbo# Default model parameters.# These options can also be specified in the API callsparameters:# Relative to the models pathmodel:luna-ai-llama2-uncensored.ggmlv3.q5_K_M.bin# temperaturetemperature:0.3# all the OpenAI request options here..top_k:top_p:max_tokens:ignore_eos:truen_keep:10seed:mode:step:negative_prompt:typical_p:tfz:frequency_penalty:mirostat_eta:mirostat_tau:mirostat:rope_freq_base:rope_freq_scale:negative_prompt_scale:# Default context sizecontext_size:512# Default number of threadsthreads:10# Define a backend (optional). By default it will try to guess the backend the first time the model is interacted with.backend: llama-stable # available:llama, stablelm, gpt2, gptj rwkv# stopwords (if supported by the backend)stopwords:- "HUMAN:"- "### Response:"# string to trim space totrimspace:- string# Strings to cut from the responsecutstrings:- "string"# Directory used to store additional assetsasset_dir:""# define chat rolesroles:user:"HUMAN:"system:"GPT:"assistant:"ASSISTANT:"template:# template file ".tmpl" with the prompt template to use by default on the endpoint call. Note there is no extension in the filescompletion:completionchat:chatedit:edit_templatefunction:function_templatefunction:disable_no_action:trueno_action_function_name:"reply"no_action_description_name:"Reply to the AI assistant"system_prompt:rms_norm_eps:# Set it to 8 for llama2 70bngqa:1## LLAMA specific options# Enable F16 if backend supports itf16:true# Enable debuggingdebug:true# Enable embeddingsembeddings:true# Mirostat configuration (llama.cpp only)mirostat_eta:0.8mirostat_tau:0.9mirostat:1# GPU Layers (only used when built with cublas)gpu_layers:22# Enable memory lockmmlock:true# GPU setting to split the tensor in multiple parts and define a main GPU# see llama.cpp for usagetensor_split:""main_gpu:""# Define a prompt cache path (relative to the models)prompt_cache_path:"prompt-cache"# Cache all the promptsprompt_cache_all:true# Read onlyprompt_cache_ro:false# Enable mmapmmap:true# Enable low vram mode (GPU only)low_vram:true# Set NUMA mode (CPU only)numa:true# Lora settingslora_adapter:"/path/to/lora/adapter"lora_base:"/path/to/lora/base"# Disable mulmatq (CUDA)no_mulmatq:true# Diffusers/transformerscuda:true
You can use a default template for every model present in your model path, by creating a corresponding file with the `.tmpl` suffix next to your model. For instance, if the model is called `foo.bin`, you can create a sibling file, `foo.bin.tmpl` which will be used as a default prompt and can be used with alpaca:
The below instruction describes a task. Write a response that appropriately completes the request.
### Instruction:
{{.Input}}
### Response:
See the prompt-templates directory in this repository for templates for some of the most popular models.
For the edit endpoint, an example template for alpaca-based models can be:
Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.### Instruction:{{.Instruction}}### Input:{{.Input}}### Response:
Install models using the API
Instead of installing models manually, you can use the LocalAI API endpoints and a model definition to install programmatically via API models in runtime.
A curated collection of model files is in the model-gallery (work in progress!). The files of the model gallery are different from the model files used to configure LocalAI models. The model gallery files contains information about the model setup, and the files necessary to run the model locally.
To install for example lunademo, you can send a POST call to the /models/apply endpoint with the model definition url (url) and the name of the model should have in LocalAI (name, optional):
PRELOAD_MODELS (or --preload-models) takes a list in JSON with the same parameter of the API calls of the /models/apply endpoint.
Similarly it can be specified a path to a YAML configuration file containing a list of models with PRELOAD_MODELS_CONFIG ( or --preload-models-config ):
LocalAI can automatically cache prompts for faster loading of the prompt. This can be useful if your model need a prompt template with prefixed text in the prompt before the input.
To enable prompt caching, you can control the settings in the model config YAML file:
prompt_cache_path is relative to the models folder. you can enter here a name for the file that will be automatically create during the first load if prompt_cache_all is set to true.
Configuring a specific backend for the model
By default LocalAI will try to autoload the model by trying all the backends. This might work for most of models, but some of the backends are NOT configured to autoload.
In order to specify a backend for your models, create a model config file in your models directory specifying the backend:
name:gpt-3.5-turbo# Default model parametersparameters:# Relative to the models pathmodel:...backend:llama-stable# ...
Connect external backends
LocalAI backends are internally implemented using gRPC services. This also allows LocalAI to connect to external gRPC services on start and extend LocalAI functionalities via third-party binaries.
The --external-grpc-backends parameter in the CLI can be used either to specify a local backend (a file) or a remote URL. The syntax is <BACKEND_NAME>:<BACKEND_URI>. Once LocalAI is started with it, the new backend name will be available for all the API endpoints.
So for instance, to register a new backend which is a local file:
When LocalAI runs in a container,
there are additional environment variables available that modify the behavior of LocalAI on startup:
Environment variable
Default
Description
REBUILD
false
Rebuild LocalAI on startup
BUILD_TYPE
Build type. Available: cublas, openblas, clblas
GO_TAGS
Go tags. Available: stablediffusion
HUGGINGFACEHUB_API_TOKEN
Special token for interacting with HuggingFace Inference API, required only when using the langchain-huggingface backend
EXTRA_BACKENDS
A space separated list of backends to prepare. For example EXTRA_BACKENDS="backend/python/diffusers backend/python/transformers" prepares the conda environment on start
Here is how to configure these variables:
# Option 1: command linedocker run --env REBUILD=true localai
# Option 2: set within an env filedocker run --env-file .env localai
Build only a single backend
You can control the backends that are built by setting the GRPC_BACKENDS environment variable. For instance, to build only the llama-cpp backend only:
make GRPC_BACKENDS=backend-assets/grpc/llama-cpp build
By default, all the backends are built.
Extra backends
LocalAI can be extended with extra backends. The backends are implemented as gRPC services and can be written in any language. The container images that are built and published on quay.io contain a set of images split in core and extra. By default Images bring all the dependencies and backends supported by LocalAI (we call those extra images). The -core images instead bring only the strictly necessary dependencies to run LocalAI without only a core set of backends.
If you wish to build a custom container image with extra backends, you can use the core images and build only the backends you are interested into or prepare the environment on startup by using the EXTRA_BACKENDS environment variable. For instance, to use the diffusers backend:
FROM quay.io/go-skynet/local-ai:master-ffmpeg-coreRUNPATH=$PATH:/opt/conda/bin make -C backend/python/diffusers
Remember also to set the EXTERNAL_GRPC_BACKENDS environment variable (or --external-grpc-backends as CLI flag) to point to the backends you are using (EXTERNAL_GRPC_BACKENDS="backend_name:/path/to/backend"), for example with diffusers:
FROM quay.io/go-skynet/local-ai:master-ffmpeg-coreRUNPATH=$PATH:/opt/conda/bin make -C backend/python/diffusersENVEXTERNAL_GRPC_BACKENDS="diffusers:/build/backend/python/diffusers/run.sh"
Note
You can specify remote external backends or path to local files. The syntax is backend-name:/path/to/backend or backend-name:host:port.
In runtime
When using the -core container image it is possible to prepare the python backends you are interested into by using the EXTRA_BACKENDS variable, for instance:
docker run --env EXTRA_BACKENDS="backend/python/diffusers" quay.io/go-skynet/local-ai:master-ffmpeg-core
Subsections of Advanced
Fine-tuning LLMs for text generation
Note
Section under construction
This section covers how to fine-tune a language model for text generation and consume it in LocalAI.
Requirements
For this example you will need at least a 12GB VRAM of GPU and a Linux box.
Fine-tuning
Fine-tuning a language model is a process that requires a lot of computational power and time.
Currently LocalAI doesn’t support the fine-tuning endpoint as LocalAI but there are are plans to support that. For the time being a guide is proposed here to give a simple starting point on how to fine-tune a model and use it with LocalAI (but also with llama.cpp).
There is an e2e example of fine-tuning a LLM model to use with LocalAI written by @mudler available here.
The steps involved are:
Preparing a dataset
Prepare the environment and install dependencies
Fine-tune the model
Merge the Lora base with the model
Convert the model to gguf
Use the model with LocalAI
Dataset preparation
We are going to need a dataset or a set of datasets.
Axolotl supports a variety of formats, in the notebook and in this example we are aiming for a very simple dataset and build that manually, so we are going to use the completion format which requires the full text to be used for fine-tuning.
A dataset for an instructor model (like Alpaca) can look like the following:
[{"text":"As an AI language model you are trained to reply to an instruction. Try to be as much polite as possible\n\n## Instruction\n\nWrite a poem about a tree.\n\n## Response\n\nTrees are beautiful, ...",},{"text":"As an AI language model you are trained to reply to an instruction. Try to be as much polite as possible\n\n## Instruction\n\nWrite a poem about a tree.\n\n## Response\n\nTrees are beautiful, ...",}]
Every block in the text is the whole text that is used to fine-tune. For example, for an instructor model it follows the following format (more or less):
<System prompt>
## Instruction
<Question, instruction>
## Response
<Expected response from the LLM>
The instruction format works such as when we are going to inference with the model, we are going to feed it only the first part up to the ## Instruction block, and the model is going to complete the text with the ## Response block.
Prepare a dataset, and upload it to your Google Drive in case you are using the Google colab. Otherwise place it next the axolotl.yaml file as dataset.json.
We will need to configure axolotl. In this example is provided a file to use axolotl.yaml that uses openllama-3b for fine-tuning. Copy the axolotl.yaml file and edit it to your needs. The dataset needs to be next to it as dataset.json. You can find the axolotl.yaml file here.
If you have a big dataset, you can pre-tokenize it to speedup the fine-tuning process:
# Optional pre-tokenize (run only if big dataset)python -m axolotl.cli.preprocess axolotl.yaml
Now we are ready to start the fine-tuning process:
And we convert it to the gguf format that LocalAI can consume:
# Convert to ggufgit clone https://github.com/ggerganov/llama.cpp.git
pushd llama.cpp && make LLAMA_CUBLAS=1&&popd# We need to convert the pytorch model into ggml for quantization# It crates 'ggml-model-f16.bin' in the 'merged' directory.pushd llama.cpp && python convert.py --outtype f16 \
../qlora-out/merged/pytorch_model-00001-of-00002.bin &&popd# Start off by making a basic q4_0 4-bit quantization.# It's important to have 'ggml' in the name of the quant for some# software to recognize it's file format.pushd llama.cpp && ./quantize ../qlora-out/merged/ggml-model-f16.gguf \
../custom-model-q4_0.bin q4_0
Now you should have ended up with a custom-model-q4_0.bin file that you can copy in the LocalAI models directory and use it with LocalAI.
Development documentation
Note
This section is for developers and contributors. If you are looking for the user documentation, this is not the right place!
This section will collect how-to, notes and development documentation
Contributing
We use conventional commits and semantic versioning. Please follow the conventional commits specification when writing commit messages.
Creating a gRPC backend
LocalAI backends are gRPC servers.
In order to create a new backend you need:
If there are changes required to the protobuf code, modify the proto file and re-generate the code with make protogen.
Modify the Makefile to add your new backend and re-generate the client code with make protogen if necessary.
Create a new gRPC server in extra/grpc if it’s not written in go: link, and create the specific implementation.
Golang gRPC servers should be added in the pkg/backend directory given their type. See piper as an example.
Golang servers needs a respective cmd/grpc binary that must be created too, see also cmd/grpc/piper as an example, update also the Makefile accordingly to build the binary during build time.
Update the Dockerfile: if the backend is written in another language, update the Dockerfile default EXTERNAL_GRPC_BACKENDS variable by listing the new binary link.
Once you are done, you can either re-build LocalAI with your backend or you can try it out by running the gRPC server manually and specifying the host and IP to LocalAI with --external-grpc-backends or using (EXTERNAL_GRPC_BACKENDS environment variable, comma separated list of name:host:port tuples, e.g. my-awesome-backend:host:port):
The model gallery is a (experimental!) collection of models configurations for LocalAI.
LocalAI to ease out installations of models provide a way to preload models on start and downloading and installing them in runtime. You can install models manually by copying them over the models directory, or use the API to configure, download and verify the model assets for you. As the UI is still a work in progress, you will find here the documentation about the API Endpoints.
Note
The models in this gallery are not directly maintained by LocalAI. If you find a model that is not working, please open an issue on the model gallery repository.
Note
GPT and text generation models might have a license which is not permissive for commercial use or might be questionable or without any license at all. Please check the model license before using it. The official gallery contains only open licensed models.
Useful Links and resources
Open LLM Leaderboard - here you can find a list of the most performing models on the Open LLM benchmark. Keep in mind models compatible with LocalAI must be quantized in the gguf format.
Model repositories
You can install a model in runtime, while the API is running and it is started already, or before starting the API by preloading the models.
To install a model in runtime you will need to use the /models/apply LocalAI API endpoint.
To enable the model-gallery repository you need to start local-ai with the GALLERIES environment variable:
where github:go-skynet/model-gallery/index.yaml will be expanded automatically to https://raw.githubusercontent.com/go-skynet/model-gallery/main/index.yaml.
Note
As this feature is experimental, you need to run local-ai with a list of GALLERIES. Currently there are two galleries:
An official one, containing only definitions and models with a clear LICENSE to avoid any dmca infringment. As I’m not sure what’s the best action to do in this case, I’m not going to include any model that is not clearly licensed in this repository which is offically linked to LocalAI.
A “community” one that contains an index of huggingface models that are compatible with the ggml format and lives in the localai-huggingface-zoo repository.
To enable the two repositories, start LocalAI with the GALLERIES environment variable:
If running with docker-compose, simply edit the .env file and uncomment the GALLERIES variable, and add the one you want to use.
Note
You might not find all the models in this gallery. Automated CI updates the gallery automatically. You can find however most of the models on huggingface (https://huggingface.co/), generally it should be available ~24h after upload.
By under any circumstances LocalAI and any developer is not responsible for the models in this gallery, as CI is just indexing them and providing a convenient way to install with an automatic configuration with a consistent API. Don’t install models from authors you don’t trust, and, check the appropriate license for your use case. Models are automatically indexed and hosted on huggingface (https://huggingface.co/). For any issue with the models, please open an issue on the model gallery repository if it’s a LocalAI misconfiguration, otherwise refer to the huggingface repository. If you think a model should not be listed, please reach to us and we will remove it from the gallery.
Note
There is no documentation yet on how to build a gallery or a repository - but you can find an example in the model-gallery repository.
List Models
To list all the available models, use the /models/available endpoint:
curl http://localhost:8080/models/available
To search for a model, you can use jq:
# Get all information about models with a name that contains "replit"curl http://localhost:8080/models/available | jq '.[] | select(.name | contains("replit"))'# Get the binary name of all local models (not hosted on Hugging Face)curl http://localhost:8080/models/available | jq '.[] | .name | select(contains("localmodels"))'# Get all of the model URLs that contains "orca"curl http://localhost:8080/models/available | jq '.[] | .urls | select(. != null) | add | select(contains("orca"))'
How to install a model from the repositories
Models can be installed by passing the full URL of the YAML config file, or either an identifier of the model in the gallery. The gallery is a repository of models that can be installed by passing the model name.
To install a model from the gallery repository, you can pass the model name in the id field. For instance, to install the bert-embeddings model, you can use the following command:
model-gallery is the repository. It is optional and can be omitted. If the repository is omitted LocalAI will search the model by name in all the repositories. In the case the same model name is present in both galleries the first match wins.
bert-embeddings is the model name in the gallery
(read its config here).
Note
If the huggingface model gallery is enabled (it’s enabled by default),
and the model has an entry in the model gallery’s associated YAML config
(for huggingface, see model-gallery/huggingface.yaml),
you can install models by specifying directly the model’s id.
For example, to install wizardlm superhot:
Note that the id can be used similarly when pre-loading models at start.
How to install a model (without a gallery)
If you don’t want to set any gallery repository, you can still install models by loading a model configuration file.
In the body of the request you must specify the model configuration file URL (url), optionally a name to install the model (name), extra files to install (files), and configuration overrides (overrides). When calling the API endpoint, LocalAI will download the models files and write the configuration to the folder used to store models.
LOCALAI=http://localhost:8080
curl $LOCALAI/models/apply -H "Content-Type: application/json" -d '{
"url": "<MODEL_CONFIG_FILE>"
}'# or if from a repositorycurl $LOCALAI/models/apply -H "Content-Type: application/json" -d '{
"id": "<GALLERY>@<MODEL_NAME>"
}'
To preload models on start instead you can use the PRELOAD_MODELS environment variable.
To preload models on start, use the PRELOAD_MODELS environment variable by setting it to a JSON array of model uri:
PRELOAD_MODELS='[{"url": "<MODEL_URL>"}]'
Note: url or id must be specified. url is used to a url to a model gallery configuration, while an id is used to refer to models inside repositories. If both are specified, the id will be used.
While the API is running, you can install the model by using the /models/apply endpoint and point it to the stablediffusion model in the models-gallery:
LocalAI will create a batch process that downloads the required files from a model definition and automatically reload itself to include the new model.
Input: url or id (required), name (optional), files (optional)
An optional, list of additional files can be specified to be downloaded within files. The name allows to override the model name. Finally it is possible to override the model config file with override.
The url is a full URL, or a github url (github:org/repo/file.yaml), or a local file (file:///path/to/file.yaml).
The id is a string in the form <GALLERY>@<MODEL_NAME>, where <GALLERY> is the name of the gallery, and <MODEL_NAME> is the name of the model in the gallery. Galleries can be specified during startup with the GALLERIES environment variable.
Returns an uuid and an url to follow up the state of the process:
AIKit is a quick, easy, and local or cloud-agnostic way to get started to host and deploy large language models (LLMs) for inference. No GPU, internet access or additional tools are needed to get started except for Docker!
AIKit uses LocalAI under-the-hood to run inference. LocalAI provides a drop-in replacement REST API that is OpenAI API compatible, so you can use any OpenAI API compatible client, such as Kubectl AI, Chatbot-UI and many more, to send requests to open-source LLMs powered by AIKit!
At this time, AIKit is tested with LocalAI llama backend. Other backends may work but are not tested. Please open an issue if you’d like to see support for other backends.
Features
π³ No GPU, Internet access or additional tools needed except for Docker!
π€ Minimal image size, resulting in less vulnerabilities and smaller attack surface with a custom distroless-based image
π Easy to use declarative configuration
β¨ OpenAI API compatible to use with any OpenAI API compatible client
π’ Kubernetes deployment ready
π¦ Supports multiple models with a single image
π₯οΈ Supports GPU-accelerated inferencing with NVIDIA GPUs
π Signed images for aikit and pre-made models
Pre-made Models
AIKit comes with pre-made models that you can use out-of-the-box!
This will build a local container image with your model(s). You can see the image with:
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
my-model latest e7b7c5a4a2cb About an hour ago 5.51GB
Running models
You can start the inferencing server for your models with:
# for pre-made models, replace "my-model" with the image namedocker run -d --rm -p 8080:8080 my-model
You can then send requests to localhost:8080 to run inference from your models. For example:
curl http://localhost:8080/v1/chat/completions -H "Content-Type: application/json" -d '{
"model": "llama-2-7b-chat",
"messages": [{"role": "user", "content": "explain kubernetes in a sentence"}]
}'{"created":1701236489,"object":"chat.completion","id":"dd1ff40b-31a7-4418-9e32-42151ab6875a","model":"llama-2-7b-chat","choices":[{"index":0,"finish_reason":"stop","message":{"role":"assistant","content":"\nKubernetes is a container orchestration system that automates the deployment, scaling, and management of containerized applications in a microservices architecture."}}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}
Kubernetes Deployment
It is easy to get started to deploy your models to Kubernetes!
Make sure you have a Kubernetes cluster running and kubectl is configured to talk to it, and your model images are accessible from the cluster.
You can use kind to create a local Kubernetes cluster for testing purposes.
# create a deployment# for pre-made models, replace "my-model" with the image namekubectl create deployment my-llm-deployment --image=my-model
# expose it as a servicekubectl expose deployment my-llm-deployment --port=8080 --target-port=8080 --name=my-llm-service
# easy to scale up and down as neededkubectl scale deployment my-llm-deployment --replicas=3# port-forward for testing locallykubectl port-forward service/my-llm-service 8080:8080
# send requests to your modelcurl http://localhost:8080/v1/chat/completions -H "Content-Type: application/json" -d '{
"model": "llama-2-7b-chat",
"messages": [{"role": "user", "content": "explain kubernetes in a sentence"}]
}'{"created":1701236489,"object":"chat.completion","id":"dd1ff40b-31a7-4418-9e32-42151ab6875a","model":"llama-2-7b-chat","choices":[{"index":0,"finish_reason":"stop","message":{"role":"assistant","content":"\nKubernetes is a container orchestration system that automates the deployment, scaling, and management of containerized applications in a microservices architecture."}}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}
For an example Kubernetes deployment and service YAML, see kubernetes folder. Please note that these are examples, you may need to customize them (such as properly configured resource requests and limits) based on your needs.
GPU Acceleration Support
At this time, only NVIDIA GPU acceleration is supported. Please open an issue if you’d like to see support for other GPU vendors.
For Kubernetes, NVIDIA GPU Operator provides a streamlined way to install the NVIDIA drivers and container toolkit to configure your cluster to use GPUs.
To get started with GPU-accelerated inferencing, make sure to set the following in your aikitfile and build your model.
runtime:cuda # use NVIDIA CUDA runtimef16:true# use float16 precisiongpu_layers:35# number of layers to offload to GPUlow_vram:true# for devices with low VRAM
Make sure to customize these values based on your model and GPU specs.
After building the model, you can run it with --gpus all flag to enable GPU support:
# for pre-made models, replace "my-model" with the image namedocker run --rm --gpus all -p 8080:8080 my-model
If GPU acceleration is working, you’ll see output that is similar to following in the debug logs:
5:32AM DBG GRPC(llama-2-7b-chat.Q4_K_M.gguf-127.0.0.1:43735): stderr ggml_init_cublas: found 1 CUDA devices:
5:32AM DBG GRPC(llama-2-7b-chat.Q4_K_M.gguf-127.0.0.1:43735): stderr Device 0: Tesla T4, compute capability 7.5
...
5:32AM DBG GRPC(llama-2-7b-chat.Q4_K_M.gguf-127.0.0.1:43735): stderr llm_load_tensors: using CUDA for GPU acceleration
5:32AM DBG GRPC(llama-2-7b-chat.Q4_K_M.gguf-127.0.0.1:43735): stderr llm_load_tensors: mem required= 70.41 MB (+ 2048.00 MB per state)5:32AM DBG GRPC(llama-2-7b-chat.Q4_K_M.gguf-127.0.0.1:43735): stderr llm_load_tensors: offloading 32 repeating layers to GPU
5:32AM DBG GRPC(llama-2-7b-chat.Q4_K_M.gguf-127.0.0.1:43735): stderr llm_load_tensors: offloading non-repeating layers to GPU
5:32AM DBG GRPC(llama-2-7b-chat.Q4_K_M.gguf-127.0.0.1:43735): stderr llm_load_tensors: offloading v cache to GPU
5:32AM DBG GRPC(llama-2-7b-chat.Q4_K_M.gguf-127.0.0.1:43735): stderr llm_load_tensors: offloading k cache to GPU
5:32AM DBG GRPC(llama-2-7b-chat.Q4_K_M.gguf-127.0.0.1:43735): stderr llm_load_tensors: offloaded 35/35 layers to GPU
5:32AM DBG GRPC(llama-2-7b-chat.Q4_K_M.gguf-127.0.0.1:43735): stderr llm_load_tensors: VRAM used: 5869 MB
AnythingLLM
AnythingLLM is an open source ChatGPT equivalent tool for chatting with documents and more in a secure environment by Mintplex Labs Inc.
Chat with your LocalAI models (or hosted models like OpenAi, Anthropic, and Azure)
Embed documents (txt, pdf, json, and more) using your LocalAI Sentence Transformers
Select any vector database you want (Chroma, Pinecone, qDrant, Weaviate ) or use the embedded on-instance vector database (LanceDB)
Supports single or multi-user tenancy with built-in permissions
Full developer API
Locally running SQLite db for minimal setup.
AnythingLLM is a fully transparent tool to deliver a customized, white-label ChatGPT equivalent experience using only the models and services you or your organization are comfortable using.
Why AnythingLLM?
AnythingLLM aims to enable you to quickly and comfortably get a ChatGPT equivalent experience using your proprietary documents for your organization with zero compromise on security or comfort.
What does AnythingLLM include?
Full UI
Full admin console and panel for managing users, chats, model selection, vector db connection, and embedder selection
Multi-user support and logins
Supports both desktop and mobile view ports
Built in vector database where no data leaves your instance at all
Docker support
Install
Local via docker
Running via docker and integrating with your LocalAI instance is a breeze.
First, pull in the latest AnythingLLM Docker image
docker pull mintplexlabs/anythingllm:master
Next, run the image on a container exposing port 3001.
docker run -d -p 3001:3001 mintplexlabs/anythingllm:master
Now open http://localhost:3001 and you will start on-boarding for setting up your AnythingLLM instance to your comfort level
Integration with your LocalAI instance.
There are two areas where you can leverage your models loaded into LocalAI - LLM and Embedding. Any LLM models should be ready to run a chat completion.
LLM model selection
During onboarding and from the sidebar setting you can select LocalAI as your LLM. Here you can set both the model and token limit of the specific model. The dropdown will automatically populate once your url is set.
The URL should look like http://localhost:8000/v1 or wherever your LocalAI instance is being served from. Non-localhost URLs are permitted if hosting LocalAI on cloud services.
LLM embedding model selection
During onboarding and from the sidebar setting you can select LocalAI as your preferred embedding engine. This model will be the model used when you upload any kind of document via AnythingLLM. Here you can set the model from available models via the LocalAI API. The dropdown will automatically populate once your url is set.
The URL should look like http://localhost:8000/v1 or wherever your LocalAI instance is being served from. Non-localhost URLs are permitted if hosting LocalAI on cloud services.
AutoGPT4all
AutoGPT4All provides you with both bash and python scripts to set up and configure AutoGPT running with the GPT4All model on the LocalAI server. This setup allows you to run queries against an open-source licensed model without any limits, completely free and offline.
git clone https://github.com/aorumbayev/autogpt4all.git
cd autogpt4all
chmod +x autogpt4all.sh
./autogpt4all.sh
Using Python Script:
Make sure you have Python installed on your machine.
git clone https://github.com/aorumbayev/autogpt4all.git
cd autogpt4all
python autogpt4all.py
βοΈ Please note this script has been primarily tested on MacOS with an M1 processor. It should work on Linux and Windows, but it has not been thoroughly tested on these platforms. If not on MacOS install git, go and make before running the script.
--uninstall - Uninstall the projects from your local machine.
Example:
python autogpt4all.py --uninstall
BionicGPT
an on-premise replacement for ChatGPT, offering the advantages of Generative AI while maintaining strict data confidentiality, BionicGPT can run on your laptop or scale into the data center.
Cut and paste the following into a docker-compose.yaml file and run docker-compose up -d access the user interface on http://localhost:7800/auth/sign_up
This has been tested on an AMD 2700x with 16GB of ram. The included ggml-gpt4all-j model runs on CPU only.
Warning - The images in this docker-compose are large due to having the model weights pre-loaded for convenience.
services:# LocalAI with pre-loaded ggml-gpt4all-jlocal-ai:image:ghcr.io/purton-tech/bionicgpt-model-api:llama-2-7b-chat# Handles parsing of multiple documents types.unstructured:image:downloads.unstructured.io/unstructured-io/unstructured-api:db264d8ports:- "8000:8000"# Handles routing between the application, barricade and the LLM APIenvoy:image:ghcr.io/purton-tech/bionicgpt-envoy:1.1.10ports:- "7800:7700"# Postgres pre-loaded with pgVectordb:image:ankane/pgvectorenvironment:POSTGRES_PASSWORD:testpasswordPOSTGRES_USER:postgresPOSTGRES_DB:finetunahealthcheck:test:["CMD-SHELL","pg_isready -U postgres"]interval:10stimeout:5sretries:5# Sets up our database tablesmigrations:image:ghcr.io/purton-tech/bionicgpt-db-migrations:1.1.10environment:DATABASE_URL:postgresql://postgres:testpassword@db:5432/postgres?sslmode=disabledepends_on:db:condition:service_healthy# Barricade handles all /auth routes for user sign up and sign in.barricade:image:purtontech/barricadeenvironment:# This secret key is used to encrypt cookies.SECRET_KEY:190a5bf4b3cbb6c0991967ab1c48ab30790af876720f1835cbbf3820f4f5d949DATABASE_URL:postgresql://postgres:testpassword@db:5432/postgres?sslmode=disableFORWARD_URL:appFORWARD_PORT:7703REDIRECT_URL:/app/post_registrationdepends_on:db:condition:service_healthymigrations:condition:service_completed_successfully# Our axum server delivering our user interfaceembeddings-job:image:ghcr.io/purton-tech/bionicgpt-embeddings-job:1.1.10environment:APP_DATABASE_URL:postgresql://ft_application:testpassword@db:5432/postgres?sslmode=disabledepends_on:db:condition:service_healthymigrations:condition:service_completed_successfully# Our axum server delivering our user interfaceapp:image:ghcr.io/purton-tech/bionicgpt:1.1.10environment:APP_DATABASE_URL:postgresql://ft_application:testpassword@db:5432/postgres?sslmode=disabledepends_on:db:condition:service_healthymigrations:condition:service_completed_successfully
Kubernetes Ready
BionicGPT is optimized to run on Kubernetes and implements the full pipeline of LLM fine tuning from data acquisition to user interface.
BMO Chatbo
Generate and brainstorm ideas while creating your notes using Large Language Models (LLMs) such as OpenAI’s “gpt-3.5-turbo” and “gpt-4” for Obsidian.
Chat from anywhere in Obsidian: Chat with your bot from anywhere within Obsidian.
Chat with current note: Use your chatbot to reference and engage within your current note.
Chatbot responds in Markdown: Receive formatted responses in Markdown for consistency.
Customizable bot name: Personalize the chatbot’s name.
System role prompt: Configure the chatbot to prompt for user roles before responding to messages.
Set Max Tokens and Temperature: Customize the length and randomness of the chatbot’s responses with Max Tokens and Temperature settings.
System theme color accents: Seamlessly matches the chatbot’s interface with your system’s color scheme.
Interact with self-hosted Large Language Models (LLMs): Use the REST API URL provided to interact with self-hosted Large Language Models (LLMs) using LocalAI.
Requirements
To use this plugin, with LocalAI, you will need to have the self-hosted API set up and running. You can follow the instructions provided by the self-hosted API provider to get it up and running.
Once you have the REST API URL for your self-hosted API, you can use it with this plugin to interact with your models.
Explore some GGUF models at theBloke.
How to activate the plugin
Two methods:
Obsidian Community plugins (Recommended):
Search for “BMO Chatbot” in the Obsidian Community plugins.
Enable “BMO Chatbot” in the settings.
To activate the plugin from this repo:
Navigate to the plugin’s folder in your terminal.
Run npm install to install any necessary dependencies for the plugin.
Once the dependencies have been installed, run npm run build to build the plugin.
Once the plugin has been built, it should be ready to activate.
Getting Started
To start using the plugin, enable it in your settings menu and enter your OpenAPI key. After completing these steps, you can access the bot panel by clicking on the bot icon in the left sidebar.
If you want to clear the chat history, simply click on the bot icon again in the left ribbon bar.
You can bring the containers down by docker-compose stop --rmi all
π± Env Variables
Flowise support different environment variables to configure your instance. You can specify the following variables in the .env file inside packages/server folder. Read more
x
Failing Installation on WSL or Linux (missing gcc)
When installing Homebrew on WSL or Linux, you may encounter the following error:
==> Installing k8sgpt from k8sgpt-ai/k8sgpt Error: The following formula cannot be installed from a bottle and must be
built from the source. k8sgpt Install Clang or run brew install gcc.
If you install gcc as suggested, the problem will persist. Therefore, you need to install the build-essential package.
Download the latest Windows binaries of k8sgpt from the Release
tab based on your system architecture.
Extract the downloaded package to your desired location. Configure the system path variable with the binary location
Operator Installation
To install within a Kubernetes cluster please use our k8sgpt-operator with installation instructions available here
This mode of operation is ideal for continuous monitoring of your cluster and can integrate with your existing monitoring such as Prometheus and Alertmanager.
Quick Start
Currently the default AI provider is OpenAI, you will need to generate an API key from OpenAI
You can do this by running k8sgpt generate to open a browser link to generate it
Run k8sgpt auth add to set it in k8sgpt.
You can provide the password directly using the --password flag.
Run k8sgpt filters to manage the active filters used by the analyzer. By default, all filters are executed during analysis.
Run k8sgpt analyze to run a scan.
And use k8sgpt analyze --explain to get a more detailed explanation of the issues.
You also run k8sgpt analyze --with-doc (with or without the explain flag) to get the official documentation from kubernetes.
Analyzers
K8sGPT uses analyzers to triage and diagnose issues in your cluster. It has a set of analyzers that are built in, but
you will be able to write your own analyzers.
curl -X GET "http://localhost:8080/analyze?namespace=k8sgpt&explain=false"
Key Features
LocalAI provider
To run local models, it is possible to use OpenAI compatible APIs, for instance LocalAI which uses llama.cpp to run inference on consumer-grade hardware. Models supported by LocalAI for instance are Vicuna, Alpaca, LLaMA, Cerebras, GPT4ALL, GPT4ALL-J, Llama2 and koala.
To run local inference, you need to download the models first, for instance you can find gguf compatible models in huggingface.com (for example vicuna, alpaca and koala).
Start the API server
To start the API server, follow the instruction in LocalAI.
Run k8sgpt
To run k8sgpt, run k8sgpt auth add with the localai backend:
There may be scenarios where you wish to have K8sGPT plugged into several default AI providers. In this case you may wish to use one as a new default, other than OpenAI which is the project default.
k8sgpt auth default -p azureopenai
Default provider set to azureopenai
With this option, the data is anonymized before being sent to the AI Backend. During the analysis execution, k8sgpt retrieves sensitive data (Kubernetes object names, labels, etc.). This data is masked when sent to the AI backend and replaced by a key that can be used to de-anonymize the data when the solution is returned to the user.
Anonymization
Error reported during analysis:
Error: HorizontalPodAutoscaler uses StatefulSet/fake-deployment as ScaleTargetRef which does not exist.
Payload sent to the AI backend:
Error: HorizontalPodAutoscaler uses StatefulSet/tGLcCRcHa1Ce5Rs as ScaleTargetRef which does not exist.
Payload returned by the AI:
The Kubernetes system is trying to scale a StatefulSet named tGLcCRcHa1Ce5Rs using the HorizontalPodAutoscaler, but it cannot find the StatefulSet. The solution is to verify that the StatefulSet name is spelled correctly and exists in the same namespace as the HorizontalPodAutoscaler.
Payload returned to the user:
The Kubernetes system is trying to scale a StatefulSet named fake-deployment using the HorizontalPodAutoscaler, but it cannot find the StatefulSet. The solution is to verify that the StatefulSet name is spelled correctly and exists in the same namespace as the HorizontalPodAutoscaler.
Note: Anonymization does not currently apply to events.
Further Details
Anonymization does not currently apply to events.
In a few analysers like Pod, we feed to the AI backend the event messages which are not known beforehand thus we are not masking them for the time being.
The following is the list of analysers in which data is being masked:-
Statefulset
Service
PodDisruptionBudget
Node
NetworkPolicy
Ingress
HPA
Deployment
Cronjob
The following is the list of analysers in which data is not being masked:-
RepicaSet
PersistentVolumeClaim
Pod
*Events
*Note:
k8gpt will not mask the above analysers because they do not send any identifying information except Events analyser.
Masking for Events analyzer is scheduled in the near future as seen in this issue. Further research has to be made to understand the patterns and be able to mask the sensitive parts of an event like pod name, namespace etc.
The following is the list of fields which are not being masked:-
Describe
ObjectStatus
Replicas
ContainerStatus
*Event Message
ReplicaStatus
Count (Pod)
*Note:
It is quite possible the payload of the event message might have something like “super-secret-project-pod-X crashed” which we don’t currently redact (scheduled in the near future as seen in this issue).
Proceed with care
The K8gpt team recommends using an entirely different backend (a local model) in critical production environments. By using a local model, you can rest assured that everything stays within your DMZ, and nothing is leaked.
If there is any uncertainty about the possibility of sending data to a public LLM (open AI, Azure AI) and it poses a risk to business-critical operations, then, in such cases, the use of public LLM should be avoided based on personal assessment and the jurisdiction of risks involved.
Configuration management
k8sgpt stores config data in the $XDG_CONFIG_HOME/k8sgpt/k8sgpt.yaml file. The data is stored in plain text, including your OpenAI key.
Config file locations:
OS
Path
MacOS
~/Library/Application Support/k8sgpt/k8sgpt.yaml
Linux
~/.config/k8sgpt/k8sgpt.yaml
Windows
%LOCALAPPDATA%/k8sgpt/k8sgpt.yaml
There may be scenarios where caching remotely is preferred.
In these scenarios K8sGPT supports AWS S3 Integration.
Remote caching
As a prerequisite AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are required as environmental variables.
Adding a remote cache
Note: this will create the bucket if it does not exist
With Kairos you can build immutable, bootable Kubernetes and OS images for your edge devices as easily as writing a Dockerfile. Optional P2P mesh with distributed ledger automates node bootstrapping and coordination. Updating nodes is as easy as CI/CD: push a new image to your container registry and let secure, risk-free A/B atomic upgrades do the rest. Kairos is part of the Secure Edge-Native Architecture (SENA) to securely run workloads at the Edge (whitepaper).
Kairos (formerly c3os) is an open-source project which brings Edge, cloud, and bare metal lifecycle OS management into the same design principles with a unified Cloud Native API.
At-a-glance:
:bowtie: Community Driven
:octocat: Open Source
:lock: Linux immutable, meta-distribution
:key: Secure
:whale: Container-based
:penguin: Distribution agnostic
Kairos can be used to:
Easily spin-up a Kubernetes cluster, with the Linux distribution of your choice :penguin:
Create your Immutable infrastructure, no more infrastructure drift! :lock:
Manage the cluster lifecycle with Kubernetesβfrom building to provisioning, and upgrading :rocket:
Create a multipleβnode, a single cluster that spans up across regions :earth_africa:
For comprehensive docs, tutorials, and examples see our documentation.
LinGoose
LinGoose (Lingo + Go + Goose πͺΏ) aims to be a complete Go framework for creating LLM apps. π€ βοΈ
LinGoose is a powerful Go framework for developing Large Language Model (LLM) based applications using pipelines. It is designed to be a complete solution and provides multiple components, including Prompts, Templates, Chat, Output Decoders, LLM, Pipelines, and Memory. With LinGoose, you can interact with LLM AI through prompts and generate complex templates. Additionally, it includes a chat feature, allowing you to create chatbots. The Output Decoders component enables you to extract specific information from the output of the LLM, while the LLM interface allows you to send prompts to various AI, such as the ones provided by OpenAI. You can chain multiple LLM steps together using Pipelines and store the output of each step in Memory for later retrieval. LinGoose also includes a Document component, which is used to store text, and a Loader component, which is used to load Documents from various sources. Finally, it includes TextSplitters, which are used to split text or Documents into multiple parts, Embedders, which are used to embed text or Documents into embeddings, and Indexes, which are used to store embeddings and documents and to perform searches.
Components
LinGoose is composed of multiple components, each one with its own purpose.
Output decoders are used to decode the output of the LLM. They can be used to extract specific information from the output. Supports JSONDecoder and RegExDecoder
LLM is an interface to various AI such as the ones provided by OpenAI. It is responsible for sending the prompt to the AI and retrieving the output. Supports LocalAI, HuggingFace and Llama.cpp.
Indexes are used to store embeddings and documents and to perform searches. Supports SimpleVectorIndex, Pinecone and Qdrant
Usage
Please refer to the documentation at lingoose.io to understand how to use LinGoose. If you prefer the π examples directory contains a lot of examples π.
However, here is a powerful example of what LinGoose is capable of:
packagemainimport("context"openaiembedder"github.com/henomis/lingoose/embedder/openai""github.com/henomis/lingoose/index/option"simplevectorindex"github.com/henomis/lingoose/index/simpleVectorIndex""github.com/henomis/lingoose/llm/openai""github.com/henomis/lingoose/loader"qapipeline"github.com/henomis/lingoose/pipeline/qa""github.com/henomis/lingoose/textsplitter")funcmain(){docs,_:=loader.NewPDFToTextLoader("./kb").WithPDFToTextPath("/opt/homebrew/bin/pdftotext").WithTextSplitter(textsplitter.NewRecursiveCharacterTextSplitter(2000,200)).Load(context.Background())index:=simplevectorindex.New("db",".",openaiembedder.New(openaiembedder.AdaEmbeddingV2))index.LoadFromDocuments(context.Background(),docs)qapipeline.New(openai.NewChat().WithVerbose(true)).WithIndex(index).Query(context.Background(),"What is the NATO purpose?",option.WithTopK(1))}
This is the famous 4-lines lingoose knowledge base chatbot. π€
Installation
Be sure to have a working Go environment, then run the following command:
go get github.com/henomis/lingoose
LLMStack
LLMStack - LLMStack is a no-code platform for building generative AI applications, chatbots, agents and connecting them to your data and business processes.
Build tailor-made generative AI applications, chatbots and agents that cater to your unique needs by chaining multiple LLMs. Seamlessly integrate your own data and GPT-powered models without any coding experience using LLMStack’s no-code builder. Trigger your AI chains from Slack or Discord. Deploy to the cloud or on-premise.
Getting Started
LLMStack deployment comes with a default admin account whose credentials are admin and promptly. Be sure to change the password from admin panel after logging in.
Features
π Chain multiple models: LLMStack allows you to chain multiple LLMs together to build complex generative AI applications.
π Use generative AI on your Data: Import your data into your accounts and use it in AI chains. LLMStack allows importing various types (CSV, TXT, PDF, DOCX, PPTX etc.,) of data from a variety of sources (gdrive, notion, websites, direct uploads etc.,). Platform will take care of preprocessing and vectorization of your data and store it in the vector database that is provided out of the box.
π οΈ No-code builder: LLMStack comes with a no-code builder that allows you to build AI chains without any coding experience. You can chain multiple LLMs together and connect them to your data and business processes.
βοΈ Deploy to the cloud or on-premise: LLMStack can be deployed to the cloud or on-premise. You can deploy it to your own infrastructure or use our cloud offering at Promptly.
π API access: Apps or chatbots built with LLMStack can be accessed via HTTP API. You can also trigger your AI chains from Slack or Discord.
π’ Multi-tenant: LLMStack is multi-tenant. You can create multiple organizations and add users to them. Users can only access the data and AI chains that belong to their organization.
What can you build with LLMStack?
Using LLMStack you can build a variety of generative AI applications, chatbots and agents. Here are some examples:
π Text generation: You can build apps that generate product descriptions, blog posts, news articles, tweets, emails, chat messages, etc., by using text generation models and optionally connecting your data. Check out this marketing content generator for example
π€ Chatbots: You can build chatbots trained on your data powered by ChatGPT like Promptly Help that is embedded on Promptly website
π¨ Multimedia generation: Build complex applications that can generate text, images, videos, audio, etc. from a prompt. This story generator is an example
π£οΈ Conversational AI: Build conversational AI systems that can have a conversation with a user. Check out this Harry Potter character chatbot
π Search augmentation: Build search augmentation systems that can augment search results with additional information using APIs. Sharebird uses LLMStack to augment search results with AI generated answer from their content similar to Bing’s chatbot
π¬ Discord and Slack bots: Apps built on LLMStack can be triggered from Slack or Discord. You can easily connect your AI chains to Slack or Discord from LLMStack’s no-code app editor. Check out our Discord server to interact with one such bot.
Administration
Login to http://localhost:3000/admin using the admin account. You can add users and assign them to organizations in the admin panel.
Documentation
Check out our documentation at llmstack.ai/docs to learn more about LLMStack.
LocalAGI
LocalAGI is a small π€ virtual assistant that you can run locally, made by the LocalAI author and powered by it.
No API keys needed, No cloud services needed, 100% Local. Tailored for Local use, however still compatible with OpenAI.
Smart-agent/virtual assistant that can do tasks
Small set of dependencies
Run with Docker/Podman/Containers
Rather than trying to do everything, provide a good starting point for other projects
Note: Be warned! It was hacked in a weekend, and it’s just an experiment to see what can be done with local LLMs.
π Features
π§ LLM for intent detection
π§ Uses functions for actions
π Write to long-term memory
π Read from long-term memory
π Internet access for search
:card_file_box: Write files
π Plan steps to achieve a goal
π€ Avatar creation with Stable Diffusion
π¨οΈ Conversational
π£οΈ Voice synthesis with TTS
:book: Quick start
No frills, just run docker-compose and start chatting with your virtual assistant:
# Modify the configuration# nano .envdocker-compose run -i --rm localagi
How to use it
By default localagi starts in interactive mode
Examples
Road trip planner by limiting searching to internet to 3 results only:
docker-compose run -i --rm localagi \
--skip-avatar \
--subtask-context \
--postprocess \
--search-results 3\
--prompt "prepare a plan for my roadtrip to san francisco"
Limit results of planning to 3 steps:
docker-compose run -i --rm localagi \
--skip-avatar \
--subtask-context \
--postprocess \
--search-results 1\
--prompt "do a plan for my roadtrip to san francisco"\
--plan-message "The assistant replies with a plan of 3 steps to answer the request with a list of subtasks with logical steps. The reasoning includes a self-contained, detailed and descriptive instruction to fullfill the task."
Advanced
localagi has several options in the CLI to tweak the experience:
--system-prompt is the system prompt to use. If not specified, it will use none.
--prompt is the prompt to use for batch mode. If not specified, it will default to interactive mode.
--interactive is the interactive mode. When used with --prompt will drop you in an interactive session after the first prompt is evaluated.
--skip-avatar will skip avatar creation. Useful if you want to run it in a headless environment.
--re-evaluate will re-evaluate if another action is needed or we have completed the user request.
--postprocess will postprocess the reasoning for analysis.
--subtask-context will include context in subtasks.
--search-results is the number of search results to use.
--plan-message is the message to use during planning. You can override the message for example to force a plan to have a different message.
--tts-api-base is the TTS API base. Defaults to http://api:8080.
--localai-api-base is the LocalAI API base. Defaults to http://api:8080.
--images-api-base is the Images API base. Defaults to http://api:8080.
--embeddings-api-base is the Embeddings API base. Defaults to http://api:8080.
--functions-model is the functions model to use. Defaults to functions.
--embeddings-model is the embeddings model to use. Defaults to all-MiniLM-L6-v2.
--llm-model is the LLM model to use. Defaults to gpt-4.
--tts-model is the TTS model to use. Defaults to en-us-kathleen-low.onnx.
--stablediffusion-model is the Stable Diffusion model to use. Defaults to stablediffusion.
--stablediffusion-prompt is the Stable Diffusion prompt to use. Defaults to DEFAULT_PROMPT.
--force-action will force a specific action.
--debug will enable debug mode.
Customize
To use a different model, you can see the examples in the config folder.
To select a model, modify the .env file and change the PRELOAD_MODELS_CONFIG variable to use a different configuration file.
Caveats
The “goodness” of a model has a big impact on how LocalAGI works. Currently 13b models are powerful enough to actually able to perform multi-step tasks or do more actions. However, it is quite slow when running on CPU (no big surprise here).
The context size is a limitation - you can find in the config examples to run with superhot 8k context size, but the quality is not good enough to perform complex tasks.
What is LocalAGI?
It is a dead simple experiment to show how to tie the various LocalAI functionalities to create a virtual assistant that can do tasks. It is simple on purpose, trying to be minimalistic and easy to understand and customize for everyone.
It is different from babyAGI or AutoGPT as it uses LocalAI functions - it is a from scratch attempt built on purpose to run locally with LocalAI (no API keys needed!) instead of expensive, cloud services. It sets apart from other projects as it strives to be small, and easy to fork on.
How it works?
LocalAGI just does the minimal around LocalAI functions to create a virtual assistant that can do generic tasks. It works by an endless loop of intent detection, function invocation, self-evaluation and reply generation (if it decides to reply! :)). The agent is capable of planning complex tasks by invoking multiple functions, and remember things from the conversation.
In a nutshell, it goes like this:
Decide based on the conversation history if it needs to take an action by using functions. It uses the LLM to detect the intent from the conversation.
if it need to take an action (e.g. “remember something from the conversation” ) or generate complex tasks ( executing a chain of functions to achieve a goal ) it invokes the functions
it re-evaluates if it needs to do any other action
return the result back to the LLM to generate a reply for the user
Under the hood LocalAI converts functions to llama.cpp BNF grammars. While OpenAI fine-tuned a model to reply to functions, LocalAI constrains the LLM to follow grammars. This is a much more efficient way to do it, and it is also more flexible as you can define your own functions and grammars. For learning more about this, check out the LocalAI documentation and my tweet that explains how it works under the hoods: https://twitter.com/mudler_it/status/1675524071457533953.
Agent functions
The intention of this project is to keep the agent minimal, so can be built on top of it or forked. The agent is capable of doing the following functions:
remember something from the conversation
recall something from the conversation
search something from the internet
plan a complex task by invoking multiple functions
write files to disk
Roadmap
100% Local, with Local AI. NO API KEYS NEEDED!
Create a simple virtual assistant
Make the virtual assistant do functions like store long-term memory and autonomously search between them when needed
Create the assistant avatar with Stable Diffusion
Give it a voice
Use weaviate instead of Chroma
Get voice input (push to talk or wakeword)
Make a REST API (OpenAI compliant?) so can be plugged by e.g. a third party service
Take a system prompt so can act with a “character” (e.g. “answer in rick and morty style”)
Development
Run docker-compose with main.py checked-out:
docker-compose run -v main.py:/app/main.py -i --rm localagi
Notes
a 13b model is enough for doing contextualized research and search/retrieve memory
a 30b model is enough to generate a roadmap trip plan ( so cool! )
With superhot models looses its magic, but maybe suitable for search
Context size is your enemy. --postprocess some times helps, but not always
It can be silly!
It is slow on CPU, don’t expect 7b models to perform good, and 13b models perform better but on CPU are quite slow.
Mattermost-OpenOps
OpenOps is an open source platform for applying generative AI to workflows in secure environments.
Enables AI exploration with full data control in a multi-user pilot.
Supports broad ecosystem of AI models from OpenAI and Microsoft to open source LLMs from Hugging Face.
Speeds development of custom security, compliance and data custody policy from early evaluation to future scale.
Unliked closed source, vendor-controlled environments where data controls cannot be audited, OpenOps provides a transparent, open source, customer-controlled platform for developing, securing and auditing AI-accelerated workflows.
Why Open Ops?
Everyone is in a race to deploy generative AI solutions, but need to do so in a responsible and safe way. OpenOps lets you run powerful models in a safe sandbox to establish the right safety protocols before rolling out to users. Here’s an example of an evaluation, implementation, and iterative rollout process:
Phase 1: Set up the OpenOps collaboration sandbox, a self-hosted service providing multi-user chat and integration with GenAI. (this repository)
Phase 2: Evaluate different GenAI providers, whether from public SaaS services like OpenAI or local open source models, based on your security and privacy requirements.
Phase 3: Invite select early adopters (especially colleagues focusing on trust and safety) to explore and evaluate the GenAI based on their workflows. Observe behavior, and record user feedback, and identify issues. Iterate on workflows and usage policies together in the sandbox. Consider issues such as data leakage, legal/copyright, privacy, response correctness and appropriateness as you apply AI at scale.
Phase 4: Set and implement policies as availability is incrementally rolled out to your wider organization.
What does OpenOps include?
Deploying the OpenOps sandbox includes the following components:
π° Mattermost Server - Open source, self-hosted alternative to Discord and Slack for strict security environments with playbooks/workflow automation, tools integration, real time 1-1 and group messaging, audio calling and screenshare.
π PostgreSQL - Database for storing private data from multi-user, chat collaboration discussions and audit history.
π€ Mattermost AI plugin - Extension of Mattermost platform for AI bot and generative AI integration.
π¦ Open Source, Self-Hosted LLM models - Models for evaluation and use case development from Hugging Face and other sources, including GPT4All (runs on a laptop in 4.2 GB) and Falcon LLM (example of leading scaled self-hosted models). Uses LocalAI.
ππ§ (Configurable) Closed Source, Vendor-Hosted AI models - SaaS-based GenAI models from Azure AI, OpenAI, & Anthropic.
ππ± (Configurable) Mattermost Mobile and Desktop Apps - End-user apps for future production deployment.
Clone the repository: git clone https://github.com/mattermost/openops && cd openops
Start docker services and configure plugin
If using OpenAI:
Run env backend=openai ./init.sh
Run ./configure_openai.sh sk-<your openai key> to add your API credentials or use the Mattermost system console to configure the plugin
If using LocalAI:
Run env backend=localai ./init.sh
Run env backend=localai ./download_model.sh to download one or supply your own gguf formatted model in the models directory.
Access Mattermost and log in with the credentials provided in the terminal.
When you log in, you will start out in a direct message with your AI Assistant bot. Now you can start exploring AI usages.
Gitpod
Click the above badge and start your Gitpod workspace
You will see VSCode interface and the workspace will configure itself automatically. Wait for the services to start and for your root login for Mattermost to be generated in the terminal
Run ./configure_openai.sh sk-<your openai key> to add your API credentials or use the Mattermost system console to configure the plugin
Access Mattermost and log in with the credentials supplied in the terminal.
When you log in, you will start out in a direct message with your AI Assistant bot. Now you can start exploring AI usages.
Usage
There many ways to integrate generative AI into confidential, self-hosted workplace discussions. To help you get started, here are some examples provided in OpenOps:
Title
Image
Description
Streaming Conversation
The OpenOps platform reproduces streamed replies from popular GenAI chatbots creating a sense of responsiveness and conversational engagement, while masking actual wait times.
Thread Summarization
Use the “Summarize Thread” menu option or the /summarize command to get a summary of the thread in a Direct Message from an AI bot. AI-generated summaries can be created from private, chat-based discussions to speed information flows and decision-making while reducing the time and cost required for organizations to stay up-to-date.
Contextual Interrogation
Users can ask follow-up questions to discussion summaries generated by AI bots to learn more about the underlying information without reviewing the raw input.
Meeting Summarization
Create meeting summaries! Designed to work with the Mattermost Calls plugin recording feature.
Chat with AI Bots
End users can interact with the AI bot in any discussion thread by mentioning AI bot with an @ prefix, as they would get the attention of a human user. The bot will receive the thread information as context for replying.
Sentiment Analysis
Use the “React for me” menu option to have the AI bot analyze the sentiment of messages use its conclusion to deliver an emoji reaction on the userβs behalf.
Reinforcement Learning from Human Feedback
Bot posts are distinguished from human posts by having π π icons available for human end users to signal whether the AI response was positive or problematic. The history of responses can be used in future to fine-tune the underlying AI models, as well as to potentially evaluate the responses of new models based on their correlation to positive and negative user ratings for past model responses.
Mods
AI for the command line, built for pipelines.
LLM based AI is really good at interpreting the output of commands and
returning the results in CLI friendly text formats like Markdown. Mods is a
simple tool that makes it super easy to use AI on the command line and in your
pipelines. Mods works with OpenAI
and LocalAI
To get started, install Mods and check out some of the
examples below. Since Mods has built-in Markdown formatting, you may also want
to grab Glow to give the output some
pizzazz.
Mods works by reading standard in and prefacing it with a prompt supplied in
the mods arguments. It sends the input text to an LLM and prints out the
result, optionally asking the LLM to format the response as Markdown. This
gives you a way to “question” the output of a command. Mods will also work on
standard in or an argument supplied prompt individually.
Installation
Mods works with OpenAI compatible endpoints. By default, Mods is configured to
support OpenAI’s official API and a LocalAI installation running on port 8080.
You can configure additional endpoints in your settings file by running
mods --settings.
LocalAI
LocalAI allows you to run a multitude of models locally. Mods works with the
GPT4ALL-J model as setup in this tutorial.
You can define more LocalAI models and endpoints with mods --settings.
Binaries are available for Linux, macOS, and Windows
Or, just install it with go:
go install github.com/charmbracelet/mods@latest
Saving conversations
Conversations save automatically. They are identified by their latest prompt.
Similar to Git, conversations have a SHA-1 identifier and a title. Conversations
can be updated, maintaining their SHA-1 identifier but changing their title.
Settings
--settings
Mods lets you tune your query with a variety of settings. You can configure
Mods with mods --settings or pass the settings as environment variables
and flags.
Model
-m, --model, MODS_MODEL
Mods uses gpt-4 with OpenAI by default but you can specify any model as long
as your account has access to it or you have installed locally with LocalAI.
You can add new models to the settings with mods --settings.
You can also specify a model and an API endpoint with -m and -a
to use models not in the settings file.
Title
-t, --title
Set a custom save title for the conversation.
Continue last
-C, --continue-last
Continues the previous conversation.
Continue
-c, --continue
Continue from the last response or a given title or SHA1.
List
-l, --list
Lists all saved conversations.
Show
-s, --show
Show the saved conversation the given title or SHA1.
Delete
--delete
Deletes the saved conversation with the given title or SHA1.
Format As Markdown
-f, --format, MODS_FORMAT
Ask the LLM to format the response as markdown. You can edit the text passed to
the LLM with mods --settings then changing the format-text value.
Raw
-r, --raw, MODS_RAW
Print the raw response without syntax highlighting, even when connect to a TTY.
Max Tokens
--max-tokens, MODS_MAX_TOKENS
Max tokens tells the LLM to respond in less than this number of tokens. LLMs
are better at longer responses so values larger than 256 tend to work best.
Temperature
--temp, MODS_TEMP
Sampling temperature is a number between 0.0 and 2.0 and determines how
confident the model is in its choices. Higher values make the output more
random and lower values make it more deterministic.
TopP
--topp, MODS_TOPP
Top P is an alternative to sampling temperature. It’s a number between 0.0 and
2.0 with smaller numbers narrowing the domain from which the model will create
its response.
No Limit
--no-limit, MODS_NO_LIMIT
By default Mods attempts to size the input to the maximum size the allowed by
the model. You can potentially squeeze a few more tokens into the input by
setting this but also risk getting a max token exceeded error from the OpenAI API.
Include Prompt
-P, --prompt, MODS_INCLUDE_PROMPT
Include prompt will preface the response with the entire prompt, both standard
in and the prompt supplied by the arguments.
Include Prompt Args
-p, --prompt-args, MODS_INCLUDE_PROMPT_ARGS
Include prompt args will include only the prompt supplied by the arguments.
This can be useful if your standard in content is long and you just a want a
summary before the response.
Max Retries
--max-retries, MODS_MAX_RETRIES
The maximum number of retries to failed API calls. The retries happen with an
exponential backoff.
Fanciness
--fanciness, MODS_FANCINESS
Your desired level of fanciness.
Quiet
-q, --quiet, MODS_QUIET
Output nothing to standard err.
Reset Settings
--reset-settings
Backup your old settings file and reset everything to the defaults.
No Cache
--no-cache, MODS_NO_CACHE
Disables conversation saving.
HTTP Proxy
-x, --http-proxy, MODS_HTTP_PROXY
Use the HTTP proxy to the connect the API endpoints.
Spark
an LLM-powered autonomous agent platform
A framework for autonomous agents who can work together to accomplish tasks using LocalAI.
Rename the .env.template file at the root of the project to .env and add your secrets to it:
# the following are needed for the agent to be able to search the web:
GOOGLE_SEARCH_ENGINE_ID=... # create a custom search engine at https://cse.google.com/cse/all
GOOGLE_API_KEY=... # obtain from https://console.cloud.google.com/apis/credentials
AGENT_DELAY=... # optionally, a delay in milliseconds following every agent action
MODEL=... # any Llama.cpp LLM model
SERVER=... # optionally, a server to connect to (default http://localhost:8080)
Interact with the agents through the console. Anything you type will be sent as a message to all agents currently.
Action errors
After spinning up a new agent, you will often see them make some mistakes which generate errors:
Trying to use an action before they’ve asked for help on it to know what its parameters are
Trying to just use a raw text response instead of a correctly-formatted action (or raw text wrapping a code block which contains a valid action)
Trying to use a multi-line parameter value without wrapping it in the multiline delimiter (% ff9d7713-0bb0-40d4-823c-5a66de48761b)
This is a normal period of adjustment as they learn to operate themselves. They generally will learn from these mistakes and recover, although agents sometimes devolve into endless error loops and can’t figure out what the problem is. It’s highly advised to never leave an agent unattended.
Agent state
Each agent stores its state under the .store directory. Agent 1, for example, has
.store/1/memory
.store/1/goals
.store/1/notes
You can simply delete any of these things, or the whole agent folder (or the whole .store) to selectively wipe whatever state you want between runs. Otherwise, agents will pick up where you left off on restart.
A nice aspect of this is that when you want to debug a problem you ran into with a particular agent, you can delete the events in their memory subsequent to the point where the problem occurred, make changes to the code, and restart them to effectively replay that moment until you’ve fixed the bug. You can also ask an agent to implement a feature, and once they’ve done so you can restart, tell them that you’ve loaded the feature, and ask them to try it out.
Here are answers to some of the most common questions.
How do I get models?
Most gguf-based models should work, but newer models may require additions to the API. If a model doesn’t work, please feel free to open up issues. However, be cautious about downloading models from the internet and directly onto your machine, as there may be security vulnerabilities in lama.cpp or ggml that could be maliciously exploited. Some models can be found on Hugging Face: https://huggingface.co/models?search=gguf, or models from gpt4all are compatible too: https://github.com/nomic-ai/gpt4all.
What’s the difference with Serge, or XXX?
LocalAI is a multi-model solution that doesn’t focus on a specific model type (e.g., llama.cpp or alpaca.cpp), and it handles all of these internally for faster inference, easy to set up locally and deploy to Kubernetes.
Everything is slow, how come?
There are few situation why this could occur. Some tips are:
Don’t use HDD to store your models. Prefer SSD over HDD. In case you are stuck with HDD, disable mmap in the model config file so it loads everything in memory.
Watch out CPU overbooking. Ideally the --threads should match the number of physical cores. For instance if your CPU has 4 cores, you would ideally allocate <= 4 threads to a model.
Run LocalAI with DEBUG=true. This gives more information, including stats on the token inference speed.
Check that you are actually getting an output: run a simple curl request with "stream": true to see how fast the model is responding.
Can I use it with a Discord bot, or XXX?
Yes! If the client uses OpenAI and supports setting a different base URL to send requests to, you can use the LocalAI endpoint. This allows to use this with every application that was supposed to work with OpenAI, but without changing the application!
Can this leverage GPUs?
There is partial GPU support, see build instructions above.
Where is the webUI?
There is the availability of localai-webui and chatbot-ui in the examples section and can be setup as per the instructions. However as LocalAI is an API you can already plug it into existing projects that provides are UI interfaces to OpenAI's APIs. There are several already on github, and should be compatible with LocalAI already (as it mimics the OpenAI API)
Enable the debug mode by setting DEBUG=true in the environment variables. This will give you more information on what’s going on.
You can also specify --debug in the command line.
I’m getting ‘invalid pitch’ error when running with CUDA, what’s wrong?
This typically happens when your prompt exceeds the context size. Try to reduce the prompt size, or increase the context size.
I’m getting a ‘SIGILL’ error, what’s wrong?
Your CPU probably does not have support for certain instructions that are compiled by default in the pre-built binaries. If you are running in a container, try setting REBUILD=true and disable the CPU instructions that are not compatible with your CPU. For instance: CMAKE_ARGS="-DLLAMA_F16C=OFF -DLLAMA_AVX512=OFF -DLLAMA_AVX2=OFF -DLLAMA_FMA=OFF" make build
How-tos
How-tos
This section includes LocalAI end-to-end examples, tutorial and how-tos curated by the community and maintained by lunamidori5.
There is a Full_Auto installer compatible with some types of Linux distributions, feel free to use them, but note that they may not fully work. If you need to install something, please use the links at the top.
git clone https://github.com/lunamidori5/localai-lunademo.git
cd localai-lunademo
#Pick your type of linux for the Full Autos, if you already have python, docker, and docker-compose installed skip this chmod. But make sure you chmod the setup_linux file.chmod +x Full_Auto_setup_Debian.sh or chmod +x Full_Auto_setup_Ubutnu.sh
chmod +x Setup_Linux.sh
#Make sure to install cuda to your host OS and to Docker if you plan on using GPU./(the setupfile you wish to run)
Windows Hosts:
REM Make sure you have git, docker-desktop, and python 3.11 installedgit clone https://github.com/lunamidori5/localai-lunademo.git
cd localai-lunademo
call Setup.bat
MacOS Hosts:
I need some help working on a MacOS Setup file, if you are willing to help out, please contact Luna Midori on discord or put in a PR on Luna Midori’s github.
Video How Tos
Ubuntu - COMING SOON
Debian - COMING SOON
Windows - COMING SOON
MacOS - PLANED - NEED HELP
Enjoy localai! (If you need help contact Luna Midori on Discord)
Trying to run Setup.bat or Setup_Linux.sh from Git Bash on Windows is not working. (Somewhat fixed)
Running over SSH or other remote command line based apps may bug out, load slowly, or crash.
Easy Model Setup
Lets learn how to setup a model, for this How To we are going to use the Dolphin 2.2.1 Mistral 7B model.
To download the model to your models folder, run this command in a commandline of your picking.
Each model needs at least 5 files, with out these files, the model will run raw, what that means is you can not change settings of the model.
File 1 - The model's GGUF file
File 2 - The model's .yaml file
File 3 - The Chat API .tmpl file
File 4 - The Chat API helper .tmpl file
File 5 - The Completion API .tmpl file
So lets fix that! We are using lunademo name for this How To but you can name the files what ever you want! Lets make blank files to start with
Now lets edit the "lunademo-chat.tmpl", This is the template that model “Chat” trained models use, but changed for LocalAI
<|im_start|>{{if eq .RoleName "assistant"}}assistant{{else if eq .RoleName "system"}}system{{else if eq .RoleName "user"}}user{{end}}
{{if .Content}}{{.Content}}{{end}}
<|im_end|>
For the "lunademo-chat-block.tmpl", Looking at the huggingface repo, this model uses the <|im_start|>assistant tag for when the AI replys, so lets make sure to add that to this file. Do not add the user as we will be doing that in our yaml file!
{{.Input}}
<|im_start|>assistant
Now in the "lunademo-completion.tmpl" file lets add this. (This is a hold over from OpenAI V0)
{{.Input}}
For the "lunademo.yaml" file. Lets set it up for your computer or hardware. (If you want to see advanced yaml configs - Link)
We are going to 1st setup the backend and context size.
backend:llamacontext_size:2000
What this does is tell LocalAI how to load the model. Then we are going to add our settings in after that. Lets add the models name and the models settings. The models name: is what you will put into your request when sending a OpenAI request to LocalAI
If you are running on GPU or want to tune the model, you can add settings like (higher the GPU Layers the more GPU used)
f16:truegpu_layers:4
To fully tune the model to your like. But be warned, you must restart LocalAI after changing a yaml file
docker compose restart
If you want to check your models yaml, here is a full copy!
backend:llamacontext_size:2000##Put settings right here for tunning!! Before name but after Backend!name:lunademoparameters:model:dolphin-2.2.1-mistral-7b.Q4_0.gguftemplate:chat:lunademo-chat-blockchat_message:lunademo-chatcompletion:lunademo-completion
Now that we got that setup, lets test it out but sending a request to Localai!
—– Adv Stuff —–
(Please do not run these steps if you have already done the setup)
Alright now that we have learned how to set up our own models, here is how to use the gallery to do alot of this for us. This command will download and set up (mostly, we will always need to edit our yaml file to fit our computer / hardware)
This will setup the model, models yaml, and both template files (you will see it only did one, as completions is out of date and not supported by OpenAI if you need one, just follow the steps from before to make one.
If you would like to download a raw model using the gallery api, you can run this command. You will need to set up the 3 files needed to run the model tho!
fromopenaiimportOpenAIclient=OpenAI(base_url="http://localhost:8080/v1",api_key="sk-xxx")messages=[{"role":"system","content":"You are LocalAI, a helpful, but really confused ai, you will only reply with confused emotes"},{"role":"user","content":"Hello How are you today LocalAI"}]completion=client.chat.completions.create(model="lunademo",messages=messages,)print(completion.choices[0].message)
importosimportopenaiopenai.api_base="http://localhost:8080/v1"openai.api_key="sx-xxx"OPENAI_API_KEY="sx-xxx"os.environ['OPENAI_API_KEY']=OPENAI_API_KEYcompletion=openai.ChatCompletion.create(model="lunademo",messages=[{"role":"system","content":"You are LocalAI, a helpful, but really confused ai, you will only reply with confused emotes"},{"role":"user","content":"How are you?"}])print(completion.choices[0].message.content)
At this point we want to set up our .env file, here is a copy for you to use if you wish, Make sure this is in the LocalAI folder.
## Set number of threads.## Note: prefer the number of physical cores. Overbooking the CPU degrades performance notably.THREADS=2## Specify a different bind address (defaults to ":8080")# ADDRESS=127.0.0.1:8080## Define galleries.## models will to install will be visible in `/models/available`GALLERIES=[{"name":"model-gallery", "url":"github:go-skynet/model-gallery/index.yaml"}, {"url": "github:go-skynet/model-gallery/huggingface.yaml","name":"huggingface"}]## Default path for modelsMODELS_PATH=/models
## Enable debug mode# DEBUG=true## Disables COMPEL (Lets Stable Diffuser work, uncomment if you plan on using it)# COMPEL=0## Enable/Disable single backend (useful if only one GPU is available)# SINGLE_ACTIVE_BACKEND=true## Specify a build type. Available: cublas, openblas, clblas.BUILD_TYPE=cublas
## Uncomment and set to true to enable rebuilding from source# REBUILD=true## Enable go tags, available: stablediffusion, tts## stablediffusion: image generation with stablediffusion## tts: enables text-to-speech with go-piper ## (requires REBUILD=true)##GO_TAGS=tts## Path where to store generated images# IMAGE_PATH=/tmp## Specify a default upload limit in MB (whisper)# UPLOAD_LIMIT# HUGGINGFACEHUB_API_TOKEN=Token here
Now that we have the .env set lets set up our docker-compose file.
It will use a container from quay.io.
Also note this docker-compose file is for CPU only.
Make sure to save that in the root of the LocalAI folder. Then lets spin up the Docker run this in a CMD or BASH
docker compose up -d --pull always
Now we are going to let that set up, once it is done, lets check to make sure our huggingface / localai galleries are working (wait until you see this screen to do this)
When you would like to request the model from CLI you can do
curl http://localhost:8080/v1/embeddings \
-H "Content-Type: application/json"\
-d '{
"input": "The food was delicious and the waiter...",
"model": "text-embedding-ada-002"
}'
At this point we want to set up our .env file, here is a copy for you to use if you wish, Make sure this is in the LocalAI folder.
## Set number of threads.## Note: prefer the number of physical cores. Overbooking the CPU degrades performance notably.THREADS=2## Specify a different bind address (defaults to ":8080")# ADDRESS=127.0.0.1:8080## Define galleries.## models will to install will be visible in `/models/available`GALLERIES=[{"name":"model-gallery", "url":"github:go-skynet/model-gallery/index.yaml"}, {"url": "github:go-skynet/model-gallery/huggingface.yaml","name":"huggingface"}]## Default path for modelsMODELS_PATH=/models
## Enable debug mode# DEBUG=true## Disables COMPEL (Lets Stable Diffuser work, uncomment if you plan on using it)# COMPEL=0## Enable/Disable single backend (useful if only one GPU is available)# SINGLE_ACTIVE_BACKEND=true## Specify a build type. Available: cublas, openblas, clblas.BUILD_TYPE=cublas
## Uncomment and set to true to enable rebuilding from source# REBUILD=true## Enable go tags, available: stablediffusion, tts## stablediffusion: image generation with stablediffusion## tts: enables text-to-speech with go-piper ## (requires REBUILD=true)##GO_TAGS=tts## Path where to store generated images# IMAGE_PATH=/tmp## Specify a default upload limit in MB (whisper)# UPLOAD_LIMIT# HUGGINGFACEHUB_API_TOKEN=Token here
Now that we have the .env set lets set up our docker-compose file.
It will use a container from quay.io.
Also note this docker-compose file is for CUDA only.
Please change the image to what you need.
master-cublas-cuda11
master-cublas-cuda11-core
v2.0.0-cublas-cuda11
v2.0.0-cublas-cuda11-core
v2.0.0-cublas-cuda11-ffmpeg
v2.0.0-cublas-cuda11-ffmpeg-core
Core Images - Smaller images without predownload python dependencies
master-cublas-cuda12
master-cublas-cuda12-core
v2.0.0-cublas-cuda12
v2.0.0-cublas-cuda12-core
v2.0.0-cublas-cuda12-ffmpeg
v2.0.0-cublas-cuda12-ffmpeg-core
Core Images - Smaller images without predownload python dependencies
Make sure to save that in the root of the LocalAI folder. Then lets spin up the Docker run this in a CMD or BASH
docker compose up -d --pull always
Now we are going to let that set up, once it is done, lets check to make sure our huggingface / localai galleries are working (wait until you see this screen to do this)
To set up a Stable Diffusion model is super easy.
In your models folder make a file called stablediffusion.yaml, then edit that file with the following. (You can change Linaqruf/animagine-xl with what ever sd-lx model you would like.
name:animagine-xlparameters:model:Linaqruf/animagine-xlbackend:diffusers# Force CPU usage - set to true for GPUf16:falsediffusers:pipeline_type:StableDiffusionXLPipelinecuda:false# Enable for GPU usage (CUDA)scheduler_type:dpm_2_a
If you are using docker, you will need to run in the localai folder with the docker-compose.yaml file in it
docker-compose down #windowsdocker compose down #linux/mac
Then in your .env file uncomment this line.
COMPEL=0
After that we can reinstall the LocalAI docker VM by running in the localai folder with the docker-compose.yaml file in it
docker-compose up #windowsdocker compose up #linux/mac
Then to download and setup the model, Just send in a normal OpenAI request! LocalAI will do the rest!