diff --git a/tools/web_search_perplexity.sh b/tools/web_search_perplexity.sh index 62ece1f..190544d 100755 --- a/tools/web_search_perplexity.sh +++ b/tools/web_search_perplexity.sh @@ -11,23 +11,20 @@ set -e # @env LLM_OUTPUT=/dev/stdout The output path main() { - curl -fsS -X POST https://api.perplexity.ai/chat/completions \ - -H "authorization: Bearer $PERPLEXITY_API_KEY" \ - -H "accept: application/json" \ - -H "content-type: application/json" \ - --data ' -{ - "model": "'"$PERPLEXITY_WEB_SEARCH_MODEL"'", - "messages": [ - { - "role": "user", - "content": "'"$argc_query"'" - } - ] -} -' | \ + jq -n --arg model "${PERPLEXITY_WEB_SEARCH_MODEL}" --arg query "$argc_query" \ + '{ + "model": $model, + "messages": [ + { "role": "user", "content": $query } + ] + }' | + curl -fsSL --d @- \ + -X POST https://api.perplexity.ai/chat/completions \ + -H "authorization: Bearer $PERPLEXITY_API_KEY" \ + -H "accept: application/json" \ + -H "content-type: application/json" | jq -r '.choices[0].message.content' \ - >> "$LLM_OUTPUT" + >>"$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" diff --git a/tools/web_search_tavily.sh b/tools/web_search_tavily.sh index 1bf1e9d..c67034c 100755 --- a/tools/web_search_tavily.sh +++ b/tools/web_search_tavily.sh @@ -10,15 +10,17 @@ set -e # @env LLM_OUTPUT=/dev/stdout The output path The output path main() { - curl -fsSL -X POST https://api.tavily.com/search \ - -H "content-type: application/json" \ - -d ' -{ - "api_key": "'"$TAVILY_API_KEY"'", - "query": "'"$argc_query"'", - "include_answer": true -}' | \ - jq -r '.answer' >> "$LLM_OUTPUT" + jq -n --arg api_key "$TAVILY_API_KEY" --arg query "$argc_query" \ + '{ + "api_key": $api_key, + "query": $query, + "include_answer": true + }' | + curl -fsSL -d @- \ + -X POST https://api.tavily.com/search \ + -H "content-type: application/json" | + jq -r '.answer' \ + >>"$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")"