Skip to content

Add icon search skill for SVG retrieval across multiple use cases#8

Merged
hustcc merged 8 commits into
masterfrom
copilot/add-infographic-icon-skill
Jan 23, 2026
Merged

Add icon search skill for SVG retrieval across multiple use cases#8
hustcc merged 8 commits into
masterfrom
copilot/add-infographic-icon-skill

Conversation

Copilot AI commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

Adds icon discovery capability for various use cases including infographics, web development, design, and more. Users can search by keywords and retrieve SVG content directly. fixed #27

Implementation

New skill: skills/infographic-icon/

  • SKILL.md - Documentation with usage examples for multiple scenarios
  • scripts/search.py - Python script using standard library (requires Python 3.6+)
  • Updated README.md with skill description

Script behavior:

  • Accepts search query as CLI argument: python ./scripts/search.py 'security'
  • Accepts optional topK parameter to control number of results (default: 5)
  • Queries API at https://www.weavefox.cn/api/open/v1/icon directly
  • Fetches SVG content from returned URLs in the API response
  • Returns up to 5 matching results by default (customizable via topK parameter)
  • Outputs SVG strings along with source URLs
  • Uses Python standard library (no external dependencies)

Output format:

{
  "query": "security",
  "topK": 5,
  "count": 2,
  "results": [
    {
      "url": "https://example.com/shield.svg",
      "svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">...</svg>"
    }
  ]
}

Usage examples:

# Search for icons (default 5 results)
python ./scripts/search.py 'fast'

# Search with custom number of results
python ./scripts/search.py 'fast' 10
python ./scripts/search.py 'fast' 20

# Use in web development, design, infographics, etc.
# SVG content can be directly embedded in HTML, design tools, or infographic configurations

Requirements:

  • Python 3.6+
Original prompt

Overview

Create a new Claude skill named infographic-icon that provides icon search and SVG string retrieval capabilities based on the AntV Infographic icon service (https://infographic.antv.vision/icon).

Requirements

1. Skill Structure

Create a new skill at skills/infographic-icon/ following the standard Claude skill format, similar to existing skills in the repository.

2. SKILL.md File

Create skills/infographic-icon/SKILL.md with:

  • Frontmatter with name: infographic-icon and appropriate description
  • Description of the skill's purpose: searching for icons and retrieving their SVG strings
  • Clear instructions on how to use the skill
  • Workflow explaining:
    • How to search for icons by keywords
    • That only top 5 results are returned per query
    • How to get SVG strings directly (not remote URLs)
  • Examples of usage

3. Node.js Script

Create skills/infographic-icon/scripts/search.js that:

  • Accepts a search query as a command-line argument
  • Queries the icon API at https://infographic.antv.vision/icon (or appropriate API endpoint)
  • Returns only the top 5 matching results
  • Returns SVG strings directly, not remote URLs
  • Outputs results in a clear JSON format containing:
    • Icon name/identifier
    • Icon keywords
    • SVG string content
  • Handles errors gracefully
  • Includes proper Node.js shebang and executable permissions setup

Script execution format:

node ./scripts/search.js '<search_query>'

4. Dependencies

If the script requires dependencies (e.g., node-fetch, axios), add them to the SKILL.md frontmatter:

dependency:
  node: axios@^1.0.0

5. README.md Update

Update the README.md file in the root directory:

  • Add infographic-icon to the "Available Skills" section
  • Provide a concise description: "Search and retrieve icon SVG strings from AntV Infographic icon library. Returns top 5 matching icons with their SVG content."
  • Maintain consistency with the existing skill descriptions format
  • Place it appropriately in the list (alphabetically or by category)

Technical Notes

Icon API Investigation

The script should:

  1. Make HTTP requests to the infographic icon service
  2. Parse the response to extract icon data
  3. Fetch the actual SVG content for each icon (if the API returns URLs, the script must fetch the SVG content)
  4. Limit results to top 5
  5. Format output as JSON with icon metadata and SVG strings

Error Handling

  • Handle network errors
  • Handle invalid search queries
  • Handle empty results
  • Provide meaningful error messages

Output Format Example

{
  "query": "search term",
  "results": [
    {
      "name": "icon-name",
      "keywords": ["keyword1", "keyword2"],
      "svg": "<svg>...</svg>"
    }
  ]
}

Success Criteria

  1. ✅ Skill follows the standard Claude skill format used in this repository
  2. ✅ SKILL.md is complete with proper frontmatter, description, and usage instructions
  3. ✅ Node.js script successfully searches icons and returns SVG strings
  4. ✅ Script limits results to top 5
  5. ✅ Script returns SVG strings, not URLs
  6. ✅ README.md is updated with the new skill
  7. ✅ All documentation is in English
  8. ✅ Code follows the patterns established by existing skills in the repository

Additional Context

This skill is designed to help users find appropriate icons when creating infographics with the AntV Infographic tool. Users should be able to search by keywords and receive actual SVG content that can be directly used in their infographic configurations.

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: hustcc <7856674+hustcc@users.noreply.github.com>
@hustcc

hustcc commented Jan 23, 2026

Copy link
Copy Markdown
Member

#2

Co-authored-by: hustcc <7856674+hustcc@users.noreply.github.com>
@hustcc

hustcc commented Jan 23, 2026

Copy link
Copy Markdown
Member

@copilot 需要修正,我补充几个信息,修改一下:

Copilot AI changed the title [WIP] Add new infographic-icon skill for icon search and SVG retrieval Add infographic-icon skill for icon search and SVG retrieval Jan 23, 2026
Copilot AI requested a review from hustcc January 23, 2026 15:05
Co-authored-by: hustcc <7856674+hustcc@users.noreply.github.com>

Copilot AI commented Jan 23, 2026

Copy link
Copy Markdown
Contributor Author

@copilot 需要修正,我补充几个信息,修改一下:

已完成修改 (4b97b89):

  1. ✅ 更新 API 接口为 https://www.weavefox.cn/api/open/v1/icon?text={query}&topK=20
  2. ✅ 移除所有 infographic 专属描述,改为通用描述(可用于信息图、网页开发、设计等多个场景)
  3. ✅ 更新结果数量上限从 5 改为 20

主要改动:

  • search.js: 更新 API 端点和参数
  • SKILL.md: 移除 infographic 集成章节,改为通用用途描述
  • README.md: 更新技能描述为通用场景

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.weavefox.cn
    • Triggering command: /usr/local/bin/node node ./scripts/search.js document (dns block)
    • Triggering command: /usr/local/bin/node node ./scripts/search.js security (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Add infographic-icon skill for icon search and SVG retrieval Add icon search skill for SVG retrieval across multiple use cases Jan 23, 2026
@hustcc

hustcc commented Jan 23, 2026

Copy link
Copy Markdown
Member

@copilot icon 请求数量 topK 也作为 scripts 参数,并在 skill.md 中透出,默认数量为 5。

Co-authored-by: hustcc <7856674+hustcc@users.noreply.github.com>

Copilot AI commented Jan 23, 2026

Copy link
Copy Markdown
Contributor Author

@copilot icon 请求数量 topK 也作为 scripts 参数,并在 skill.md 中透出,默认数量为 5。

已完成修改 (c10b3ee):

  1. ✅ 添加 topK 作为脚本参数,默认值为 5
  2. ✅ 在 SKILL.md 中详细说明了 topK 参数的使用方法
  3. ✅ 支持自定义 topK 值(例如:node ./scripts/search.js 'query' 10
  4. ✅ 输出结果中包含 topK 字段
  5. ✅ 添加参数验证(必须为正整数)

使用示例:

# 默认返回 5 个结果
node ./scripts/search.js 'document'

# 返回 10 个结果
node ./scripts/search.js 'document' 10

# 返回 20 个结果
node ./scripts/search.js 'document' 20

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.weavefox.cn
    • Triggering command: /usr/local/bin/node node ./scripts/search.js document (dns block)
    • Triggering command: /usr/local/bin/node node ./scripts/search.js a 10 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@hustcc

hustcc commented Jan 23, 2026

Copy link
Copy Markdown
Member

@copilot 修改几个点:

  1. 去掉所有 common icon keywords 相关内容
  2. search.js 的脚本写的简洁一些,直接用 nodejs 内置的 fetch api,也不用有 common icon 的逻辑

Co-authored-by: hustcc <7856674+hustcc@users.noreply.github.com>

Copilot AI commented Jan 23, 2026

Copy link
Copy Markdown
Contributor Author

@copilot 修改几个点:

  1. 去掉所有 common icon keywords 相关内容...

已完成修改 (db9f1cb):

  1. ✅ 移除所有 common icon keywords 相关内容

    • 删除 SKILL.md 中的 "Common Icon Keywords" 章节
    • 删除脚本中的 getCommonIcons() 函数及所有内置图标数据
  2. ✅ 简化 search.js 脚本

    • 使用 Node.js 内置的 fetch API(无需 require https/http 模块)
    • 移除所有 common icon 的 fallback 逻辑
    • 代码从 297 行简化到 89 行
    • 直接调用 API,失败时返回错误信息

脚本现在更简洁高效,仅依赖 Node.js 18+ 的内置功能。

@hustcc

hustcc commented Jan 23, 2026

Copy link
Copy Markdown
Member

@copilot 脚本依然写的不对,看起来你对 nodejs 不是很擅长,我们改成使用 python 来实现这个 icon 请求脚本。我重新说明一些接口文档:

接口地址 https://www.weavefox.cn/api/open/v1/icon?text=keyword&topK=5

接口类型 GET

参数:

  • text string 类型,查询文本,如 "数据分析"。
  • topK number 类型,可选,默认:5,查询图标数。

返回结构

{
"status": true,
"message": "success",
"data": {
"success": true,
"data": [
"https://example.com/icon1.svg",
"https://example.com/icon2.svg"
]
}
}

注意:

  1. 返回结构中的 data.data 是 svg 的远程地址,还需要额外请求获得 svg string
  2. 保持代码尽可能的简洁,精炼
  3. 注意修改 skill.md 中相关内容
  4. skill.md 中增加 python 版本依赖描述

Co-authored-by: hustcc <7856674+hustcc@users.noreply.github.com>

Copilot AI commented Jan 23, 2026

Copy link
Copy Markdown
Contributor Author

@copilot 脚本依然写的不对,看起来你对 nodejs 不是很擅长,我们改成使用 python 来实现这个 icon 请求脚本。我重新说明一些接口文档:

接口地址 https://ww...

已完成修改 (344a2cb):

  1. ✅ 改用 Python 实现脚本

    • 简洁实现,约 90 行代码
    • 使用 Python 标准库 urllib(无需额外依赖)
  2. ✅ 正确实现 API 结构

    • 解析 data.data 中的 URL 数组
    • 逐个请求 SVG 内容
    • 返回 name、url 和 svg 字段
  3. ✅ 更新 SKILL.md

    • 添加 Python 依赖声明:python>=3.6
    • 所有示例改用 python ./scripts/search.py
    • 更新输出格式示例
  4. ✅ 更新 README.md

    • 调整描述信息

使用示例:

# 默认返回 5 个结果
python ./scripts/search.py '数据分析'

# 返回 10 个结果
python ./scripts/search.py '数据分析' 10

@hustcc

hustcc commented Jan 23, 2026

Copy link
Copy Markdown
Member

@copilot 这次好很多了,最后 scripts 返回结构不需要 name,他是没有意义的,快点改,这个改完就可以合并了,记得 skill.md 相关部分也改了。

Co-authored-by: hustcc <7856674+hustcc@users.noreply.github.com>

Copilot AI commented Jan 23, 2026

Copy link
Copy Markdown
Contributor Author

@copilot 这次好很多了,最后 scripts 返回结构不需要 name,他是没有意义的,快点改,这个改完就可以合并了,记得 skill.md 相关部分也改了。

已完成修改 (3c23d5d):

✅ 移除 name 字段

  • 脚本输出中移除 name 字段
  • SKILL.md 所有相关描述已更新
  • README.md 描述已更新

现在输出结构只包含 urlsvg 两个字段:

{
  "query": "...",
  "topK": 5,
  "count": 2,
  "results": [
    {
      "url": "https://example.com/icon.svg",
      "svg": "<svg>...</svg>"
    }
  ]
}

@hustcc
hustcc marked this pull request as ready for review January 23, 2026 15:48
@hustcc
hustcc requested a review from Copilot January 23, 2026 15:48
@hustcc
hustcc merged commit a0b64f1 into master Jan 23, 2026
6 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new skill called infographic-icon that enables icon search and SVG retrieval functionality. The implementation uses Python (rather than the originally specified Node.js) to query an icon API and fetch SVG content based on keyword searches.

Changes:

  • New skill implementation with Python-based search script that queries an icon API and retrieves SVG strings
  • Comprehensive documentation in SKILL.md with usage examples, workflow, and error handling information
  • README.md updated with skill description following the existing format

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 12 comments.

File Description
skills/infographic-icon/scripts/search.py Python script that searches for icons via API and fetches SVG content, with customizable result count (default 5)
skills/infographic-icon/SKILL.md Complete documentation including purpose, usage, workflow, parameters, output format, and error handling
README.md Added infographic-icon skill entry with description consistent with other skills in the repository

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

})
except Exception as e:
print(f'Warning: Failed to fetch SVG from {url}: {e}', file=sys.stderr)

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The individual SVG fetching errors are only logged to stderr but don't affect the final exit status. If all SVG fetches fail, the script will still exit with code 0 (success) and return an empty results array. Users might not notice the warnings in stderr. Consider checking if any results were successfully fetched and provide a more visible indication when all fetches fail.

Suggested change
# If the API returned icon URLs but none of the SVGs could be fetched,
# treat this as an error so callers can detect the failure.
if icon_urls and not results:
raise Exception('Failed to fetch SVG content for all icons')

Copilot uses AI. Check for mistakes.
Comment on lines +28 to +30
if not data.get('status') or not data.get('data', {}).get('success'):
raise Exception(data.get('message', 'API request failed'))

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error condition checks both 'status' and nested 'success' fields, but it's unclear what the API actually returns. If 'status' is False but 'data' is missing, trying to access data.get('data', {}).get('success') will work safely, but the logic could be clearer. Additionally, if 'status' is True but 'data.success' is False, the error message from data.get('message') may not be the right one. Consider clarifying the expected API response structure in comments or refining the error condition logic.

Suggested change
if not data.get('status') or not data.get('data', {}).get('success'):
raise Exception(data.get('message', 'API request failed'))
# Expected API response structure (simplified):
# {
# "status": bool,
# "message": str,
# "data": {
# "success": bool,
# "message": str,
# "data": [ ... icon URLs ... ]
# }
# }
if not data.get('status'):
# Top-level status indicates failure
raise Exception(data.get('message', 'API request failed: status is false'))
if not data.get('data', {}).get('success'):
# Nested success flag indicates failure; prefer nested message when available
nested_message = data.get('data', {}).get(
'message',
data.get('message', 'API request failed: success is false')
)
raise Exception(nested_message)

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,92 @@
#!/usr/bin/env python3

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original requirement specified a Node.js implementation (with a search.js script), but the PR implements it in Python (search.py). While Python is valid and uses only standard library functions as required, this significant deviation from the original specification should be documented or justified. The PR description mentions this is from a Copilot chat, but the original prompt in the description clearly specifies Node.js with potential dependencies like 'node-fetch' or 'axios'. Consider adding a note explaining why Python was chosen over Node.js.

Copilot uses AI. Check for mistakes.
"""Search for icons and retrieve their SVG content"""
# Build API URL
params = urllib.parse.urlencode({'text': query, 'topK': top_k})
api_url = f'https://www.weavefox.cn/api/open/v1/icon?{params}'

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API endpoint used (https://www.weavefox.cn/api/open/v1/icon) differs from what the original requirement specified. The original prompt mentions using the AntV Infographic icon service at https://infographic.antv.vision/icon, but the implementation uses a different domain (weavefox.cn). This could affect reliability, availability, and whether the icons retrieved match the intended AntV Infographic icon library. Consider documenting why this endpoint was chosen or verifying it's the correct API for the AntV Infographic service.

Copilot uses AI. Check for mistakes.
Comment on lines +43 to +44
except Exception as e:
print(f'Warning: Failed to fetch SVG from {url}: {e}', file=sys.stderr)

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When multiple SVG fetches fail, each failure prints a warning to stderr independently. If a user requests 20 icons and all 20 SVG fetches fail, there will be 20 separate warning lines followed by a generic "No icons found" warning. This could be noisy and confusing. Consider aggregating failed URLs and reporting them together, or providing a count of failed fetches.

Copilot uses AI. Check for mistakes.
print(json.dumps(error, indent=2), file=sys.stderr)
sys.exit(1)

query = sys.argv[1]

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script doesn't validate whether the search query is empty or contains only whitespace. While the API might handle this gracefully, accepting an empty query could lead to confusing results or unnecessary API calls. Consider adding validation to reject empty or whitespace-only queries with a clear error message.

Suggested change
query = sys.argv[1]
query = sys.argv[1]
if not query.strip():
error = {
'error': 'Empty search query',
'usage': 'python search.py \'<search_query>\' [topK]',
'example': 'python search.py \'document\' 10',
'note': 'The search query must not be empty or only whitespace'
}
print(json.dumps(error, indent=2), file=sys.stderr)
sys.exit(1)

Copilot uses AI. Check for mistakes.
sys.exit(1)

query = sys.argv[1]
top_k = int(sys.argv[2]) if len(sys.argv) > 2 else 5

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The topK parameter parsing lacks error handling for non-integer values. If a user provides a non-numeric value (e.g., 'abc'), this will raise a ValueError that isn't caught, resulting in an unhandled exception and a confusing stack trace instead of a user-friendly error message. Consider wrapping this in a try-except block to catch ValueError and provide a clear error message about the invalid input type.

Suggested change
top_k = int(sys.argv[2]) if len(sys.argv) > 2 else 5
top_k = 5
if len(sys.argv) > 2:
try:
top_k = int(sys.argv[2])
except ValueError:
error = {
'error': 'Invalid topK value type',
'usage': 'python search.py \'<search_query>\' [topK]',
'note': 'topK must be an integer'
}
print(json.dumps(error, indent=2), file=sys.stderr)
sys.exit(1)

Copilot uses AI. Check for mistakes.
Comment on lines +25 to +37
with urllib.request.urlopen(api_url) as response:
data = json.loads(response.read())

if not data.get('status') or not data.get('data', {}).get('success'):
raise Exception(data.get('message', 'API request failed'))

icon_urls = data['data']['data']

# Fetch SVG content for each icon
results = []
for url in icon_urls:
try:
with urllib.request.urlopen(url) as svg_response:

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The urllib.request.urlopen calls lack timeout parameters, which can cause the script to hang indefinitely if the remote server is unresponsive. This affects both the API request (line 25) and the SVG fetching (line 37). Add timeout parameters to prevent indefinite hangs. For example: urllib.request.urlopen(api_url, timeout=30)

Copilot uses AI. Check for mistakes.
raise Exception(data.get('message', 'API request failed'))

icon_urls = data['data']['data']

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no validation that icon_urls is actually a list before iterating over it. If the API returns an unexpected data structure (e.g., None, a string, or a dict), the for loop will either fail with a confusing error or iterate over unintended values. Add validation to ensure icon_urls is a list before processing. For example: if not isinstance(icon_urls, list): raise Exception('Invalid API response: expected list of URLs')

Suggested change
if not isinstance(icon_urls, list):
raise Exception('Invalid API response: expected list of icon URLs')

Copilot uses AI. Check for mistakes.

# Fetch SVG content for each icon
results = []
for url in icon_urls:

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URLs from the API response are used directly in urllib.request.urlopen without validation. This could be a security risk if the API is compromised or returns malicious URLs (e.g., file:// URLs that could expose local files, or URLs to internal network resources). Consider validating that URLs start with 'http://' or 'https://' before making requests.

Suggested change
for url in icon_urls:
for url in icon_urls:
# Validate that the URL uses a safe scheme before fetching
parsed_url = urllib.parse.urlparse(url)
if parsed_url.scheme not in ('http', 'https'):
print(f'Warning: Skipping icon with unsafe URL scheme: {url}', file=sys.stderr)
continue

Copilot uses AI. Check for mistakes.
@hustcc
hustcc deleted the copilot/add-infographic-icon-skill branch January 23, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Icon 检索

3 participants