diff --git a/agent/agent.go b/agent/agent.go index 7560f61..5ee4343 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -176,6 +176,8 @@ func (a *Agent) consumeJob(job *Job, role string) { // We are self evaluating if we consume the job as a system role selfEvaluation := role == SystemRole + memory := a.options.enableKB && a.options.ragdb != nil + a.Lock() // Set the action context ctx, cancel := context.WithCancel(context.Background()) @@ -206,7 +208,7 @@ func (a *Agent) consumeJob(job *Job, role string) { } // RAG - if a.options.enableKB && a.options.ragdb != nil { + if memory { // Walk conversation from bottom to top, and find the first message of the user // to use it as a query to the KB var userMessage string diff --git a/example/webui/agents.html b/example/webui/agents.html new file mode 100644 index 0000000..a1ee34d --- /dev/null +++ b/example/webui/agents.html @@ -0,0 +1,63 @@ + + + + + Agent List + + + + +
+
+

Smart Agent List

+
+
+
+
+
+ + + + + + + + + + + + {{ range .Agents }} + + + + + + + {{ end }} + + +
+ Name + + Status + + Talk + + Delete +
{{.}}Online + Talk + + Delete +
+
+
+
+
+
+ + Add New Agent + +
+
+ + diff --git a/example/webui/index.html b/example/webui/index.html index a1ee34d..c0eabd1 100644 --- a/example/webui/index.html +++ b/example/webui/index.html @@ -2,60 +2,22 @@ - Agent List + Smart Assistant Dashboard - -
+
-

Smart Agent List

+

Smart Assistant Dashboard

-
-
-
-
- - - - - - - - - - - - {{ range .Agents }} - - - - - - - {{ end }} - - -
- Name - - Status - - Talk - - Delete -
{{.}}Online - Talk - - Delete -
-
-
-
-
- diff --git a/example/webui/main.go b/example/webui/main.go index edad841..800812e 100644 --- a/example/webui/main.go +++ b/example/webui/main.go @@ -106,6 +106,12 @@ func main() { }) }) + webapp.Get("/agents", func(c *fiber.Ctx) error { + return c.Render("agents.html", fiber.Map{ + "Agents": pool.List(), + }) + }) + webapp.Get("/create", func(c *fiber.Ctx) error { return c.Render("create.html", fiber.Map{ "Title": "Hello, World!", @@ -152,8 +158,8 @@ func main() { func (a *App) KnowledgeBase(db *InMemoryDatabase) func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error { payload := struct { - URL string `json:"url"` - ChunkSize int `json:"chunk_size"` + URL string `form:"url"` + ChunkSize int `form:"chunk_size"` }{} if err := c.BodyParser(&payload); err != nil { @@ -169,28 +175,7 @@ func (a *App) KnowledgeBase(db *InMemoryDatabase) func(c *fiber.Ctx) error { chunkSize = payload.ChunkSize } - go func() { - content, err := Sitemap(website) - if err != nil { - fmt.Println("Error walking sitemap for website", err) - } - fmt.Println("Found pages: ", len(content)) - fmt.Println("ChunkSize: ", chunkSize) - - for _, c := range content { - chunks := splitParagraphIntoChunks(c, chunkSize) - fmt.Println("chunks: ", len(chunks)) - for _, chunk := range chunks { - db.AddEntry(chunk) - } - - db.SaveDB() - } - - if err := db.SaveToStore(); err != nil { - fmt.Println("Error storing in the KB", err) - } - }() + go WebsiteToKB(website, chunkSize, db) return c.Redirect("/knowledgebase") } @@ -199,7 +184,7 @@ func (a *App) KnowledgeBase(db *InMemoryDatabase) func(c *fiber.Ctx) error { func (a *App) Notify(pool *AgentPool) func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error { payload := struct { - Message string `json:"message"` + Message string `form:"message"` }{} if err := c.BodyParser(&payload); err != nil { diff --git a/example/webui/rag.go b/example/webui/rag.go index 375a92a..d048a9f 100644 --- a/example/webui/rag.go +++ b/example/webui/rag.go @@ -119,6 +119,30 @@ func Sitemap(url string) (res []string, err error) { return } +func WebsiteToKB(website string, chunkSize int, db *InMemoryDatabase) { + content, err := Sitemap(website) + if err != nil { + fmt.Println("Error walking sitemap for website", err) + } + fmt.Println("Found pages: ", len(content)) + fmt.Println("ChunkSize: ", chunkSize) + + for _, c := range content { + chunks := splitParagraphIntoChunks(c, chunkSize) + fmt.Println("chunks: ", len(chunks)) + for _, chunk := range chunks { + fmt.Println("Chunk size: ", len(chunk)) + db.AddEntry(chunk) + } + + db.SaveDB() + } + + if err := db.SaveToStore(); err != nil { + fmt.Println("Error storing in the KB", err) + } +} + // splitParagraphIntoChunks takes a paragraph and a maxChunkSize as input, // and returns a slice of strings where each string is a chunk of the paragraph // that is at most maxChunkSize long, ensuring that words are not split. diff --git a/llm/rag/rag_chromem.go b/llm/rag/chromem.go similarity index 96% rename from llm/rag/rag_chromem.go rename to llm/rag/chromem.go index a14486e..5f33d2d 100644 --- a/llm/rag/rag_chromem.go +++ b/llm/rag/chromem.go @@ -24,7 +24,6 @@ func NewChromemDB(collection, path string, openaiClient *openai.Client) (*Chrome embeddingFunc := chromem.EmbeddingFunc( func(ctx context.Context, text string) ([]float32, error) { - fmt.Println("Creating embeddings") resp, err := openaiClient.CreateEmbeddings(ctx, openai.EmbeddingRequestStrings{ Input: []string{text}, @@ -64,7 +63,6 @@ func (c *ChromemDB) Store(s string) error { if s == "" { return fmt.Errorf("empty string") } - fmt.Println("Trying to store", s) return c.collection.AddDocuments(context.Background(), []chromem.Document{ { Content: s, diff --git a/llm/rag/rag_localai.go b/llm/rag/localai.go similarity index 100% rename from llm/rag/rag_localai.go rename to llm/rag/localai.go