mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-06-02 00:57:41 +08:00
feat: add image vision provider
This commit is contained in:
@@ -72,8 +72,12 @@ bash scripts/vision.sh "image.jpg" "Analyze this" "gpt-4o-mini"
|
||||
|
||||
| Variable | Required | Default | Description |
|
||||
|----------|----------|---------|-------------|
|
||||
| `OPENAI_API_KEY` | Yes | - | Your OpenAI API key |
|
||||
| `OPENAI_API_BASE` | No | `https://api.openai.com/v1` | Custom API base URL |
|
||||
| `OPENAI_API_KEY` | No* | - | OpenAI API key (preferred) |
|
||||
| `OPENAI_API_BASE` | No | `https://api.openai.com/v1` | Custom OpenAI API base URL |
|
||||
| `LINKAI_API_KEY` | No* | - | LinkAI API key (fallback when OPENAI_API_KEY is not set) |
|
||||
| `LINKAI_API_BASE` | No | `https://api.link-ai.tech` | LinkAI API base URL |
|
||||
|
||||
\* At least one of `OPENAI_API_KEY` or `LINKAI_API_KEY` must be set. OpenAI takes priority when both are configured.
|
||||
|
||||
## Response Format
|
||||
|
||||
|
||||
@@ -6,8 +6,7 @@ metadata:
|
||||
emoji: 👁️
|
||||
requires:
|
||||
bins: ["curl", "base64"]
|
||||
env: ["OPENAI_API_KEY"]
|
||||
primaryEnv: "OPENAI_API_KEY"
|
||||
anyEnv: ["OPENAI_API_KEY", "LINKAI_API_KEY"]
|
||||
---
|
||||
|
||||
# OpenAI Image Vision
|
||||
@@ -16,12 +15,13 @@ Analyze images using OpenAI's GPT-4 Vision API. The model can understand visual
|
||||
|
||||
## Setup
|
||||
|
||||
This skill requires an OpenAI API key. If not configured:
|
||||
This skill requires at least one of the following API keys (OpenAI is preferred when both are set):
|
||||
|
||||
1. Get your API key from https://platform.openai.com/api-keys
|
||||
2. Set the key using: `env_config(action="set", key="OPENAI_API_KEY", value="your-key")`
|
||||
1. **OpenAI** (preferred): `env_config(action="set", key="OPENAI_API_KEY", value="your-key")`
|
||||
2. **LinkAI** (fallback): `env_config(action="set", key="LINKAI_API_KEY", value="your-key")`
|
||||
|
||||
Optional: Set custom API base URL:
|
||||
|
||||
Optional: Set custom API base URL (default: https://api.openai.com/v1):
|
||||
```bash
|
||||
env_config(action="set", key="OPENAI_API_BASE", value="your-base-url")
|
||||
```
|
||||
|
||||
@@ -18,13 +18,21 @@ if [ -z "$question" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "${OPENAI_API_KEY:-}" ]; then
|
||||
echo '{"error": "OPENAI_API_KEY environment variable is not set", "help": "Visit https://platform.openai.com/api-keys to get an API key"}'
|
||||
# Determine API key and base URL (prefer OpenAI, fallback to LinkAI)
|
||||
api_key="${OPENAI_API_KEY:-}"
|
||||
api_base="${OPENAI_API_BASE:-https://api.openai.com/v1}"
|
||||
|
||||
if [ -z "$api_key" ] && [ -n "${LINKAI_API_KEY:-}" ]; then
|
||||
api_key="$LINKAI_API_KEY"
|
||||
api_base="${LINKAI_API_BASE:-https://api.link-ai.tech}/v1"
|
||||
>&2 echo "[vision.sh] Using LinkAI API (OPENAI_API_KEY not set)"
|
||||
fi
|
||||
|
||||
if [ -z "$api_key" ]; then
|
||||
echo '{"error": "No API key configured. Set OPENAI_API_KEY or LINKAI_API_KEY", "help": "Visit https://platform.openai.com/api-keys or https://link-ai.tech to get an API key"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Set API base URL (default to OpenAI's official endpoint)
|
||||
api_base="${OPENAI_API_BASE:-https://api.openai.com/v1}"
|
||||
# Remove trailing slash if present
|
||||
api_base="${api_base%/}"
|
||||
|
||||
@@ -175,7 +183,7 @@ fi
|
||||
curl_cmd=$(command -v curl)
|
||||
response=$($curl_cmd -sS --max-time 60 \
|
||||
-X POST \
|
||||
-H "Authorization: Bearer $OPENAI_API_KEY" \
|
||||
-H "Authorization: Bearer $api_key" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$request_body" \
|
||||
"$api_base/chat/completions" 2>&1)
|
||||
|
||||
@@ -261,14 +261,15 @@ Write the YAML frontmatter with `name`, `description`, and optional `metadata`:
|
||||
- Example description for a `docx` skill: "Comprehensive document creation, editing, and analysis with support for tracked changes, comments, formatting preservation, and text extraction. Use when the agent needs to work with professional documents (.docx files) for: (1) Creating new documents, (2) Modifying or editing content, (3) Working with tracked changes, (4) Adding comments, or any other document tasks"
|
||||
- `metadata`: (Optional) Specify requirements and configuration
|
||||
- `requires.bins`: Required binaries (e.g., `["curl", "jq"]`)
|
||||
- `requires.env`: Required environment variables (e.g., `["OPENAI_API_KEY"]`)
|
||||
- `primaryEnv`: Primary environment variable name (for API keys)
|
||||
- `requires.env`: Required environment variables — all must be set (e.g., `["MYAPI_KEY"]`)
|
||||
- `requires.anyEnv`: Alternative environment variables — at least one must be set (e.g., `["OPENAI_API_KEY", "LINKAI_API_KEY"]`)
|
||||
- `requires.anyBins`: Alternative binaries — at least one must be present
|
||||
- `always`: Set to `true` to always load regardless of requirements
|
||||
- `emoji`: Skill icon (optional)
|
||||
|
||||
**API Key Requirements**:
|
||||
|
||||
If your skill needs an API key, declare it in metadata:
|
||||
If your skill needs a single API key, declare it in `requires.env`:
|
||||
|
||||
```yaml
|
||||
---
|
||||
@@ -278,7 +279,19 @@ metadata:
|
||||
requires:
|
||||
bins: ["curl"]
|
||||
env: ["MYAPI_KEY"]
|
||||
primaryEnv: "MYAPI_KEY"
|
||||
---
|
||||
```
|
||||
|
||||
If your skill supports multiple API key providers (e.g., OpenAI or LinkAI), use `requires.anyEnv`:
|
||||
|
||||
```yaml
|
||||
---
|
||||
name: my-vision
|
||||
description: Analyze images using Vision API
|
||||
metadata:
|
||||
requires:
|
||||
bins: ["curl"]
|
||||
anyEnv: ["OPENAI_API_KEY", "LINKAI_API_KEY"]
|
||||
---
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user