Compare commits
13 Commits
32b7420c34
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 22eb918fb1 | |||
| 0174e31cf7 | |||
| b01057e11a | |||
| 7c0be6d00e | |||
| 6e498cc0d5 | |||
| d891140817 | |||
| d0115790e0 | |||
| ef4ef41404 | |||
| 39b1199617 | |||
| 3a82afd483 | |||
| fb2d58a87f | |||
| 653445b005 | |||
| b4ed7dd5b4 |
196
.gitea/workflows/build-push.yaml
Normal file
196
.gitea/workflows/build-push.yaml
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
env:
|
||||||
|
NTFY_URL: http://ntfy.observability.svc.cluster.local:80
|
||||||
|
GOPRIVATE: git.daviestechlabs.io
|
||||||
|
REGISTRY: gitea-http.gitea.svc.cluster.local:3000/daviestechlabs
|
||||||
|
REGISTRY_HOST: gitea-http.gitea.svc.cluster.local:3000
|
||||||
|
IMAGE_NAME: voice-assistant
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
name: Lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Configure private modules
|
||||||
|
run: git config --global url."https://gitea-actions:${{ secrets.DISPATCH_TOKEN }}@git.daviestechlabs.io/".insteadOf "https://git.daviestechlabs.io/"
|
||||||
|
|
||||||
|
- name: Run go vet
|
||||||
|
run: go vet ./...
|
||||||
|
|
||||||
|
- name: Install golangci-lint
|
||||||
|
run: |
|
||||||
|
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b "$(go env GOPATH)/bin"
|
||||||
|
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
|
||||||
|
|
||||||
|
- name: Run golangci-lint
|
||||||
|
run: golangci-lint run ./...
|
||||||
|
|
||||||
|
test:
|
||||||
|
name: Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Configure private modules
|
||||||
|
run: git config --global url."https://gitea-actions:${{ secrets.DISPATCH_TOKEN }}@git.daviestechlabs.io/".insteadOf "https://git.daviestechlabs.io/"
|
||||||
|
|
||||||
|
- name: Verify dependencies
|
||||||
|
run: go mod verify
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: go build -v ./...
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
|
||||||
|
|
||||||
|
release:
|
||||||
|
name: Release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [lint, test]
|
||||||
|
if: gitea.ref == 'refs/heads/main' && gitea.event_name == 'push'
|
||||||
|
outputs:
|
||||||
|
version: ${{ steps.version.outputs.version }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Determine version bump
|
||||||
|
id: version
|
||||||
|
run: |
|
||||||
|
# Get latest tag or default to v0.0.0
|
||||||
|
LATEST=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
||||||
|
VERSION=${LATEST#v}
|
||||||
|
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
|
||||||
|
|
||||||
|
# Check commit message for keywords
|
||||||
|
MSG="${{ gitea.event.head_commit.message }}"
|
||||||
|
if echo "$MSG" | grep -qiE "^major:|BREAKING CHANGE"; then
|
||||||
|
MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0
|
||||||
|
BUMP="major"
|
||||||
|
elif echo "$MSG" | grep -qiE "^(minor:|feat:)"; then
|
||||||
|
MINOR=$((MINOR + 1)); PATCH=0
|
||||||
|
BUMP="minor"
|
||||||
|
else
|
||||||
|
PATCH=$((PATCH + 1))
|
||||||
|
BUMP="patch"
|
||||||
|
fi
|
||||||
|
|
||||||
|
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
|
||||||
|
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
||||||
|
echo "bump=$BUMP" >> $GITHUB_OUTPUT
|
||||||
|
echo "Bumping $LATEST → $NEW_VERSION ($BUMP)"
|
||||||
|
|
||||||
|
- name: Create and push tag
|
||||||
|
run: |
|
||||||
|
git config user.name "gitea-actions[bot]"
|
||||||
|
git config user.email "actions@git.daviestechlabs.io"
|
||||||
|
git tag -a ${{ steps.version.outputs.version }} -m "Release ${{ steps.version.outputs.version }}"
|
||||||
|
git push origin ${{ steps.version.outputs.version }}
|
||||||
|
|
||||||
|
docker:
|
||||||
|
name: Docker Build & Push
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [lint, test, release]
|
||||||
|
if: gitea.ref == 'refs/heads/main' && gitea.event_name == 'push'
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Configure insecure registry
|
||||||
|
run: |
|
||||||
|
sudo mkdir -p /etc/docker
|
||||||
|
echo '{"insecure-registries": ["${{ env.REGISTRY_HOST }}"]}' | sudo tee /etc/docker/daemon.json
|
||||||
|
sudo kill -SIGHUP "$(pidof dockerd)" || true
|
||||||
|
sleep 3
|
||||||
|
|
||||||
|
- name: Login to Gitea Registry
|
||||||
|
run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "${{ env.REGISTRY_HOST }}" -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
||||||
|
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
if: vars.DOCKERHUB_USERNAME != ''
|
||||||
|
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ vars.DOCKERHUB_USERNAME }}" --password-stdin
|
||||||
|
|
||||||
|
- name: Extract metadata
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
tags: |
|
||||||
|
type=raw,value=${{ needs.release.outputs.version }}
|
||||||
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
run: |
|
||||||
|
# Build with all tags
|
||||||
|
TAGS=""
|
||||||
|
while IFS= read -r tag; do
|
||||||
|
[ -n "$tag" ] && TAGS="$TAGS -t $tag"
|
||||||
|
done <<< "${{ steps.meta.outputs.tags }}"
|
||||||
|
docker build $TAGS \
|
||||||
|
--label "org.opencontainers.image.source=${{ gitea.server_url }}/${{ gitea.repository }}" \
|
||||||
|
--label "org.opencontainers.image.revision=${{ gitea.sha }}" \
|
||||||
|
.
|
||||||
|
# Push each tag
|
||||||
|
while IFS= read -r tag; do
|
||||||
|
[ -n "$tag" ] && docker push "$tag"
|
||||||
|
done <<< "${{ steps.meta.outputs.tags }}"
|
||||||
|
|
||||||
|
|
||||||
|
notify:
|
||||||
|
name: Notify
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [lint, test, release, docker]
|
||||||
|
if: always()
|
||||||
|
steps:
|
||||||
|
- name: Notify on success
|
||||||
|
if: needs.lint.result == 'success' && needs.test.result == 'success'
|
||||||
|
run: |
|
||||||
|
curl -s \
|
||||||
|
-H "Title: ✅ CI Passed: ${{ gitea.repository }}" \
|
||||||
|
-H "Priority: default" \
|
||||||
|
-H "Tags: white_check_mark,github" \
|
||||||
|
-H "Click: ${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}" \
|
||||||
|
-d "Branch: ${{ gitea.ref_name }}
|
||||||
|
Commit: ${{ gitea.event.head_commit.message || gitea.sha }}
|
||||||
|
Release: ${{ needs.release.result == 'success' && needs.release.outputs.version || 'skipped' }}
|
||||||
|
Docker: ${{ needs.docker.result }}" \
|
||||||
|
${{ env.NTFY_URL }}/gitea-ci
|
||||||
|
|
||||||
|
- name: Notify on failure
|
||||||
|
if: needs.lint.result == 'failure' || needs.test.result == 'failure'
|
||||||
|
run: |
|
||||||
|
curl -s \
|
||||||
|
-H "Title: ❌ CI Failed: ${{ gitea.repository }}" \
|
||||||
|
-H "Priority: high" \
|
||||||
|
-H "Tags: x,github" \
|
||||||
|
-H "Click: ${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}" \
|
||||||
|
-d "Branch: ${{ gitea.ref_name }}
|
||||||
|
Commit: ${{ gitea.event.head_commit.message || gitea.sha }}
|
||||||
|
Lint: ${{ needs.lint.result }}
|
||||||
|
Test: ${{ needs.test.result }}" \
|
||||||
|
${{ env.NTFY_URL }}/gitea-ci
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
name: CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
pull_request:
|
|
||||||
branches: [main]
|
|
||||||
|
|
||||||
env:
|
|
||||||
NTFY_URL: http://ntfy.observability.svc.cluster.local:80
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
lint:
|
|
||||||
name: Lint
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up uv
|
|
||||||
run: curl -LsSf https://astral.sh/uv/install.sh | sh && echo "$HOME/.local/bin" >> $GITHUB_PATH
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
run: uv python install 3.13
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: uv sync --frozen --extra dev
|
|
||||||
|
|
||||||
- name: Run ruff check
|
|
||||||
run: uv run ruff check .
|
|
||||||
|
|
||||||
- name: Run ruff format check
|
|
||||||
run: uv run ruff format --check .
|
|
||||||
|
|
||||||
test:
|
|
||||||
name: Test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up uv
|
|
||||||
run: curl -LsSf https://astral.sh/uv/install.sh | sh && echo "$HOME/.local/bin" >> $GITHUB_PATH
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
run: uv python install 3.13
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: uv sync --frozen --extra dev
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: uv run pytest -v
|
|
||||||
|
|
||||||
release:
|
|
||||||
name: Release
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [lint, test]
|
|
||||||
if: gitea.ref == 'refs/heads/main' && gitea.event_name == 'push'
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Determine version bump
|
|
||||||
id: version
|
|
||||||
run: |
|
|
||||||
# Get latest tag or default to v0.0.0
|
|
||||||
LATEST=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
|
||||||
VERSION=${LATEST#v}
|
|
||||||
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
|
|
||||||
|
|
||||||
# Check commit message for keywords
|
|
||||||
MSG="${{ gitea.event.head_commit.message }}"
|
|
||||||
if echo "$MSG" | grep -qiE "^major:|BREAKING CHANGE"; then
|
|
||||||
MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0
|
|
||||||
BUMP="major"
|
|
||||||
elif echo "$MSG" | grep -qiE "^(minor:|feat:)"; then
|
|
||||||
MINOR=$((MINOR + 1)); PATCH=0
|
|
||||||
BUMP="minor"
|
|
||||||
else
|
|
||||||
PATCH=$((PATCH + 1))
|
|
||||||
BUMP="patch"
|
|
||||||
fi
|
|
||||||
|
|
||||||
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
|
|
||||||
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
|
||||||
echo "bump=$BUMP" >> $GITHUB_OUTPUT
|
|
||||||
echo "Bumping $LATEST → $NEW_VERSION ($BUMP)"
|
|
||||||
|
|
||||||
- name: Create and push tag
|
|
||||||
run: |
|
|
||||||
git config user.name "gitea-actions[bot]"
|
|
||||||
git config user.email "actions@git.daviestechlabs.io"
|
|
||||||
git tag -a ${{ steps.version.outputs.version }} -m "Release ${{ steps.version.outputs.version }}"
|
|
||||||
git push origin ${{ steps.version.outputs.version }}
|
|
||||||
|
|
||||||
notify:
|
|
||||||
name: Notify
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [lint, test, release]
|
|
||||||
if: always()
|
|
||||||
steps:
|
|
||||||
- name: Notify on success
|
|
||||||
if: needs.lint.result == 'success' && needs.test.result == 'success'
|
|
||||||
run: |
|
|
||||||
curl -s \
|
|
||||||
-H "Title: ✅ CI Passed: ${{ gitea.repository }}" \
|
|
||||||
-H "Priority: default" \
|
|
||||||
-H "Tags: white_check_mark,github" \
|
|
||||||
-H "Click: ${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}" \
|
|
||||||
-d "Branch: ${{ gitea.ref_name }}
|
|
||||||
Commit: ${{ gitea.event.head_commit.message || gitea.sha }}
|
|
||||||
Release: ${{ needs.release.result == 'success' && 'created' || 'skipped' }}" \
|
|
||||||
${{ env.NTFY_URL }}/gitea-ci
|
|
||||||
|
|
||||||
- name: Notify on failure
|
|
||||||
if: needs.lint.result == 'failure' || needs.test.result == 'failure'
|
|
||||||
run: |
|
|
||||||
curl -s \
|
|
||||||
-H "Title: ❌ CI Failed: ${{ gitea.repository }}" \
|
|
||||||
-H "Priority: high" \
|
|
||||||
-H "Tags: x,github" \
|
|
||||||
-H "Click: ${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}" \
|
|
||||||
-d "Branch: ${{ gitea.ref_name }}
|
|
||||||
Commit: ${{ gitea.event.head_commit.message || gitea.sha }}
|
|
||||||
Lint: ${{ needs.lint.result }}
|
|
||||||
Test: ${{ needs.test.result }}" \
|
|
||||||
${{ env.NTFY_URL }}/gitea-ci
|
|
||||||
60
.gitea/workflows/update-dependency.yml
Normal file
60
.gitea/workflows/update-dependency.yml
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
name: Update handler-base
|
||||||
|
|
||||||
|
on:
|
||||||
|
repository_dispatch:
|
||||||
|
types: [handler-base-release]
|
||||||
|
|
||||||
|
env:
|
||||||
|
NTFY_URL: http://ntfy.observability.svc.cluster.local:80
|
||||||
|
GOPRIVATE: git.daviestechlabs.io
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
update:
|
||||||
|
name: Update handler-base dependency
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.DISPATCH_TOKEN }}
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Configure Git
|
||||||
|
run: |
|
||||||
|
git config user.name "gitea-actions[bot]"
|
||||||
|
git config user.email "actions@git.daviestechlabs.io"
|
||||||
|
git config --global url."https://gitea-actions:${{ secrets.DISPATCH_TOKEN }}@git.daviestechlabs.io/".insteadOf "https://git.daviestechlabs.io/"
|
||||||
|
|
||||||
|
- name: Update handler-base
|
||||||
|
run: |
|
||||||
|
VERSION="${{ gitea.event.client_payload.version }}"
|
||||||
|
echo "Updating handler-base to ${VERSION}"
|
||||||
|
go get git.daviestechlabs.io/daviestechlabs/handler-base@${VERSION}
|
||||||
|
go mod tidy
|
||||||
|
|
||||||
|
- name: Commit and push
|
||||||
|
run: |
|
||||||
|
VERSION="${{ gitea.event.client_payload.version }}"
|
||||||
|
if git diff --quiet go.mod go.sum; then
|
||||||
|
echo "No changes to commit"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
git add go.mod go.sum
|
||||||
|
git commit -m "chore(deps): bump handler-base to ${VERSION}"
|
||||||
|
git push
|
||||||
|
|
||||||
|
- name: Notify
|
||||||
|
if: success()
|
||||||
|
run: |
|
||||||
|
VERSION="${{ gitea.event.client_payload.version }}"
|
||||||
|
curl -s \
|
||||||
|
-H "Title: 📦 Dep Update: ${{ gitea.repository }}" \
|
||||||
|
-H "Priority: default" \
|
||||||
|
-H "Tags: package,github" \
|
||||||
|
-d "handler-base updated to ${VERSION}" \
|
||||||
|
${{ env.NTFY_URL }}/gitea-ci
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -35,6 +35,7 @@ ENV/
|
|||||||
# Compiled KFP pipelines
|
# Compiled KFP pipelines
|
||||||
*.yaml
|
*.yaml
|
||||||
!.pre-commit-config.yaml
|
!.pre-commit-config.yaml
|
||||||
|
!.gitea/**/*.yaml
|
||||||
!pipelines/*.py
|
!pipelines/*.py
|
||||||
|
|
||||||
# Local
|
# Local
|
||||||
|
|||||||
@@ -3,10 +3,13 @@ FROM golang:1.25-alpine AS builder
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN apk add --no-cache ca-certificates
|
RUN apk add --no-cache ca-certificates git
|
||||||
|
|
||||||
|
ENV GOPRIVATE=git.daviestechlabs.io
|
||||||
|
ENV GONOSUMCHECK=git.daviestechlabs.io
|
||||||
|
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN --mount=type=secret,id=netrc,target=/root/.netrc go mod download
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
|||||||
26
e2e_test.go
26
e2e_test.go
@@ -28,26 +28,26 @@ func newVoiceMocks(t *testing.T) *voiceMocks {
|
|||||||
m := &voiceMocks{}
|
m := &voiceMocks{}
|
||||||
|
|
||||||
m.STT = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
m.STT = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
json.NewEncoder(w).Encode(map[string]string{"text": "What is the weather today?"})
|
_ = json.NewEncoder(w).Encode(map[string]string{"text": "What is the weather today?"})
|
||||||
}))
|
}))
|
||||||
t.Cleanup(m.STT.Close)
|
t.Cleanup(m.STT.Close)
|
||||||
|
|
||||||
m.Embeddings = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
m.Embeddings = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
json.NewEncoder(w).Encode(map[string]any{
|
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||||
"data": []map[string]any{{"embedding": []float64{0.5, 0.6, 0.7}}},
|
"data": []map[string]any{{"embedding": []float64{0.5, 0.6, 0.7}}},
|
||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
t.Cleanup(m.Embeddings.Close)
|
t.Cleanup(m.Embeddings.Close)
|
||||||
|
|
||||||
m.Reranker = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
m.Reranker = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
json.NewEncoder(w).Encode(map[string]any{
|
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||||
"results": []map[string]any{{"index": 0, "relevance_score": 0.88}},
|
"results": []map[string]any{{"index": 0, "relevance_score": 0.88}},
|
||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
t.Cleanup(m.Reranker.Close)
|
t.Cleanup(m.Reranker.Close)
|
||||||
|
|
||||||
m.LLM = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
m.LLM = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
json.NewEncoder(w).Encode(map[string]any{
|
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||||
"choices": []map[string]any{
|
"choices": []map[string]any{
|
||||||
{"message": map[string]any{"content": "Sunny with a high of 72."}},
|
{"message": map[string]any{"content": "Sunny with a high of 72."}},
|
||||||
},
|
},
|
||||||
@@ -56,7 +56,7 @@ func newVoiceMocks(t *testing.T) *voiceMocks {
|
|||||||
t.Cleanup(m.LLM.Close)
|
t.Cleanup(m.LLM.Close)
|
||||||
|
|
||||||
m.TTS = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
m.TTS = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write(make([]byte, 8000)) // simulated audio
|
_, _ = w.Write(make([]byte, 8000)) // simulated audio
|
||||||
}))
|
}))
|
||||||
t.Cleanup(m.TTS.Close)
|
t.Cleanup(m.TTS.Close)
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ func TestVoicePipeline_FullFlow(t *testing.T) {
|
|||||||
func TestVoicePipeline_STTFailure(t *testing.T) {
|
func TestVoicePipeline_STTFailure(t *testing.T) {
|
||||||
failSTT := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
failSTT := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(500)
|
w.WriteHeader(500)
|
||||||
w.Write([]byte("model not loaded"))
|
_, _ = w.Write([]byte("model not loaded"))
|
||||||
}))
|
}))
|
||||||
defer failSTT.Close()
|
defer failSTT.Close()
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ func TestVoicePipeline_STTFailure(t *testing.T) {
|
|||||||
func TestVoicePipeline_TTSLargeResponse(t *testing.T) {
|
func TestVoicePipeline_TTSLargeResponse(t *testing.T) {
|
||||||
// TTS that returns 1 MB of audio.
|
// TTS that returns 1 MB of audio.
|
||||||
bigTTS := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
bigTTS := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write(make([]byte, 1<<20))
|
_, _ = w.Write(make([]byte, 1<<20))
|
||||||
}))
|
}))
|
||||||
defer bigTTS.Close()
|
defer bigTTS.Close()
|
||||||
|
|
||||||
@@ -156,17 +156,17 @@ func TestVoicePipeline_TTSLargeResponse(t *testing.T) {
|
|||||||
|
|
||||||
func BenchmarkVoicePipeline_Full(b *testing.B) {
|
func BenchmarkVoicePipeline_Full(b *testing.B) {
|
||||||
sttSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
sttSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write([]byte(`{"text":"hello"}`))
|
_, _ = w.Write([]byte(`{"text":"hello"}`))
|
||||||
}))
|
}))
|
||||||
defer sttSrv.Close()
|
defer sttSrv.Close()
|
||||||
|
|
||||||
llmSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
llmSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write([]byte(`{"choices":[{"message":{"content":"answer"}}]}`))
|
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"answer"}}]}`))
|
||||||
}))
|
}))
|
||||||
defer llmSrv.Close()
|
defer llmSrv.Close()
|
||||||
|
|
||||||
ttsSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ttsSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write(make([]byte, 4000))
|
_, _ = w.Write(make([]byte, 4000))
|
||||||
}))
|
}))
|
||||||
defer ttsSrv.Close()
|
defer ttsSrv.Close()
|
||||||
|
|
||||||
@@ -178,8 +178,8 @@ func BenchmarkVoicePipeline_Full(b *testing.B) {
|
|||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for b.Loop() {
|
for b.Loop() {
|
||||||
stt.Transcribe(ctx, audio, "en")
|
_, _ = stt.Transcribe(ctx, audio, "en")
|
||||||
llm.Generate(ctx, "question", "", "")
|
_, _ = llm.Generate(ctx, "question", "", "")
|
||||||
tts.Synthesize(ctx, "answer", "en", "")
|
_, _ = tts.Synthesize(ctx, "answer", "en", "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
go.mod
8
go.mod
@@ -3,8 +3,9 @@ module git.daviestechlabs.io/daviestechlabs/voice-assistant
|
|||||||
go 1.25.1
|
go 1.25.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.daviestechlabs.io/daviestechlabs/handler-base v0.0.0
|
git.daviestechlabs.io/daviestechlabs/handler-base v1.0.0
|
||||||
github.com/nats-io/nats.go v1.48.0
|
github.com/nats-io/nats.go v1.48.0
|
||||||
|
google.golang.org/protobuf v1.36.11
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@@ -18,8 +19,6 @@ require (
|
|||||||
github.com/klauspost/compress v1.18.0 // indirect
|
github.com/klauspost/compress v1.18.0 // indirect
|
||||||
github.com/nats-io/nkeys v0.4.11 // indirect
|
github.com/nats-io/nkeys v0.4.11 // indirect
|
||||||
github.com/nats-io/nuid v1.0.1 // indirect
|
github.com/nats-io/nuid v1.0.1 // indirect
|
||||||
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
|
|
||||||
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
|
||||||
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
||||||
go.opentelemetry.io/otel v1.40.0 // indirect
|
go.opentelemetry.io/otel v1.40.0 // indirect
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.40.0 // indirect
|
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.40.0 // indirect
|
||||||
@@ -37,7 +36,4 @@ require (
|
|||||||
google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409 // indirect
|
google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409 // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 // indirect
|
||||||
google.golang.org/grpc v1.78.0 // indirect
|
google.golang.org/grpc v1.78.0 // indirect
|
||||||
google.golang.org/protobuf v1.36.11 // indirect
|
|
||||||
)
|
)
|
||||||
|
|
||||||
replace git.daviestechlabs.io/daviestechlabs/handler-base => ../handler-base
|
|
||||||
|
|||||||
6
go.sum
6
go.sum
@@ -1,3 +1,5 @@
|
|||||||
|
git.daviestechlabs.io/daviestechlabs/handler-base v1.0.0 h1:pB3ehOKaDYQfbyRBKQXrB9curqSFteLrDveoElRKnBY=
|
||||||
|
git.daviestechlabs.io/daviestechlabs/handler-base v1.0.0/go.mod h1:zocOHFt8yY3cW4+Xi37sNr5Tw7KcjGFSZqgWYxPWyqA=
|
||||||
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||||
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
@@ -31,10 +33,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
|
|
||||||
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
|
|
||||||
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
|
|
||||||
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
|
|
||||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||||
go.opentelemetry.io/otel v1.40.0 h1:oA5YeOcpRTXq6NN7frwmwFR0Cn3RhTVZvXsP4duvCms=
|
go.opentelemetry.io/otel v1.40.0 h1:oA5YeOcpRTXq6NN7frwmwFR0Cn3RhTVZvXsP4duvCms=
|
||||||
|
|||||||
19
main.go
19
main.go
@@ -16,6 +16,7 @@ import (
|
|||||||
"git.daviestechlabs.io/daviestechlabs/handler-base/handler"
|
"git.daviestechlabs.io/daviestechlabs/handler-base/handler"
|
||||||
"git.daviestechlabs.io/daviestechlabs/handler-base/messages"
|
"git.daviestechlabs.io/daviestechlabs/handler-base/messages"
|
||||||
"git.daviestechlabs.io/daviestechlabs/handler-base/natsutil"
|
"git.daviestechlabs.io/daviestechlabs/handler-base/natsutil"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -43,13 +44,13 @@ func main() {
|
|||||||
|
|
||||||
h := handler.New("voice.request", cfg)
|
h := handler.New("voice.request", cfg)
|
||||||
|
|
||||||
h.OnTypedMessage(func(ctx context.Context, msg *nats.Msg) (any, error) {
|
h.OnTypedMessage(func(ctx context.Context, msg *nats.Msg) (proto.Message, error) {
|
||||||
req, err := natsutil.Decode[messages.VoiceRequest](msg.Data)
|
var req messages.VoiceRequest
|
||||||
if err != nil {
|
if err := natsutil.Decode(msg.Data, &req); err != nil {
|
||||||
return &messages.VoiceResponse{Error: "Invalid request encoding"}, nil
|
return &messages.VoiceResponse{Error: "Invalid request encoding"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
requestID := req.RequestID
|
requestID := req.RequestId
|
||||||
if requestID == "" {
|
if requestID == "" {
|
||||||
requestID = "unknown"
|
requestID = "unknown"
|
||||||
}
|
}
|
||||||
@@ -64,8 +65,8 @@ func main() {
|
|||||||
|
|
||||||
slog.Info("processing voice request", "request_id", requestID)
|
slog.Info("processing voice request", "request_id", requestID)
|
||||||
|
|
||||||
errResp := func(msg string) (any, error) {
|
errResp := func(msg string) (proto.Message, error) {
|
||||||
return &messages.VoiceResponse{RequestID: requestID, Error: msg}, nil
|
return &messages.VoiceResponse{RequestId: requestID, Error: msg}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. Audio arrives as raw bytes — no base64 decode needed
|
// 1. Audio arrives as raw bytes — no base64 decode needed
|
||||||
@@ -146,7 +147,7 @@ func main() {
|
|||||||
|
|
||||||
// Build typed response
|
// Build typed response
|
||||||
result := &messages.VoiceResponse{
|
result := &messages.VoiceResponse{
|
||||||
RequestID: requestID,
|
RequestId: requestID,
|
||||||
Response: responseText,
|
Response: responseText,
|
||||||
Audio: responseAudio,
|
Audio: responseAudio,
|
||||||
}
|
}
|
||||||
@@ -160,13 +161,13 @@ func main() {
|
|||||||
if len(documents) < limit {
|
if len(documents) < limit {
|
||||||
limit = len(documents)
|
limit = len(documents)
|
||||||
}
|
}
|
||||||
result.Sources = make([]messages.DocumentSource, limit)
|
result.Sources = make([]*messages.DocumentSource, limit)
|
||||||
for i := 0; i < limit; i++ {
|
for i := 0; i < limit; i++ {
|
||||||
text := documents[i].Document
|
text := documents[i].Document
|
||||||
if len(text) > 200 {
|
if len(text) > 200 {
|
||||||
text = text[:200]
|
text = text[:200]
|
||||||
}
|
}
|
||||||
result.Sources[i] = messages.DocumentSource{Text: text, Score: documents[i].Score}
|
result.Sources[i] = &messages.DocumentSource{Text: text, Score: documents[i].Score}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
26
main_test.go
26
main_test.go
@@ -5,26 +5,26 @@ import (
|
|||||||
|
|
||||||
"git.daviestechlabs.io/daviestechlabs/handler-base/messages"
|
"git.daviestechlabs.io/daviestechlabs/handler-base/messages"
|
||||||
"git.daviestechlabs.io/daviestechlabs/handler-base/natsutil"
|
"git.daviestechlabs.io/daviestechlabs/handler-base/natsutil"
|
||||||
"github.com/vmihailenco/msgpack/v5"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVoiceRequestDecode(t *testing.T) {
|
func TestVoiceRequestDecode(t *testing.T) {
|
||||||
req := messages.VoiceRequest{
|
req := &messages.VoiceRequest{
|
||||||
RequestID: "req-123",
|
RequestId: "req-123",
|
||||||
Audio: []byte{0x01, 0x02, 0x03},
|
Audio: []byte{0x01, 0x02, 0x03},
|
||||||
Language: "en",
|
Language: "en",
|
||||||
Collection: "docs",
|
Collection: "docs",
|
||||||
}
|
}
|
||||||
data, err := msgpack.Marshal(&req)
|
data, err := proto.Marshal(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
decoded, err := natsutil.Decode[messages.VoiceRequest](data)
|
var decoded messages.VoiceRequest
|
||||||
if err != nil {
|
if err := natsutil.Decode(data, &decoded); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if decoded.RequestID != "req-123" {
|
if decoded.RequestId != "req-123" {
|
||||||
t.Errorf("RequestID = %q", decoded.RequestID)
|
t.Errorf("RequestId = %q", decoded.RequestId)
|
||||||
}
|
}
|
||||||
if len(decoded.Audio) != 3 {
|
if len(decoded.Audio) != 3 {
|
||||||
t.Errorf("Audio len = %d", len(decoded.Audio))
|
t.Errorf("Audio len = %d", len(decoded.Audio))
|
||||||
@@ -32,19 +32,19 @@ func TestVoiceRequestDecode(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestVoiceResponseRoundtrip(t *testing.T) {
|
func TestVoiceResponseRoundtrip(t *testing.T) {
|
||||||
resp := messages.VoiceResponse{
|
resp := &messages.VoiceResponse{
|
||||||
RequestID: "req-456",
|
RequestId: "req-456",
|
||||||
Response: "It is sunny today.",
|
Response: "It is sunny today.",
|
||||||
Audio: make([]byte, 8000),
|
Audio: make([]byte, 8000),
|
||||||
Transcription: "What is the weather?",
|
Transcription: "What is the weather?",
|
||||||
Sources: []messages.DocumentSource{{Text: "weather doc", Score: 0.9}},
|
Sources: []*messages.DocumentSource{{Text: "weather doc", Score: 0.9}},
|
||||||
}
|
}
|
||||||
data, err := msgpack.Marshal(&resp)
|
data, err := proto.Marshal(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
var got messages.VoiceResponse
|
var got messages.VoiceResponse
|
||||||
if err := msgpack.Unmarshal(data, &got); err != nil {
|
if err := proto.Unmarshal(data, &got); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if got.Response != "It is sunny today." {
|
if got.Response != "It is sunny today." {
|
||||||
|
|||||||
Reference in New Issue
Block a user