Skip to content

Create, Evaluate, and Connect AI Skills

update client and readme

LiamLYYY3ad9e484a18d
diff --git a/skillnet-ai/README.md b/skillnet-ai/README.md
index 52a2d36..6fd0d7c 100644
--- a/skillnet-ai/README.md
+++ b/skillnet-ai/README.md
@@ -29,101 +29,89 @@ pip install skillnet-ai
## 🛠 Usage (Python SDK)
-### 1. Search for Skills
+The `SkillNetClient` provides a unified interface for searching, downloading, creating, and evaluating skills.
-You can search for skills using keywords or natural language (AI Search).
+### 1. Initialize the Client
+
+Initialize the client with your credentials. You can also set `API_KEY` and `GITHUB_TOKEN` in your environment variables.
```python
-from skillnet_ai import SkillNetSearcher
+from skillnet_ai import SkillNetClient
-searcher = SkillNetSearcher()
+# Initialize with optional credentials
+client = SkillNetClient(
+ api_key="sk-...", # Required for AI Search, Creation, and Evaluation
+ base_url="...", # Optional custom LLM base URL
+ github_token="ghp-..." # Optional, for private repos or higher rate limits
+)
+```
-# 1. Standard Keyword Search
-results = searcher.search(q="pdf")
+### 2. Search for Skills
+Perform keyword-based or semantic AI searches to find skills.
-# 2. Semantic Search
-results = searcher.search(q="Help me analyze financial PDF reports", mode="vector")
+```python
+# 1. Standard Keyword Search
+results = client.search(q="pdf tool")
-top_skill = results[0]
-print(f"Top Skill: {top_skill.skill_name} (Stars: {top_skill.stars})")
-print(f"Description: {top_skill.skill_description}")
-print(f"URL: {skill.skill_url}")
+# 2. Semantic AI Search (requires api_key)
+results = client.search(q="Help me analyze financial PDF reports", mode="vector")
+if results:
+ top_skill = results[0]
+ print(f"Found: {top_skill.skill_name} (Stars: {top_skill.stars})")
+ print(f"URL: {top_skill.skill_url}")
```
-### 2. Install a Skill
-
-Once you have a skill's URL (usually from the search results), you can download and install it into your agent's workspace.
+### 3. Install a Skill
+Download and install a skill directly from a URL (e.g., from search results) into your local workspace.
```python
-from skillnet_ai import SkillDownloader
-
skill_url = "https://github.com/anthropics/skills/tree/main/skills/skill-creator"
-# Downloads and extracts the skill to target_dir
-skilldownloader = SkillDownloader()
-local_path = skilldownloader.download(skill_url, target_dir="./my_agent_skills")
-
-if local_path:
+try:
+ # Downloads to ./my_agent_skills
+ local_path = client.download(url=skill_url, target_dir="./my_agent_skills")
print(f"Skill successfully installed at: {local_path}")
+except Exception as e:
+ print(f"Download failed: {e}")
```
-### 3. Create a Skill from Trajectory
-
-Turn raw conversation logs or execution traces into a polished Skill Package (`SKILL.md`, scripts, etc.).
-
-> **Note:** This feature requires an LLM API Key.
+### 4. Create a Skill from Trajectory
+Turn conversation logs or execution traces into a polished Skill Package (SKILL.md, scripts, etc.).
```python
-import os
-from skillnet_ai import SkillCreator
-
-# 1. Prepare your trajectory (e.g., a conversation log)
+# 1. Prepare your trajectory (e.g., a conversation log string)
trajectory_log = """
User: I need to rename all .jpg files in this folder to .png.
Agent: I will write a python script to iterate through the folder...
Agent: Script executed. Renamed 5 files.
"""
-# Set your API key and url
-api_key="sk-...", # Your API Key
-base_url="xxxxxx", # Optional. Useful if using a proxy or compatible API
-
-# 2. Initialize Creator
-creator = SkillCreator(api_key=api_key, base_url=base_url, model="gpt-4o")
-
-# 3. Create Skills
-output_dir = "./created_skills"
-created_paths = creator.create_from_trajectory(trajectory_log, output_dir=output_dir)
+# 2. Generate Skills
+# Returns a list of paths to the generated skill folders
+created_paths = client.create(
+ trajectory_content=trajectory_log,
+ output_dir="./created_skills",
+ model="gpt-4o"
+)
-print(f"Created {len(created_paths)} new skills in {output_dir}")
+print(f"Created {len(created_paths)} new skills.")
+for path in created_paths:
+ print(f"- {path}")
```
-### 4. Skill Evaluation
-
-Assess the Safety, Completeness, Excutability, Modifiability and Cost-Aware of a skill before using it. This tool generates a complete evaluation based on the skill's code and documentation.
-
-> **Note:** This feature requires an LLM API Key.
+### 5. Skill Evaluation
+Assess the Safety, Completeness, Executability, and Modifiability of a skill. Supports both remote GitHub URLs and local directories.
```python
-import os
-from skillnet_ai import SkillEvaluator, EvaluatorConfig
-
-# 1. Configure the Evaluator
-config = EvaluatorConfig(
- api_key="sk-...", # Your API Key
- base_url="xxxxxx", # Optional. Useful if using a proxy or compatible API
- model="gpt-4o" # Model to use for evaluation
-)
-evaluator = SkillEvaluator(config)
-
-# 2. Evaluate a Skill (from URL or Local Path)
-skill_url = "https://github.com/microsoft/autogen/tree/main/samples/tools/web_search"
+# target_skill = "./my_skills/web_search"
+target_skill = "https://github.com/microsoft/autogen/tree/main/samples/tools/web_search"
-# You can also use evaluator.evaluate_from_path("./my_skills/web_search")
-result = evaluator.evaluate_from_url(skill_url)
+# Evaluates the skill using the client's API key
+result = client.evaluate(target=target_skill)
-print(f"Evaluation: {result}")
+# Display results
+print(f"Evaluation Result: {result}")
```
---
@@ -157,7 +145,7 @@ skillnet search "visualization" --category "Data" --sort-by stars --limit 10
--min-stars: Filter results by minimum star rating.
-### 2. Download Skills (download)
+### 2. Install Skills (download)
Download and install a skill directly from a GitHub repository subdirectory.
@@ -186,7 +174,7 @@ skillnet create ./logs/trajectory.txt --output-dir ./generated_skills
skillnet create ./logs/chat_history.txt --model gpt-4o
```
-### Evaluate Skills (evaluate)
+### 4. Evaluate Skills (evaluate)
Generate a comprehensive quality report (Safety, Completeness, Executability, Modifiability, Cost Awareness) for a skill.
Requirement: Ensure API_KEY is set in your environment variables.
diff --git a/skillnet-ai/src/skillnet_ai/__init__.py b/skillnet-ai/src/skillnet_ai/__init__.py
index bfff398..bd4d9e6 100644
--- a/skillnet-ai/src/skillnet_ai/__init__.py
+++ b/skillnet-ai/src/skillnet_ai/__init__.py
@@ -5,12 +5,14 @@ SkillNet AI SDK
A client library for searching, downloading, creating and evaluating AI Agent Skills.
"""
+from skillnet_ai.client import SkillNetClient
from skillnet_ai.creator import SkillCreator
from skillnet_ai.downloader import SkillDownloader
from skillnet_ai.evaluator import SkillEvaluator, EvaluatorConfig
from skillnet_ai.searcher import SkillNetSearcher
__all__ = [
+ "SkillNetClient",
"SkillCreator",
"SkillDownloader",
"SkillEvaluator",
diff --git a/skillnet-ai/src/skillnet_ai/client.py b/skillnet-ai/src/skillnet_ai/client.py
new file mode 100644
index 0000000..423b458
--- /dev/null
+++ b/skillnet-ai/src/skillnet_ai/client.py
@@ -0,0 +1,213 @@
+import os
+from typing import List, Optional, Dict, Any, Union
+from pathlib import Path
+
+from skillnet_ai.creator import SkillCreator
+from skillnet_ai.downloader import SkillDownloader
+from skillnet_ai.evaluator import SkillEvaluator, EvaluatorConfig
+from skillnet_ai.searcher import SkillNetSearcher
+
+class SkillNetError(Exception):
+ """Custom exception class for SkillNet Client errors."""
+ pass
+
+class SkillNetClient:
+ """
+ A Python SDK client for interacting with SkillNet AI services.
+
+ This client aggregates Search, Download, Creation, and Evaluation functionalities.
+ """
+
+ def __init__(
+ self,
+ api_key: Optional[str] = None,
+ base_url: Optional[str] = None,
+ github_token: Optional[str] = None
+ ):
+ """
+ Initialize the SkillNet Client.
+
+ Args:
+ api_key: OpenAI/SkillNet API Key. Defaults to env var API_KEY.
+ base_url: Base URL for the LLM API. Defaults to env var BASE_URL or OpenAI default.
+ github_token: GitHub token for downloading private skills or avoiding rate limits.
+ Defaults to env var GITHUB_TOKEN.
+ """
+ self.api_key = api_key or os.getenv("API_KEY")
+ self.base_url = base_url or os.getenv("BASE_URL")
+ self.github_token = github_token or os.getenv("GITHUB_TOKEN")
+
+
+ def search(
+ self,
+ q: str,
+ mode: str = "keyword",
+ category: Optional[str] = None,
+ limit: int = 20,
+ page: int = 1,
+ min_stars: int = 0,
+ sort_by: str = "stars",
+ threshold: float = 0.8
+ ) -> List[Any]:
+ """
+ Search for skills on SkillNet.
+
+ Args:
+ q: The search query.
+ mode: 'keyword' or 'vector'.
+ category: Filter by category.
+ limit: Max results.
+ page: Page number (keyword mode only).
+ min_stars: Filter by stars (keyword mode only).
+ sort_by: 'stars' or 'recent' (keyword mode only).
+ threshold: Similarity threshold (vector mode only).
+
+ Returns:
+ List[SkillModel]: A list of skill objects found.
+ """
+ try:
+ searcher = SkillNetSearcher()
+ results = searcher.search(
+ q=q,
+ mode=mode,
+ category=category,
+ limit=limit,
+ page=page,
+ min_stars=min_stars,
+ sort_by=sort_by,
+ threshold=threshold
+ )
+ return results
+ except Exception as e:
+ raise SkillNetError(f"Search failed: {str(e)}") from e
+
+ def download(
+ self,
+ url: str,
+ target_dir: str = ".",
+ token: Optional[str] = None
+ ) -> str:
+ """
+ Download a skill from a GitHub URL.
+
+ Args:
+ url: The GitHub URL of the specific skill folder.
+ target_dir: Local directory to install into.
+ token: Optional override for GitHub token.
+
+ Returns:
+ str: The absolute path to the installed skill folder.
+
+ Raises:
+ SkillNetError: If download fails.
+ """
+ # Use instance token if specific token not provided
+ use_token = token if token else self.github_token
+ downloader = SkillDownloader(api_token=use_token)
+
+ try:
+ installed_path = downloader.download(folder_url=url, target_dir=target_dir)
+ if not installed_path:
+ raise SkillNetError("Download returned None. Check URL validity or permissions.")
+ return os.path.abspath(installed_path)
+ except Exception as e:
+ raise SkillNetError(f"Download failed: {str(e)}") from e
+
+ def create(
+ self,
+ trajectory_content: str,
+ output_dir: Union[str, Path] = "./generated_skills",
+ model: str = "gpt-4o"
+ ) -> List[str]:
+ """
+ Generate executable skills from a trajectory log.
+
+ Args:
+ trajectory_content: The text content of the execution log/trajectory.
+ output_dir: Directory where new skills will be saved.
+ model: The LLM model to use.
+
+ Returns:
+ List[str]: A list of paths to the generated skill folders.
+ """
+ if not self.api_key:
+ raise SkillNetError("API_KEY is required for skill creation.")
+
+ if not trajectory_content.strip():
+ raise SkillNetError("Trajectory content is empty.")
+
+ try:
+ creator = SkillCreator(
+ api_key=self.api_key,
+ base_url=self.base_url,
+ model=model
+ )
+
+ created_paths = creator.create_from_trajectory(
+ trajectory=trajectory_content,
+ output_dir=str(output_dir)
+ )
+
+ return created_paths if created_paths else []
+ except Exception as e:
+ raise SkillNetError(f"Creation failed: {str(e)}") from e
+
+ def evaluate(
+ self,
+ target: str,
+ name: Optional[str] = None,
+ category: Optional[str] = None,
+ description: Optional[str] = None,
+ model: str = "gpt-4o",
+ max_workers: int = 5
+ ) -> Dict[str, Any]:
+ """
+ Evaluate a skill (local path or URL).
+
+ Args:
+ target: Local folder path OR GitHub URL.
+ name: Override skill name.
+ category: Override skill category.
+ description: Override skill description.
+ model: LLM model for evaluation.
+ max_workers: Concurrency limit.
+
+ Returns:
+ Dict[str, Any]: The evaluation report dictionary.
+ """
+ if not self.api_key:
+ raise SkillNetError("API_KEY is required for evaluation.")
+
+ config = EvaluatorConfig(
+ api_key=self.api_key,
+ base_url=self.base_url,
+ model=model,
+ max_workers=max_workers
+ )
+ evaluator = SkillEvaluator(config)
+
+ try:
+ is_url = target.startswith("http://") or target.startswith("https://")
+
+ if is_url:
+ result = evaluator.evaluate_from_url(
+ url=target,
+ name=name,
+ category=category,
+ description=description
+ )
+ else:
+ result = evaluator.evaluate_from_path(
+ path=target,
+ name=name,
+ category=category,
+ description=description
+ )
+
+ if "error" in result:
+ raise SkillNetError(f"Evaluation logic returned error: {result['error']}")
+
+ return result
+
+ except Exception as e:
+ raise SkillNetError(f"Evaluation process failed: {str(e)}") from e
\ No newline at end of file