Re-order main
This commit is contained in:
38
main.go
38
main.go
@@ -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 == "" {
|
||||||
|
cwd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
stateDir = filepath.Join(cwd, "pool")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func ragDB() (ragDB agent.RAGDB) {
|
||||||
// current dir
|
|
||||||
cwd, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
stateDir := cwd + "/pool"
|
|
||||||
os.MkdirAll(stateDir, 0755)
|
|
||||||
|
|
||||||
var 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"))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user