feat(ingestion): add /ingest and /ingest-path HTTP handlers
Wires pipeline.Run into the HTTP layer so callers can ingest raw text or files/directories without touching the filesystem directly. Rewrites main.go to parse LLM and watcher env vars and build pipeline.Config. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,31 +5,70 @@ import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/mathiasbq/hyperguild/ingestion/internal/api"
|
||||
"github.com/mathiasbq/hyperguild/ingestion/internal/llm"
|
||||
"github.com/mathiasbq/hyperguild/ingestion/internal/pipeline"
|
||||
)
|
||||
|
||||
func envOr(key, fallback string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return v
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
func envInt(key string, fallback int) int {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil {
|
||||
return n
|
||||
}
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
func main() {
|
||||
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
|
||||
|
||||
brainDir := os.Getenv("INGEST_BRAIN_DIR")
|
||||
if brainDir == "" {
|
||||
brainDir = "../brain"
|
||||
brainDir := envOr("INGEST_BRAIN_DIR", "../brain")
|
||||
port := envOr("INGEST_PORT", "3300")
|
||||
|
||||
llmURL := envOr("INGEST_LLM_URL", "http://iguana:4000/v1")
|
||||
llmKey := os.Getenv("INGEST_LLM_KEY")
|
||||
llmModel := envOr("INGEST_LLM_MODEL", "koala/qwen35-9b-fast")
|
||||
llmTimeoutMins := envInt("INGEST_LLM_TIMEOUT", 15)
|
||||
chunkSize := envInt("INGEST_CHUNK_SIZE", 6000)
|
||||
watchInterval := envInt("INGEST_WATCH_INTERVAL", 30)
|
||||
|
||||
llmClient := llm.New(llmURL, llmKey, llmModel, time.Duration(llmTimeoutMins)*time.Minute)
|
||||
|
||||
pipelineCfg := pipeline.Config{
|
||||
Complete: llmClient.Complete,
|
||||
ChunkSize: chunkSize,
|
||||
}
|
||||
|
||||
port := os.Getenv("INGEST_PORT")
|
||||
if port == "" {
|
||||
port = "3300"
|
||||
}
|
||||
h := api.NewHandler(brainDir, logger, pipelineCfg)
|
||||
|
||||
h := api.NewHandler(brainDir, logger)
|
||||
// TODO(task11): start watcher when INGEST_WATCH_INTERVAL > 0
|
||||
_ = watchInterval
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/query", h.Query)
|
||||
mux.HandleFunc("/write", h.Write)
|
||||
mux.HandleFunc("/ingest", h.Ingest)
|
||||
mux.HandleFunc("/ingest-path", h.IngestPath)
|
||||
|
||||
addr := ":" + port
|
||||
logger.Info("ingestion server starting", "addr", addr, "brain_dir", brainDir)
|
||||
logger.Info("ingestion server starting",
|
||||
"addr", addr,
|
||||
"brain_dir", brainDir,
|
||||
"llm_url", llmURL,
|
||||
"llm_model", llmModel,
|
||||
"chunk_size", chunkSize,
|
||||
"watch_interval_s", watchInterval,
|
||||
)
|
||||
if err := http.ListenAndServe(addr, mux); err != nil {
|
||||
logger.Error("server stopped", "err", err)
|
||||
os.Exit(1)
|
||||
|
||||
Reference in New Issue
Block a user