mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-06-02 00:57:41 +08:00
feat: improve the memory system
This commit is contained in:
@@ -214,6 +214,19 @@ These files contain established best practices for effective skill design.
|
||||
|
||||
To begin implementation, start with the reusable resources identified above: `scripts/`, `references/`, and `assets/` files. Note that this step may require user input. For example, when implementing a `brand-guidelines` skill, the user may need to provide brand assets or templates to store in `assets/`, or documentation to store in `references/`.
|
||||
|
||||
**Available Base Tools**:
|
||||
|
||||
The agent has access to these core tools that you can leverage in your skill:
|
||||
- **bash**: Execute shell commands (use for curl, ls, grep, sed, awk, bc for calculations, etc.)
|
||||
- **read**: Read file contents
|
||||
- **write**: Write files
|
||||
- **edit**: Edit files with search/replace
|
||||
|
||||
**Minimize Dependencies**:
|
||||
- ✅ **Prefer bash + curl** for HTTP API calls (no Python dependencies)
|
||||
- ✅ **Use bash tools** (grep, sed, awk) for text processing
|
||||
- ✅ **Keep scripts simple** - if bash can do it, no need for Python (document packages/versions if Python is used)
|
||||
|
||||
**Important Guidelines**:
|
||||
- **scripts/**: Only create scripts that will be executed. Test all scripts before including.
|
||||
- **references/**: ONLY create if documentation is too large for SKILL.md (>500 lines). Most skills don't need this.
|
||||
|
||||
49
skills/web-fetch/SKILL.md
Normal file
49
skills/web-fetch/SKILL.md
Normal file
@@ -0,0 +1,49 @@
|
||||
---
|
||||
name: web-fetch
|
||||
description: Fetch and extract readable content from web pages
|
||||
homepage: https://github.com/zhayujie/chatgpt-on-wechat
|
||||
metadata:
|
||||
emoji: 🌐
|
||||
requires:
|
||||
bins: ["curl"]
|
||||
---
|
||||
|
||||
# Web Fetch
|
||||
|
||||
Fetch and extract readable content from web pages using curl and basic text processing.
|
||||
|
||||
## Usage
|
||||
|
||||
Use the provided script to fetch a URL and extract its content:
|
||||
|
||||
```bash
|
||||
bash scripts/fetch.sh <url> [output_file]
|
||||
```
|
||||
|
||||
**Parameters:**
|
||||
- `url`: The HTTP/HTTPS URL to fetch (required)
|
||||
- `output_file`: Optional file to save the output (default: stdout)
|
||||
|
||||
**Returns:**
|
||||
- Extracted page content with title and text
|
||||
|
||||
## Examples
|
||||
|
||||
### Fetch a web page
|
||||
```bash
|
||||
bash scripts/fetch.sh "https://example.com"
|
||||
```
|
||||
|
||||
### Save to file
|
||||
```bash
|
||||
bash scripts/fetch.sh "https://example.com" output.txt
|
||||
cat output.txt
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- Uses curl for HTTP requests (timeout: 20s)
|
||||
- Extracts title and basic text content
|
||||
- Removes HTML tags and scripts
|
||||
- Works with any standard web page
|
||||
- No external dependencies beyond curl
|
||||
54
skills/web-fetch/scripts/fetch.sh
Executable file
54
skills/web-fetch/scripts/fetch.sh
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env bash
|
||||
# Fetch and extract readable content from a web page
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
url="${1:-}"
|
||||
output_file="${2:-}"
|
||||
|
||||
if [ -z "$url" ]; then
|
||||
echo "Error: URL is required"
|
||||
echo "Usage: bash fetch.sh <url> [output_file]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Validate URL
|
||||
if [[ ! "$url" =~ ^https?:// ]]; then
|
||||
echo "Error: Invalid URL (must start with http:// or https://)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Fetch the page with curl
|
||||
html=$(curl -sS -L --max-time 20 \
|
||||
-H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36" \
|
||||
-H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" \
|
||||
"$url" 2>&1) || {
|
||||
echo "Error: Failed to fetch URL: $url"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Extract title
|
||||
title=$(echo "$html" | grep -oP '(?<=<title>).*?(?=</title>)' | head -1 || echo "Untitled")
|
||||
|
||||
# Remove script and style tags
|
||||
text=$(echo "$html" | sed 's/<script[^>]*>.*<\/script>//gI' | sed 's/<style[^>]*>.*<\/style>//gI')
|
||||
|
||||
# Remove HTML tags
|
||||
text=$(echo "$text" | sed 's/<[^>]*>//g')
|
||||
|
||||
# Clean up whitespace
|
||||
text=$(echo "$text" | tr -s ' ' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
||||
|
||||
# Format output
|
||||
result="Title: $title
|
||||
|
||||
Content:
|
||||
$text"
|
||||
|
||||
# Output to file or stdout
|
||||
if [ -n "$output_file" ]; then
|
||||
echo "$result" > "$output_file"
|
||||
echo "Content saved to: $output_file"
|
||||
else
|
||||
echo "$result"
|
||||
fi
|
||||
Reference in New Issue
Block a user