Introduce multiple agents, tools, and utilities for processing, extracting, and answering user-provided questions using LLMs and external data. Key features include knowledge processing, question splitting, search term generation, and contextual knowledge handling.
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package searcher
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
|
|
"gitea.stevedudenhoeffer.com/steve/go-extractor"
|
|
"gitea.stevedudenhoeffer.com/steve/go-extractor/sites/duckduckgo"
|
|
gollm "gitea.stevedudenhoeffer.com/steve/go-llm"
|
|
)
|
|
|
|
func deferClose(closer io.Closer) {
|
|
if closer != nil {
|
|
_ = closer.Close()
|
|
}
|
|
}
|
|
|
|
type searchResult struct {
|
|
Answer string `json:"answer"`
|
|
Sources []string `json:"sources"`
|
|
}
|
|
|
|
func fnSearch(ctx *gollm.Context, args struct {
|
|
Query string `description:"The search query to perform on duckduckgo"`
|
|
Question string `description:"The question(s) you are trying to answer when you read the search results. e.g: "`
|
|
}) (string, error) {
|
|
browser, ok := ctx.Value("browser").(extractor.Browser)
|
|
if !ok {
|
|
return "", fmt.Errorf("browser not found")
|
|
}
|
|
|
|
cfg := duckduckgo.Config{
|
|
SafeSearch: duckduckgo.SafeSearchOff,
|
|
Region: "us-en",
|
|
}
|
|
|
|
page, err := cfg.OpenSearch(ctx, browser, args.Query)
|
|
defer deferClose(page)
|
|
|
|
if err != nil {
|
|
return "", fmt.Errorf("failed to search: %w", err)
|
|
}
|
|
|
|
return "", nil
|
|
}
|