@clawhub-tianmaomao-c8b448a2e6
Query local documents via AnythingLLM RAG (Retrieval-Augmented Generation). Use when the user asks about their private/local documents, PDFs, uploaded files,...
--- name: anythingllm-rag description: | Query local documents via AnythingLLM RAG (Retrieval-Augmented Generation). Use when the user asks about their private/local documents, PDFs, uploaded files, or wants to search their knowledge base. Also handles uploading new documents to AnythingLLM. Triggers on phrases like "查询文档", "搜索本地", "PDF里说了什么", "我的文档", "上传文档", "RAG", "知识库查询", "document search", "find in my files". For general questions not about local documents, use the default model instead. --- # AnythingLLM RAG Skill Query local/private documents through AnythingLLM's RAG API. ## Configuration Environment variables (set in TOOLS.md or shell): - `ANYTHINGLLM_URL` — default `http://localhost:3001` - `ANYTHINGLLM_API_KEY` — API token - `ANYTHINGLLM_WORKSPACE` — default workspace slug Script location: `scripts/anythingllm.sh` ## When to Use **Use AnythingLLM RAG when:** - User asks about their local/private documents - User wants to search uploaded PDFs, DOCX, TXT files - User asks "what does X document say about Y" - User wants to upload documents to the knowledge base **Use default model when:** - General knowledge questions - Questions not related to local documents - Coding, writing, analysis without document context ## Commands ### Query documents (RAG) ```bash bash scripts/anythingllm.sh query "你的问题" ``` ### Upload a file ```bash bash scripts/anythingllm.sh upload /path/to/file.pdf ``` ### Upload raw text ```bash bash scripts/anythingllm.sh upload-text "文本内容" "文档标题" ``` ### List documents ```bash bash scripts/anythingllm.sh list-docs ``` ### Check API health ```bash bash scripts/anythingllm.sh health ``` ## Response Format Query returns JSON with: - `textResponse` — the RAG-generated answer - `sources` — array of source documents used for context Present the answer to the user, citing relevant sources when available. ## Notes - Scripts are in the skill's `scripts/` directory — use paths relative to skill location - API key and workspace are pre-configured - For PDF/DOCX queries, documents must be uploaded first FILE:scripts/anythingllm.sh #!/bin/bash # AnythingLLM RAG API Client # Usage: anythingllm.sh <command> [args] # # Commands: # query <question> - Query the workspace with RAG # upload <file> [workspace] - Upload a document # upload-text <text> <title> - Upload raw text as document # list-docs - List documents in workspace # workspaces - List all workspaces # health - Check API health # Config - update these if needed ANYTHINGLLM_URL="-http://localhost:3001" ANYTHINGLLM_API_KEY="-JYF2P4K-SQ6MKA3-NGW734W-6CVY672" DEFAULT_WORKSPACE="-e2c3afc4-d5fc-44c9-964a-7a571e7ee49f" api_call() { local method="$1" local endpoint="$2" local data="$3" local curl_cmd="curl -s -w '\n%{http_code}' -X method \ -H 'Authorization: Bearer ANYTHINGLLM_API_KEY' \ -H 'Content-Type: application/json' \ 'ANYTHINGLLM_URL/apiendpoint'" if [ -n "$data" ]; then curl_cmd="curl_cmd -d 'data'" fi local response=$(eval "$curl_cmd") local http_code=$(echo "$response" | tail -n1) local body=$(echo "$response" | sed '$d') if [ "$http_code" -ge 400 ] 2>/dev/null; then echo "Error (HTTP $http_code): $body" >&2 return 1 fi echo "$body" } query_rag() { local question="$1" local workspace="-$DEFAULT_WORKSPACE" local payload=$(cat <<EOF { "message": "question", "mode": "query" } EOF ) curl -s -X POST \ -H "Authorization: Bearer ANYTHINGLLM_API_KEY" \ -H "Content-Type: application/json" \ "ANYTHINGLLM_URL/api/v1/workspace/workspace/chat" \ -d "$payload" } upload_file() { local file="$1" local workspace="-$DEFAULT_WORKSPACE" if [ ! -f "$file" ]; then echo "Error: File not found: $file" >&2 return 1 fi curl -s -X POST \ -H "Authorization: Bearer ANYTHINGLLM_API_KEY" \ -F "file=@file" \ -F "addToWorkspaces=workspace" \ "ANYTHINGLLM_URL/api/v1/document/upload" } upload_text() { local text="$1" local title="$2" local workspace="-$DEFAULT_WORKSPACE" local payload=$(cat <<EOF { "textContent": "$(echo "$text" | sed 's/"/\\"/g' | tr '\n' ' ')", "metadata": { "title": "title" }, "addToWorkspaces": "workspace" } EOF ) api_call "POST" "/v1/document/raw-text" "$payload" } list_docs() { local workspace="-$DEFAULT_WORKSPACE" # Use workspace documents endpoint curl -s -X GET \ -H "Authorization: Bearer ANYTHINGLLM_API_KEY" \ -H "Accept: application/json" \ "ANYTHINGLLM_URL/api/v1/workspace/workspace/documents" } list_workspaces() { api_call "GET" "/v1/workspaces" } health_check() { api_call "GET" "/v1/auth" } # Main command handler case "$1" in query) query_rag "$2" "$3" ;; upload) upload_file "$2" "$3" ;; upload-text) upload_text "$2" "$3" "$4" ;; list-docs) list_docs "$2" ;; workspaces) list_workspaces ;; health) health_check ;; *) echo "Usage: $0 <command> [args]" echo "" echo "Commands:" echo " query <question> [workspace] - Query the workspace with RAG" echo " upload <file> [workspace] - Upload a document" echo " upload-text <text> <title> - Upload raw text as document" echo " list-docs [workspace] - List documents in workspace" echo " workspaces - List all workspaces" echo " health - Check API health" exit 1 ;; esac