Nik Afiq 520f5d1ffb
Some checks failed
CI / build-ai-gateway (push) Has been cancelled
CI / build-ha-gateway (push) Has been cancelled
CI / build-discord-bot (push) Has been cancelled
CI / test (push) Has been cancelled
feat: add ai-gateway microservice with gRPC API for AI logic
- Implemented new gRPC service `AIService` in `proto/ai/v1/ai.proto` for handling natural language queries.
- Generated Go code for the gRPC service and messages in `gen/ai/v1/`.
- Created `services/ai-gateway/` directory structure with necessary files for the service.
- Added configuration loading and structured logging.
- Implemented domain logic for intent parsing and interaction with Home Assistant.
- Established outbound adapters for Ollama and Home Assistant with mTLS support.
- Updated `go.work` to include the new service and maintain existing dependencies.
- Modified `discord-bot` to use the new `ai-gateway` for AI interactions.
- Added deployment manifest for Kubernetes and CI/CD configuration for building and deploying the service.
2026-04-21 21:52:28 +09:00

46 lines
1.2 KiB
Go

package grpc
import (
"context"
"gitea.nik4nao.com/nik/home-services/ai-gateway/internal/app"
"gitea.nik4nao.com/nik/home-services/ai-gateway/internal/logger"
aiv1 "gitea.nik4nao.com/nik/home-services/gen/ai/v1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// Server adapts the AI query app to the gRPC transport.
type Server struct {
aiv1.UnimplementedAIServiceServer
app *app.QueryApp
}
// NewServer constructs the AIService gRPC adapter.
func NewServer(app *app.QueryApp) *Server {
return &Server{app: app}
}
// Query handles one AI query request.
func (s *Server) Query(ctx context.Context, req *aiv1.QueryRequest) (*aiv1.QueryResponse, error) {
if req.GetText() == "" {
return nil, status.Error(codes.InvalidArgument, "text is required")
}
log := logger.FromContext(ctx)
if req.GetSource() != "" {
log = log.With("source", req.GetSource())
ctx = logger.WithLogger(ctx, log)
}
result, err := s.app.Query(ctx, req.GetText())
if err != nil {
return nil, status.Errorf(codes.Unavailable, "query failed: %v", err)
}
return &aiv1.QueryResponse{
Reply: result.Reply,
Intent: result.Intent,
ActionTaken: result.ActionTaken,
}, nil
}