This skill provides OCR (Optical Character Recognition) functionality using models available via OpenRouter. It uses the OpenAI Python library to communicate with OpenRouter's API, specifically designed for models like Baidu's Qianfan OCR.
When you need to extract text from an image:
openai, requests (install via pip install openai requests)C:\Users\Administrator\.openclaw\secrets\openrouter.env (format: OPENROUTER_API_KEY=your_key_here)
```bash
python ocr.py
```
image_input: Either a URL or a local file path to the imageprompt: Optional text prompt for the OCR (default: "OCR提取图片所有文字")python ocr.py "https://example.com/image.jpg"
python ocr.py "https://example.com/image.jpg" "请识别图片中的所有文字"
python ocr.py "C:\path\to\image.jpg"
The skill uses the OpenAI client configured with:
https://openrouter.ai/api/v1baidu/qianfan-ocr-fast:free (configurable via environment variable)OPENROUTER_API_KEY environment variableIt sends a multimodal request containing:
The model returns the extracted text which is printed to console.
OPENROUTER_API_KEY: Required - Your OpenRouter API keyOCR_MODEL: Optional - Model to use (default: baidu/qianfan-ocr-fast:free)OCR_BASE_URL: Optional - OpenRouter base URL (default: https://openrouter.ai/api/v1)mkdir -p skills/openrouter-ocrocr.py script in this directorypip install openai requests```bash
setx OPENROUTER_API_KEY "your_api_key_here"
```
(Restart terminal after setting)
OCR_MODEL environment variableOPENROUTER_API_KEY is set correctlypip install openai requests✅ OCR 识别结果:
------------------------------------------------------------
这是识别出的文本内容
...
------------------------------------------------------------
Never commit your API key to version control. Keep it secure in environment variables.
共 1 个版本