aboutsummaryrefslogtreecommitdiffstats
path: root/tools/search_exa.sh
blob: 33d4564ea23d022a7f4c1b6a3c0ec3e5ab754642 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env bash
set -e

# @describe Perform a web search using Exa API to get up-to-date information or additional context.
# Use this when you need current information or feel a search could provide a better answer.

# @env EXA_API_KEY! The api key
# @env EXA_MAX_RESULTS=5 The max results to return.
# @option --query! The query to search for.

main() {
    curl -fsSL -X POST https://api.exa.ai/search \
        -H "content-type: application/json" \
        -H "x-api-key: $EXA_API_KEY" \
        -d '
{
    "query": "'"$argc_query"'",
    "numResults": '"$EXA_MAX_RESULTS"',
    "type": "keyword",
    "contents": {
        "text": {
            "maxCharacters": 200
        }
    }
}' | \
        jq '[.results[] | {title: .title, url: .url, text: .text}]'
}

eval "$(argc --argc-eval "$0" "$@")"