refactor: rewrite duckduckgo-search skill for accuracy and usability
Follow-up to PR #267 merge: - Fix CLI syntax: -k is keywords, -m is max results (was reversed) - Add clear trigger condition: use only when web_search tool unavailable - Remove misleading curl fallback (DuckDuckGo Instant Answer API is not a web search endpoint) - Fix package name: ddgs (renamed from duckduckgo-search) - Add workflow section for search → web_extract pipeline - Add pitfalls and limitations sections - Fix author attribution to actual contributor - Rewrite shell script as simple ddgs wrapper with availability check
This commit is contained in:
parent
d19109742e
commit
2af2f148ab
2 changed files with 82 additions and 108 deletions
|
|
@ -1,32 +1,28 @@
|
|||
#!/bin/bash
|
||||
# DuckDuckGo Search Helper Script
|
||||
# Fallback for when ddgs library is unavailable
|
||||
# Usage: ./duckduckgo.sh [text|images|news|videos] <query> [limit]
|
||||
# Wrapper around ddgs CLI with sensible defaults
|
||||
# Usage: ./duckduckgo.sh <query> [max_results]
|
||||
|
||||
set -e
|
||||
|
||||
MODE="${1:-text}"
|
||||
QUERY="$2"
|
||||
LIMIT="${3:-5}"
|
||||
QUERY="$1"
|
||||
MAX_RESULTS="${2:-5}"
|
||||
|
||||
if [ -z "$QUERY" ]; then
|
||||
echo "Usage: $0 [text|images|news|videos] <query> [limit]"
|
||||
echo "Usage: $0 <query> [max_results]"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 text 'python async' 5"
|
||||
echo " $0 images 'cat' 10"
|
||||
echo " $0 'python async programming' 5"
|
||||
echo " $0 'latest AI news' 10"
|
||||
echo ""
|
||||
echo "Requires: pip install ddgs"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# URL encode query
|
||||
ENCODED_QUERY=$(echo "$QUERY" | sed 's/ /+/g' | sed 's/&/%26/g' | sed 's/=/%3D/g')
|
||||
# Check if ddgs is available
|
||||
if ! command -v ddgs &> /dev/null; then
|
||||
echo "Error: ddgs not found. Install with: pip install ddgs"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$MODE" in
|
||||
text|images|news|videos)
|
||||
curl -s "https://api.duckduckgo.com/?q=${ENCODED_QUERY}&format=json&limit=${LIMIT}"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown mode: $MODE"
|
||||
echo "Valid modes: text, images, news, videos"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
ddgs text -k "$QUERY" -m "$MAX_RESULTS"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue