Re-order main

This commit is contained in:
Ettore Di Giacinto
2025-02-26 22:45:50 +01:00
parent 0a18d8409e
commit 43c29fbdb0

30
main.go
View File

@@ -3,6 +3,7 @@ package main
import ( import (
"log" "log"
"os" "os"
"path/filepath"
"github.com/mudler/local-agent-framework/core/agent" "github.com/mudler/local-agent-framework/core/agent"
"github.com/mudler/local-agent-framework/core/state" "github.com/mudler/local-agent-framework/core/state"
@@ -17,8 +18,7 @@ var apiKey = os.Getenv("API_KEY")
var vectorStore = os.Getenv("VECTOR_STORE") var vectorStore = os.Getenv("VECTOR_STORE")
var timeout = os.Getenv("TIMEOUT") var timeout = os.Getenv("TIMEOUT")
var embeddingModel = os.Getenv("EMBEDDING_MODEL") var embeddingModel = os.Getenv("EMBEDDING_MODEL")
var stateDir = os.Getenv("STATE_DIR")
const defaultChunkSize = 4098
func init() { func init() {
if testModel == "" { if testModel == "" {
@@ -30,19 +30,17 @@ func init() {
if timeout == "" { if timeout == "" {
timeout = "5m" timeout = "5m"
} }
} if stateDir == "" {
func main() {
// current dir
cwd, err := os.Getwd() cwd, err := os.Getwd()
if err != nil { if err != nil {
panic(err) panic(err)
} }
stateDir := cwd + "/pool" stateDir = filepath.Join(cwd, "pool")
os.MkdirAll(stateDir, 0755) }
}
var ragDB agent.RAGDB func ragDB() (ragDB agent.RAGDB) {
lai := llm.NewClient(apiKey, apiURL+"/v1", timeout) lai := llm.NewClient(apiKey, apiURL+"/v1", timeout)
switch vectorStore { switch vectorStore {
@@ -57,16 +55,30 @@ func main() {
} }
} }
return
}
func main() {
// make sure state dir exists
os.MkdirAll(stateDir, 0755)
// Initialize rag DB connection
ragDB := ragDB()
// Create the agent pool
pool, err := state.NewAgentPool(testModel, apiURL, stateDir, ragDB, webui.Actions, webui.Connectors, timeout) pool, err := state.NewAgentPool(testModel, apiURL, stateDir, ragDB, webui.Actions, webui.Connectors, timeout)
if err != nil { if err != nil {
panic(err) panic(err)
} }
// Create the application
app := webui.NewApp(webui.WithPool(pool)) app := webui.NewApp(webui.WithPool(pool))
// Start the agents
if err := pool.StartAll(); err != nil { if err := pool.StartAll(); err != nil {
panic(err) panic(err)
} }
// Start the web server
log.Fatal(app.Listen(":3000")) log.Fatal(app.Listen(":3000"))
} }