Guides
Guides
Step-by-step recipes for the most common BRICQS workflows.
Build a streaming chat API
Deploy LLaMA 3 and stream tokens back to a browser client using Server-Sent Events.
1. Deploy the model
bricqs deploy chat-api --model meta-llama/Llama-3-8B-Instruct --min 12. Call with streaming
pythonfrom openai import OpenAI
client = OpenAI(
api_key="<your-api-key>",
base_url="https://<app-name>.bricqs.run/v1",
)
for chunk in client.chat.completions.create(
model="llama3:8b",
messages=[{"role": "user", "content": "Explain edge computing in one paragraph."}],
stream=True,
):
print(chunk.choices[0].delta.content or "", end="", flush=True)3. Forward from your backend to the browser
python# FastAPI example — stream the BRICQS response to the client
from fastapi import FastAPI
from fastapi.responses import StreamingResponse
import httpx
app = FastAPI()
@app.post("/chat")
async def chat(prompt: str):
async def gen():
async with httpx.AsyncClient() as c:
async with c.stream("POST", "<endpoint>/v1/chat/completions",
headers={"Authorization": "Bearer <key>"},
json={"model": "llama3:8b", "messages": [{"role":"user","content":prompt}], "stream": True},
) as r:
async for line in r.aiter_lines():
if line:
yield line + "\n"
return StreamingResponse(gen(), media_type="text/event-stream")Build a RAG pipeline
Index a set of documents into pgvector, then route user questions to a retrieval step before calling the LLM.
1. Set up pgvector
sqlCREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE docs (
id bigserial PRIMARY KEY,
text text,
emb vector(384)
);
CREATE INDEX ON docs USING ivfflat (emb vector_cosine_ops);2. Embed and index
pythonfrom sentence_transformers import SentenceTransformer
import psycopg2, os
model = SentenceTransformer("all-MiniLM-L6-v2")
conn = psycopg2.connect(os.environ["DATABASE_URL"])
cur = conn.cursor()
texts = ["BRICQS provides managed AI compute.", "pgvector stores dense embeddings."]
for t in texts:
emb = model.encode(t).tolist()
cur.execute("INSERT INTO docs (text, emb) VALUES (%s, %s)", (t, emb))
conn.commit()3. Query + generate
pythondef answer(question: str) -> str:
q_emb = model.encode(question).tolist()
cur.execute(
"SELECT text FROM docs ORDER BY emb <=> %s::vector LIMIT 3",
(q_emb,)
)
context = " ".join(r[0] for r in cur.fetchall())
resp = client.chat.completions.create(
model="llama3:8b",
messages=[
{"role": "system", "content": f"Use this context: {context}"},
{"role": "user", "content": question},
],
)
return resp.choices[0].message.contentDeploy from CI/CD (GitHub Actions)
Automatically deploy to a preview environment on every pull request, then promote to production on merge to main.
yamlname: Deploy
on:
pull_request:
branches: [main]
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Install CLI
run: pip install bricqs
- name: Configure credentials
run: |
mkdir -p ~/.bricqs
echo '{"access_token":"<BRICQS_TOKEN>","email":"ci@example.com"}' > ~/.bricqs/config.json
chmod 600 ~/.bricqs/config.json
- name: Deploy preview (PR only)
if: github.event_name == 'pull_request'
run: |
bricqs deploy pr-<PR_NUMBER> \
--model meta-llama/Llama-3-8B-Instruct \
--env preview
- name: Deploy production (main only)
if: github.ref == 'refs/heads/main'
run: |
bricqs deploy prod-api \
--model meta-llama/Llama-3-8B-Instruct \
--env productionNote: Store your BRICQS API token in Settings → Secrets → Actions → BRICQS_TOKEN in your GitHub repository. Never commit it in plaintext.
Whisper speech-to-text
Transcribe audio files using Whisper Large v3 deployed on BRICQS.
pythonimport httpx, base64, pathlib
audio_bytes = pathlib.Path("recording.mp3").read_bytes()
encoded = base64.b64encode(audio_bytes).decode()
resp = httpx.post(
"https://<app-name>.bricqs.run/transcribe",
headers={"Authorization": "Bearer <key>"},
json={"audio": encoded, "language": "en"},
)
print(resp.json()["text"])