feat: add search tools (#58)

This commit is contained in:
sigoden
2024-07-05 19:49:26 +08:00
committed by GitHub
parent c7e027c6c3
commit 74789b5a72
8 changed files with 125 additions and 21 deletions
+15
View File
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -e
# @describe Search arXiv for a query and return the top papers.
# @env ARXIV_MAX_RESULTS=5 The max results to return.
# @option --query! The query to search for.
main() {
encoded_query="$(jq -nr --arg q "$argc_query" '$q|@uri')"
url="http://export.arxiv.org/api/query?search_query=all:$encoded_query&max_results=$ARXIV_MAX_RESULTS"
curl -fsSL "$url"
}
eval "$(argc --argc-eval "$0" "$@")"
+20
View File
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -e
# @describe Perform a web search using Bing Web Search 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 BING_API_KEY! The api key
# @env BING_MAX_RESULTS=5 The max results to return.
# @option --query! The query to search for.
main() {
encoded_query="$(jq -nr --arg q "$argc_query" '$q|@uri')"
url="https://api.bing.microsoft.com/v7.0/search?q=$encoded_query&mkt=en-us&textdecorations=true&textformat=raw&count=$BING_MAX_RESULTS&offset=0"
curl -fsSL "$url" \
-H "Ocp-Apim-Subscription-Key: $BING_API_KEY" | \
jq '[.webPages.value[] | {name: .name, url: .url, snippet: .snippet}]'
}
eval "$(argc --argc-eval "$0" "$@")"
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -e
# @describe Perform a web search using Brave Search 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 BRAVE_API_KEY! The api key
# @env BRAVE_MAX_RESULTS=5 The max results to return.
# @option --query! The query to search for.
main() {
encoded_query="$(jq -nr --arg q "$argc_query" '$q|@uri')"
url="https://api.search.brave.com/res/v1/web/search?q=$encoded_query&count=$BRAVE_MAX_RESULTS"
curl -fsSL "$url" \
-H "Accept: application/json" \
-H "X-Subscription-Token: $BRAVE_API_KEY" | \
jq '[.web.results[] | {title: .title, url: .url, description: .description}]'
}
eval "$(argc --argc-eval "$0" "$@")"
+2 -3
View File
@@ -1,9 +1,8 @@
#!/usr/bin/env bash
set -e
# @describe Takes in a query string and returns search result from DuckDuckGo.
# Use it to answer user questions that require dates, facts, real-time information, or news.
# This ensures accurate and up-to-date answers.
# @describe Perform a web search using DuckDuckGo 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.
# @meta require-tools ddgr
# @env DDG_MAX_RESULTS=5 The max results to return.
+31
View File
@@ -0,0 +1,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" "$@")"
+20
View File
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -e
# @describe Perform a web search using SearXNG 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 SEARXNG_API_BASE! The api url
# @env SEARXNG_MAX_RESULTS=5 The max results to return.
# @option --query! The query to search for.
main() {
encoded_query="$(jq -nr --arg q "$argc_query" '$q|@uri')"
url="$SEARXNG_API_BASE/search?q=$encoded_query&categories=general&language=en-US&format=json"
curl -fsSL "$url" | \
jq '[.results[:'"$SEARXNG_MAX_RESULTS"'] | .[] | {url: .url, title: .title, content: .content}]'
}
eval "$(argc --argc-eval "$0" "$@")"
+12 -6
View File
@@ -1,18 +1,24 @@
#!/usr/bin/env bash
set -e
# @describe Perform a web search using Tavily API to get up-to-date information or additional context.
# @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 TAVILY_API_KEY! The max results to return.
# @env TAVILY_API_KEY! The api key
# @env TAVILY_MAX_RESULTS=5 The max results to return.
# @option --query! The query to search for.
main() {
curl -fsSL -X POST \
-H 'content-type: application/json' \
-d '{"api_key":"'"$TAVILY_API_KEY"'","query":"'"$argc_query"'","search_depth":"advanced","max_results":"'"$TAVILY_MAX_RESULTS"'"}' \
https://api.tavily.com/search
curl -fsSL -X POST https://api.tavily.com/search \
-H "content-type: application/json" \
-d '
{
"api_key": "'"$TAVILY_API_KEY"'",
"query": "'"$argc_query"'",
"search_depth": "advanced",
"max_results": "'"$TAVILY_MAX_RESULTS"'"
}' | \
jq '[.results[] | {title: .title, url: .url, content: .content}]'
}
eval "$(argc --argc-eval "$0" "$@")"
+4 -12
View File
@@ -3,22 +3,14 @@ set -e
# @describe Get an answer to a question using Wolfram Alpha. Input should the query in English.
# Use it to answer user questions that require computation, detailed facts, data analysis, or complex queries.
# This ensures accurate and precise answers.
# @env WOLFRAM_API_ID! The api id
# @option --query! The query to search for.
# @env WOLFRAM_API_ID!
main() {
local curl_args=(
-sSf -G
--data-urlencode "output=JSON"
--data-urlencode "format=plaintext"
--data-urlencode "input=$argc_query"
--data-urlencode "appid=$WOLFRAM_API_ID"
"https://api.wolframalpha.com/v2/query"
)
curl "${curl_args[@]}" | \
jq -r '.queryresult.pods[] | select(.subpods[0].plaintext != "")'
encoded_query="$(jq -nr --arg q "$argc_query" '$q|@uri')"
url="https://api.wolframalpha.com/v2/query?appid=$WOLFRAM_API_ID&input=$encoded_query&output=json&format=plaintext"
curl -fsSL "$url" | jq '[.queryresult | .pods[] | {title:.title, values:[.subpods[].plaintext | select(. != "")]}]'
}
eval "$(argc --argc-eval "$0" "$@")"