mirror of
https://github.com/coalaura/whiskr.git
synced 2025-12-02 20:22:52 +00:00
improvements to exa tool
This commit is contained in:
66
exa.go
66
exa.go
@@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -87,6 +88,8 @@ func ExaRunSearch(ctx context.Context, args SearchWebArguments) (*ExaResults, er
|
|||||||
args.NumResults = 12
|
args.NumResults = 12
|
||||||
}
|
}
|
||||||
|
|
||||||
|
guidance := ExaGuidanceForIntent(args)
|
||||||
|
|
||||||
data := map[string]any{
|
data := map[string]any{
|
||||||
"query": args.Query,
|
"query": args.Query,
|
||||||
"type": "auto",
|
"type": "auto",
|
||||||
@@ -98,36 +101,58 @@ func ExaRunSearch(ctx context.Context, args SearchWebArguments) (*ExaResults, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
contents := map[string]any{
|
contents := map[string]any{
|
||||||
"summary": map[string]any{},
|
"summary": map[string]any{
|
||||||
"highlights": map[string]any{
|
"query": guidance,
|
||||||
"numSentences": 2,
|
|
||||||
"highlightsPerUrl": 3,
|
|
||||||
},
|
},
|
||||||
"livecrawl": "preferred",
|
"livecrawl": "preferred",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
highlights := map[string]any{
|
||||||
|
"numSentences": 2,
|
||||||
|
"highlightsPerUrl": 3,
|
||||||
|
"query": guidance,
|
||||||
|
}
|
||||||
|
|
||||||
switch args.Intent {
|
switch args.Intent {
|
||||||
case "news":
|
case "news":
|
||||||
|
highlights["highlightsPerUrl"] = 2
|
||||||
|
|
||||||
data["category"] = "news"
|
data["category"] = "news"
|
||||||
data["numResults"] = max(8, args.NumResults)
|
data["numResults"] = max(8, args.NumResults)
|
||||||
data["startPublishedDate"] = daysAgo(30)
|
data["startPublishedDate"] = daysAgo(30)
|
||||||
case "docs":
|
case "docs":
|
||||||
|
highlights["numSentences"] = 3
|
||||||
|
highlights["highlightsPerUrl"] = 4
|
||||||
|
|
||||||
contents["subpages"] = 1
|
contents["subpages"] = 1
|
||||||
contents["subpageTarget"] = []string{"documentation", "changelog", "release notes"}
|
contents["subpageTarget"] = []string{"documentation", "changelog", "release notes"}
|
||||||
case "papers":
|
case "papers":
|
||||||
|
highlights["numSentences"] = 4
|
||||||
|
highlights["highlightsPerUrl"] = 4
|
||||||
|
|
||||||
data["category"] = "research paper"
|
data["category"] = "research paper"
|
||||||
data["startPublishedDate"] = daysAgo(365 * 2)
|
data["startPublishedDate"] = daysAgo(365 * 2)
|
||||||
case "code":
|
case "code":
|
||||||
data["category"] = "github"
|
highlights["highlightsPerUrl"] = 4
|
||||||
|
|
||||||
contents["subpages"] = 1
|
contents["subpages"] = 1
|
||||||
contents["subpageTarget"] = []string{"readme", "changelog", "code"}
|
contents["subpageTarget"] = []string{"readme", "changelog", "code"}
|
||||||
case "deep_read":
|
|
||||||
contents["text"] = map[string]any{
|
contents["text"] = map[string]any{
|
||||||
"maxCharacters": 8000,
|
"maxCharacters": 8000,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data["category"] = "github"
|
||||||
|
case "deep_read":
|
||||||
|
highlights["numSentences"] = 3
|
||||||
|
highlights["highlightsPerUrl"] = 5
|
||||||
|
|
||||||
|
contents["text"] = map[string]any{
|
||||||
|
"maxCharacters": 12000,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contents["highlights"] = highlights
|
||||||
|
|
||||||
data["contents"] = contents
|
data["contents"] = contents
|
||||||
|
|
||||||
switch args.Recency {
|
switch args.Recency {
|
||||||
@@ -170,3 +195,32 @@ func ExaRunContents(ctx context.Context, args FetchContentsArguments) (*ExaResul
|
|||||||
func daysAgo(days int) string {
|
func daysAgo(days int) string {
|
||||||
return time.Now().Add(-time.Duration(days) * 24 * time.Hour).Format(time.DateOnly)
|
return time.Now().Add(-time.Duration(days) * 24 * time.Hour).Format(time.DateOnly)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExaGuidanceForIntent(args SearchWebArguments) string {
|
||||||
|
var recency string
|
||||||
|
|
||||||
|
switch args.Recency {
|
||||||
|
case "month":
|
||||||
|
recency = " since " + daysAgo(30)
|
||||||
|
case "year":
|
||||||
|
recency = " since " + daysAgo(365)
|
||||||
|
}
|
||||||
|
|
||||||
|
goal := strings.TrimSpace(args.Query)
|
||||||
|
|
||||||
|
switch args.Intent {
|
||||||
|
case "news":
|
||||||
|
return "Give who/what/when/where and key numbers" + recency +
|
||||||
|
". Include dates and named sources; 2-4 bullets. Note disagreements. Ignore speculation."
|
||||||
|
case "docs":
|
||||||
|
return "Extract install command, minimal example, breaking changes" + recency + ", key config options with defaults, and deprecations. Prefer official docs and release notes."
|
||||||
|
case "papers":
|
||||||
|
return "Summarize problem, method, dataset, metrics (with numbers), baselines, novelty, and limitations; include year/venue."
|
||||||
|
case "code":
|
||||||
|
return "Summarize repo purpose, language, license, last release/commit" + recency + ", install steps and minimal example; note breaking changes. Prefer README/docs."
|
||||||
|
case "deep_read":
|
||||||
|
return "Answer: " + goal + ". Extract exact numbers, dates, quotes (with speaker) plus 1-2 sentences of context."
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Focus on answering: " + goal + ". Provide dates, versions, key numbers; 3-5 concise bullets. Ignore marketing fluff."
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user