36 lines
812 B
Go
36 lines
812 B
Go
|
|
package server
|
||
|
|
|
||
|
|
import (
|
||
|
|
"net/http"
|
||
|
|
|
||
|
|
"play-life-llm/internal/handler"
|
||
|
|
"play-life-llm/internal/ollama"
|
||
|
|
"play-life-llm/internal/tavily"
|
||
|
|
|
||
|
|
"github.com/gorilla/mux"
|
||
|
|
)
|
||
|
|
|
||
|
|
// Config holds server and client configuration.
|
||
|
|
type Config struct {
|
||
|
|
OllamaHost string
|
||
|
|
TavilyAPIKey string
|
||
|
|
DefaultModel string
|
||
|
|
}
|
||
|
|
|
||
|
|
// NewRouter returns an HTTP router with /health and /ask registered.
|
||
|
|
func NewRouter(cfg Config) http.Handler {
|
||
|
|
ollamaClient := ollama.NewClient(cfg.OllamaHost)
|
||
|
|
tavilyClient := tavily.NewClient(cfg.TavilyAPIKey)
|
||
|
|
|
||
|
|
askHandler := &handler.AskHandler{
|
||
|
|
Ollama: ollamaClient,
|
||
|
|
Tavily: tavilyClient,
|
||
|
|
DefaultModel: cfg.DefaultModel,
|
||
|
|
}
|
||
|
|
|
||
|
|
r := mux.NewRouter()
|
||
|
|
r.HandleFunc("/health", handler.Health).Methods(http.MethodGet)
|
||
|
|
r.Handle("/ask", askHandler).Methods(http.MethodPost)
|
||
|
|
return r
|
||
|
|
}
|