Route monitoring TG classification through AI service
Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 5s
Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 5s
This commit is contained in:
@@ -20,6 +20,8 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"monitoring-tg/internal/aiservice"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/minio/minio-go/v7"
|
||||
@@ -43,10 +45,10 @@ type config struct {
|
||||
PostgresPort int
|
||||
PollIntervalSeconds int
|
||||
LLMEnabled bool
|
||||
LLMBaseURL string
|
||||
LLMAPIKey string
|
||||
LLMModel string
|
||||
LLMTimeout time.Duration
|
||||
AIServiceURL string
|
||||
AIServiceToken string
|
||||
MinioEndpoint string
|
||||
MinioAccessKey string
|
||||
MinioSecretKey string
|
||||
@@ -62,6 +64,7 @@ type app struct {
|
||||
http *http.Client
|
||||
python *http.Client
|
||||
minio *minio.Client
|
||||
ai *aiservice.Client
|
||||
}
|
||||
|
||||
type accessScope struct {
|
||||
@@ -149,6 +152,7 @@ func main() {
|
||||
http: &http.Client{Timeout: cfg.LLMTimeout},
|
||||
python: &http.Client{Timeout: 15 * time.Minute},
|
||||
minio: minioClient,
|
||||
ai: aiservice.New(cfg.AIServiceURL, cfg.AIServiceToken, cfg.LLMTimeout),
|
||||
}
|
||||
|
||||
server := &http.Server{
|
||||
@@ -1118,24 +1122,32 @@ func (a *app) handleStats(ctx context.Context, w http.ResponseWriter, r *http.Re
|
||||
|
||||
func (a *app) handleLLMStatus(ctx context.Context, w http.ResponseWriter) {
|
||||
ready := false
|
||||
var providerError string
|
||||
model := a.cfg.LLMModel
|
||||
if a.cfg.LLMEnabled {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, strings.TrimRight(a.cfg.LLMBaseURL, "/")+"/v1/models", nil)
|
||||
if err == nil {
|
||||
if a.cfg.LLMAPIKey != "" {
|
||||
req.Header.Set("Authorization", "Bearer "+a.cfg.LLMAPIKey)
|
||||
}
|
||||
resp, err := a.http.Do(req)
|
||||
if err == nil {
|
||||
ready = resp.StatusCode >= 200 && resp.StatusCode < 300
|
||||
_ = resp.Body.Close()
|
||||
status, err := a.ai.ProvidersStatus(ctx)
|
||||
if err != nil {
|
||||
providerError = err.Error()
|
||||
} else {
|
||||
for _, provider := range status.Providers {
|
||||
if provider.Name == "llm" {
|
||||
ready = provider.Configured && provider.OK
|
||||
providerError = provider.Error
|
||||
if provider.Model != "" {
|
||||
model = provider.Model
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{
|
||||
"enabled": a.cfg.LLMEnabled,
|
||||
"ready": ready,
|
||||
"base_url": a.cfg.LLMBaseURL,
|
||||
"model": a.cfg.LLMModel,
|
||||
"enabled": a.cfg.LLMEnabled,
|
||||
"ready": ready,
|
||||
"base_url": a.cfg.AIServiceURL,
|
||||
"model": model,
|
||||
"provider": "ai-service",
|
||||
"provider_error": providerError,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1777,10 +1789,10 @@ func loadConfig() config {
|
||||
PostgresPort: envInt("POSTGRES_PORT", 5432),
|
||||
PollIntervalSeconds: envInt("POLL_INTERVAL_SECONDS", 60),
|
||||
LLMEnabled: envBool("LLM_ENABLED", true),
|
||||
LLMBaseURL: env("LLM_BASE_URL", "http://10.2.3.5:8002"),
|
||||
LLMAPIKey: env("LLM_API_KEY", ""),
|
||||
LLMModel: env("LLM_MODEL", "qwen2.5-14b"),
|
||||
LLMTimeout: time.Duration(envInt("LLM_TIMEOUT_SECONDS", 120)) * time.Second,
|
||||
AIServiceURL: env("AI_SERVICE_URL", ""),
|
||||
AIServiceToken: env("AI_SERVICE_TOKEN", ""),
|
||||
MinioEndpoint: env("MINIO_ENDPOINT", ""),
|
||||
MinioAccessKey: env("MINIO_ACCESS_KEY", ""),
|
||||
MinioSecretKey: env("MINIO_SECRET_KEY", ""),
|
||||
|
||||
Reference in New Issue
Block a user