Skip to content

Commit d388115

Browse files
committed
chore(docs): add opencode, GHA, and realtime voice assistant examples
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 33cc0b8 commit d388115

1 file changed

Lines changed: 275 additions & 0 deletions

File tree

docs/content/integrations.md

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,278 @@ The list below is a list of software that integrates with LocalAI.
3434
- [Langchain](https://docs.langchain.com/oss/python/integrations/providers/localai) integration package [pypi](https://pypi.org/project/langchain-localai/)
3535

3636
Feel free to open up a Pull request (by clicking at the "Edit page" below) to get a page for your project made or if you see a error on one of the pages!
37+
38+
## Configuration Guides
39+
40+
This section provides step-by-step instructions for configuring specific software to work with LocalAI.
41+
42+
### OpenCode
43+
44+
[OpenCode](https://opencode.ai) is an AI-powered code editor that can be configured to use LocalAI as its backend provider.
45+
46+
#### Prerequisites
47+
48+
- LocalAI must be running and accessible (either locally or on a network)
49+
- You need to know your LocalAI server's IP address/hostname and port (default is `8080`)
50+
51+
#### Configuration Steps
52+
53+
1. **Edit the OpenCode configuration file**
54+
55+
Open the OpenCode configuration file located at `~/.config/opencode/opencode.json` in your editor.
56+
57+
2. **Add LocalAI provider configuration**
58+
59+
Add the following configuration to your `opencode.json` file, replacing the values with your own:
60+
61+
```json
62+
{
63+
"$schema": "https://opencode.ai/config.json",
64+
"provider": {
65+
"LocalAI": {
66+
"npm": "@ai-sdk/openai-compatible",
67+
"name": "LocalAI (local)",
68+
"options": {
69+
"baseURL": "http://127.0.0.1:8080/v1"
70+
},
71+
"models": {
72+
"Qwen3-Coder-30B-A3B-Instruct-i1-GGUF": {
73+
"name": "Qwen3-Coder-30B-A3B-Instruct-i1-GGUF",
74+
"limit": {
75+
"context": 38000,
76+
"output": 65536
77+
}
78+
},
79+
"qwen_qwen3-30b-a3b-instruct-2507": {
80+
"name": "qwen_qwen3-30b-a3b-instruct-2507",
81+
"limit": {
82+
"context": 38000,
83+
"output": 65536
84+
}
85+
}
86+
}
87+
}
88+
}
89+
}
90+
```
91+
92+
3. **Customize the configuration**
93+
94+
- **baseURL**: Replace `http://127.0.0.1:8080/v1` with your LocalAI server's address and port.
95+
- **name**: Change "LocalAI (local)" to a descriptive name for your setup.
96+
- **models**: Replace the model names with the actual model names available in your LocalAI instance. You can find available models by checking your LocalAI models directory or using the LocalAI API.
97+
- **limit**: Adjust the `context` and `output` token limits based on your model's capabilities and available resources.
98+
99+
4. **Verify your models**
100+
101+
Ensure that the model names in the configuration match exactly with the model names configured in your LocalAI instance. You can verify available models by checking your LocalAI configuration or using the `/v1/models` endpoint.
102+
103+
5. **Restart OpenCode**
104+
105+
After saving the configuration file, restart OpenCode for the changes to take effect.
106+
107+
108+
### GitHub Actions
109+
110+
You can use LocalAI in GitHub Actions workflows to perform AI-powered tasks like code review, diff summarization, or automated analysis. The [LocalAI GitHub Action](https://github.com/mudler/localai-github-action) makes it easy to spin up a LocalAI instance in your CI/CD pipeline.
111+
112+
#### Prerequisites
113+
114+
- A GitHub repository with Actions enabled
115+
- A model name from [models.localai.io](https://models.localai.io) or a Hugging Face model reference
116+
117+
#### Example Workflow
118+
119+
This example workflow demonstrates how to use LocalAI to summarize pull request diffs and send notifications:
120+
121+
1. **Create a workflow file**
122+
123+
Create a new file in your repository at `.github/workflows/localai.yml`:
124+
125+
```yaml
126+
name: Use LocalAI in GHA
127+
on:
128+
pull_request:
129+
types:
130+
- closed
131+
132+
jobs:
133+
notify-discord:
134+
if: ${{ (github.event.pull_request.merged == true) && (contains(github.event.pull_request.labels.*.name, 'area/ai-model')) }}
135+
env:
136+
MODEL_NAME: qwen_qwen3-4b-instruct-2507
137+
runs-on: ubuntu-latest
138+
steps:
139+
- uses: actions/checkout@v4
140+
with:
141+
fetch-depth: 0 # needed to checkout all branches for this Action to work
142+
# Starts the LocalAI container
143+
- id: foo
144+
uses: mudler/localai-github-action@v1.1
145+
with:
146+
model: 'qwen_qwen3-4b-instruct-2507' # Any from models.localai.io, or from huggingface.com with: "huggingface://<repository>/file"
147+
# Check the PR diff using the current branch and the base branch of the PR
148+
- uses: GrantBirki/git-diff-action@v2.7.0
149+
id: git-diff-action
150+
with:
151+
json_diff_file_output: diff.json
152+
raw_diff_file_output: diff.txt
153+
file_output_only: "true"
154+
# Ask to explain the diff to LocalAI
155+
- name: Summarize
156+
env:
157+
DIFF: ${{ steps.git-diff-action.outputs.raw-diff-path }}
158+
id: summarize
159+
run: |
160+
input="$(cat $DIFF)"
161+
162+
# Define the LocalAI API endpoint
163+
API_URL="http://localhost:8080/chat/completions"
164+
165+
# Create a JSON payload using jq to handle special characters
166+
json_payload=$(jq -n --arg input "$input" '{
167+
model: "'$MODEL_NAME'",
168+
messages: [
169+
{
170+
role: "system",
171+
content: "Write a message summarizing the change diffs"
172+
},
173+
{
174+
role: "user",
175+
content: $input
176+
}
177+
]
178+
}')
179+
180+
# Send the request to LocalAI
181+
response=$(curl -s -X POST $API_URL \
182+
-H "Content-Type: application/json" \
183+
-d "$json_payload")
184+
185+
# Extract the summary from the response
186+
summary="$(echo $response | jq -r '.choices[0].message.content')"
187+
188+
# Print the summary
189+
echo "Summary:"
190+
echo "$summary"
191+
echo "payload sent"
192+
echo "$json_payload"
193+
{
194+
echo 'message<<EOF'
195+
echo "$summary"
196+
echo EOF
197+
} >> "$GITHUB_OUTPUT"
198+
# Send the summary somewhere (e.g. Discord)
199+
- name: Discord notification
200+
env:
201+
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }}
202+
DISCORD_USERNAME: "discord-bot"
203+
DISCORD_AVATAR: ""
204+
uses: Ilshidur/action-discord@master
205+
with:
206+
args: ${{ steps.summarize.outputs.message }}
207+
```
208+
209+
#### Configuration Options
210+
211+
- **Model selection**: Replace `qwen_qwen3-4b-instruct-2507` with any model from [models.localai.io](https://models.localai.io). You can also use Hugging Face models by using the full huggingface model url`.
212+
- **Trigger conditions**: Customize the `if` condition to control when the workflow runs. The example only runs when a PR is merged and has a specific label.
213+
- **API endpoint**: The LocalAI container runs on `http://localhost:8080` by default. The action exposes the service on the standard port.
214+
- **Custom prompts**: Modify the system message in the JSON payload to change what LocalAI is asked to do with the diff.
215+
216+
#### Use Cases
217+
218+
- **Code review automation**: Automatically review code changes and provide feedback
219+
- **Diff summarization**: Generate human-readable summaries of code changes
220+
- **Documentation generation**: Create documentation from code changes
221+
- **Security scanning**: Analyze code for potential security issues
222+
- **Test generation**: Generate test cases based on code changes
223+
224+
#### Additional Resources
225+
226+
- [LocalAI GitHub Action repository](https://github.com/mudler/localai-github-action)
227+
- [Available models](https://models.localai.io)
228+
- [LocalAI API documentation](/reference/)
229+
230+
### Realtime Voice Assistant
231+
232+
LocalAI supports realtime voice interactions , enabling voice assistant applications with real-time speech-to-speech communication. A complete example implementation is available in the [LocalAI-examples repository](https://github.com/mudler/LocalAI-examples/tree/main/realtime).
233+
234+
#### Overview
235+
236+
The realtime voice assistant example demonstrates how to build a voice assistant that:
237+
- Captures audio input from the user in real-time
238+
- Transcribes speech to text using LocalAI's transcription capabilities
239+
- Processes the text with a language model
240+
- Generates audio responses using text-to-speech
241+
- Streams audio back to the user in real-time
242+
243+
#### Prerequisites
244+
245+
- A transcription model (e.g., Whisper) configured in LocalAI
246+
- A text-to-speech model configured in LocalAI
247+
- A language model for generating responses
248+
249+
#### Getting Started
250+
251+
1. **Clone the example repository**
252+
253+
```bash
254+
git clone https://github.com/mudler/LocalAI-examples.git
255+
cd LocalAI-examples/realtime
256+
```
257+
258+
2. **Start LocalAI with Docker Compose**
259+
260+
```bash
261+
docker compose up -d
262+
```
263+
264+
The first time you start docker compose, it will take a while to download the available models. You can follow the model downloads in real-time:
265+
266+
```bash
267+
docker logs -f realtime-localai-1
268+
```
269+
270+
3. **Install host dependencies**
271+
272+
Install the required host dependencies (sudo is required):
273+
274+
```bash
275+
sudo bash setup.sh
276+
```
277+
278+
4. **Run the voice assistant**
279+
280+
Start the voice assistant application:
281+
282+
```bash
283+
bash run.sh
284+
```
285+
286+
#### Configuration Notes
287+
288+
- **CPU vs GPU**: The example is optimized for CPU usage. However, you can run LocalAI with a GPU for better performance and to use bigger/better models.
289+
- **Python client**: The Python part downloads PyTorch for CPU, but this is fine as computation is offloaded to LocalAI. The Python client only runs Silero VAD (Voice Activity Detection), which is fast, and handles audio recording.
290+
- **Thin client architecture**: The Python client is designed to run on thin clients such as Raspberry PIs, while LocalAI handles the heavier computational workload on a more powerful machine.
291+
292+
#### Key Features
293+
294+
- **Real-time processing**: Low-latency audio streaming for natural conversations
295+
- **Voice Activity Detection (VAD)**: Automatic detection of when the user is speaking
296+
- **Turn-taking**: Handles conversation flow with proper turn detection
297+
- **OpenAI-compatible API**: Uses LocalAI's OpenAI-compatible realtime API endpoints
298+
299+
#### Use Cases
300+
301+
- **Voice assistants**: Build custom voice assistants for home automation or productivity
302+
- **Accessibility tools**: Create voice interfaces for accessibility applications
303+
- **Interactive applications**: Add voice interaction to games, educational software, or entertainment apps
304+
- **Customer service**: Implement voice-based customer support systems
305+
306+
#### Additional Resources
307+
308+
- [Realtime Voice Assistant Example](https://github.com/mudler/LocalAI-examples/tree/main/realtime)
309+
- [LocalAI Realtime API documentation](/features/)
310+
- [Audio features documentation](/features/text-to-audio/)
311+
- [Transcription features documentation](/features/audio-to-text/)

0 commit comments

Comments
 (0)