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 (
"log"
"os"
"path/filepath"
"github.com/mudler/local-agent-framework/core/agent"
"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 timeout = os.Getenv("TIMEOUT")
var embeddingModel = os.Getenv("EMBEDDING_MODEL")
const defaultChunkSize = 4098
var stateDir = os.Getenv("STATE_DIR")
func init() {
if testModel == "" {
@@ -30,19 +30,17 @@ func init() {
if timeout == "" {
timeout = "5m"
}
}
func main() {
// current dir
if stateDir == "" {
cwd, err := os.Getwd()
if err != nil {
panic(err)
}
stateDir := cwd + "/pool"
os.MkdirAll(stateDir, 0755)
stateDir = filepath.Join(cwd, "pool")
}
}
var ragDB agent.RAGDB
func ragDB() (ragDB agent.RAGDB) {
lai := llm.NewClient(apiKey, apiURL+"/v1", timeout)
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)
if err != nil {
panic(err)
}
// Create the application
app := webui.NewApp(webui.WithPool(pool))
// Start the agents
if err := pool.StartAll(); err != nil {
panic(err)
}
// Start the web server
log.Fatal(app.Listen(":3000"))
}