Add an index
This commit is contained in:
63
example/webui/agents.html
Normal file
63
example/webui/agents.html
Normal file
@@ -0,0 +1,63 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Agent List</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
|
||||
|
||||
</head>
|
||||
<body class="bg-gray-900 p-4 text-white">
|
||||
<div class="max-w-6xl mx-auto">
|
||||
<div class="text-center mb-6">
|
||||
<h1 class="text-2xl font-bold">Smart Agent List</h1>
|
||||
</div>
|
||||
<div class="flex flex-col">
|
||||
<div class="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
|
||||
<div class="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
|
||||
<div class="shadow overflow-hidden border-b border-gray-700 sm:rounded-lg">
|
||||
<table class="min-w-full divide-y divide-gray-700">
|
||||
<thead class="bg-gray-700">
|
||||
<tr>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-400 uppercase tracking-wider">
|
||||
Name
|
||||
</th>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-400 uppercase tracking-wider">
|
||||
Status
|
||||
</th>
|
||||
<th scope="col" class="relative px-6 py-3">
|
||||
<span class="sr-only">Talk</span>
|
||||
</th>
|
||||
<th scope="col" class="relative px-6 py-3">
|
||||
<span class="sr-only">Delete</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="bg-gray-800 divide-y divide-gray-700">
|
||||
<!-- Dynamic agent rows go here -->
|
||||
{{ range .Agents }}
|
||||
<tr>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-300">{{.}}</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">Online</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||
<a href="/talk/{{.}}" class="text-blue-500 hover:text-blue-400">Talk</a>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||
<a href="/delete/{{.}}" class="text-blue-500 hover:text-blue-400">Delete</a>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
<!-- Repeat for each agent -->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-6">
|
||||
<a href="/create" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
|
||||
Add New Agent
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -2,60 +2,22 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Agent List</title>
|
||||
<title>Smart Assistant Dashboard</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
|
||||
|
||||
</head>
|
||||
<body class="bg-gray-900 p-4 text-white">
|
||||
<div class="max-w-6xl mx-auto">
|
||||
<div class="max-w-4xl mx-auto">
|
||||
<div class="text-center mb-6">
|
||||
<h1 class="text-2xl font-bold">Smart Agent List</h1>
|
||||
<h1 class="text-3xl font-bold">Smart Assistant Dashboard</h1>
|
||||
</div>
|
||||
<div class="flex flex-col">
|
||||
<div class="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
|
||||
<div class="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
|
||||
<div class="shadow overflow-hidden border-b border-gray-700 sm:rounded-lg">
|
||||
<table class="min-w-full divide-y divide-gray-700">
|
||||
<thead class="bg-gray-700">
|
||||
<tr>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-400 uppercase tracking-wider">
|
||||
Name
|
||||
</th>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-400 uppercase tracking-wider">
|
||||
Status
|
||||
</th>
|
||||
<th scope="col" class="relative px-6 py-3">
|
||||
<span class="sr-only">Talk</span>
|
||||
</th>
|
||||
<th scope="col" class="relative px-6 py-3">
|
||||
<span class="sr-only">Delete</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="bg-gray-800 divide-y divide-gray-700">
|
||||
<!-- Dynamic agent rows go here -->
|
||||
{{ range .Agents }}
|
||||
<tr>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-300">{{.}}</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">Online</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||
<a href="/talk/{{.}}" class="text-blue-500 hover:text-blue-400">Talk</a>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||
<a href="/delete/{{.}}" class="text-blue-500 hover:text-blue-400">Delete</a>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
<!-- Repeat for each agent -->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-6">
|
||||
<a href="/create" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
|
||||
Add New Agent
|
||||
<div class="flex flex-col items-center space-y-4">
|
||||
<!-- Button to Agent List Page -->
|
||||
<a href="/agents" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
|
||||
Agent List
|
||||
</a>
|
||||
<!-- Button to Knowledgebase Management Page -->
|
||||
<a href="/knowledgebase" class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded">
|
||||
Manage Knowledgebase
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user