Skip to content

Create, Evaluate, and Connect AI Skills

update examples

Jiang Chen40e59218afaf
diff --git a/skillnet-ai/examples/create_example.py b/skillnet-ai/examples/create_example.py
index 17d0d51..4022396 100644
--- a/skillnet-ai/examples/create_example.py
+++ b/skillnet-ai/examples/create_example.py
@@ -1,10 +1,10 @@
+"""
+Skill Creation Example - Using SkillNetClient
+"""
import os
-import logging
-from skillnet_ai import SkillCreator
+from skillnet_ai import SkillNetClient
-logging.basicConfig(level=logging.INFO)
-
-# Sample trajectory for demonstration
+# Sample trajectory
SAMPLE_TRAJECTORY = """
User: Please analyze this invoice.pdf and extract the total amount and date.
Agent: I will use the PDF tool. Opening invoice.pdf...
@@ -12,70 +12,35 @@ Agent: Text extracted. Found 'Total: $500' and 'Date: 2023-10-12'.
Agent: The total is $500 and the date is Oct 12, 2023.
"""
-
-def create_from_trajectory():
- """Create skill from execution trajectory."""
- api_key = os.getenv("API_KEY")
- if not api_key:
- print("Please set API_KEY environment variable.")
- return
-
- base_url = os.getenv("BASE_URL") or "https://api.openai.com/v1"
- creator = SkillCreator(api_key=api_key, base_url=base_url, model="gpt-4o")
-
- print("πŸš€ Creating skill from trajectory...")
-
- try:
- paths = creator.create_from_trajectory(
- trajectory=SAMPLE_TRAJECTORY,
- output_dir="./created_skills"
- )
- print("\n✨ Creation Complete!")
- for p in paths:
- print(f" - Created: {p}")
- except Exception as e:
- print(f"❌ Error: {e}")
-
-
-def create_from_github():
- """Create skill from GitHub repository."""
- api_key = os.getenv("API_KEY")
- if not api_key:
- print("Please set API_KEY environment variable.")
- return
-
- base_url = os.getenv("BASE_URL") or "https://api.openai.com/v1"
- github_token = os.getenv("GITHUB_TOKEN")
-
- creator = SkillCreator(api_key=api_key, base_url=base_url, model="gpt-4o")
-
- # Example: DeepKE - Knowledge Extraction Toolkit
- github_url = "https://github.com/zjunlp/DeepKE"
-
- print(f"πŸš€ Creating skill from GitHub: {github_url}")
-
- try:
- paths = creator.create_from_github(
- github_url=github_url,
- output_dir="./created_skills",
- api_token=github_token,
- max_files=20
- )
- print("\n✨ Creation Complete!")
- for p in paths:
- print(f" - Created: {p}")
- except Exception as e:
- print(f"❌ Error: {e}")
+# Sample GitHub repository URL
+SAMPLE_GITHUB_URL = "https://github.com/zjunlp/DeepKE"
def main():
- import sys
-
- if len(sys.argv) > 1 and sys.argv[1] == "--github":
- create_from_github()
- else:
- create_from_trajectory()
- print("\nπŸ’‘ Tip: Use --github flag to create from GitHub repository")
+ # Initialize client
+ client = SkillNetClient(
+ api_key=os.getenv("API_KEY"),
+ base_url=os.getenv("BASE_URL", "https://api.openai.com/v1"),
+ github_token=os.getenv("GITHUB_TOKEN"),
+ )
+
+ # Example 1: Create from trajectory
+ print("πŸš€ Creating skill from trajectory...")
+ paths = client.create(
+ trajectory_content=SAMPLE_TRAJECTORY,
+ output_dir="./created_skills"
+ )
+ for p in paths:
+ print(f" - {p}")
+
+ # Example 2: Create from GitHub repository
+ print("\nπŸš€ Creating skill from GitHub...")
+ paths = client.create(
+ github_url=SAMPLE_GITHUB_URL,
+ output_dir="./created_skills"
+ )
+ for p in paths:
+ print(f" - {p}")
if __name__ == "__main__":
diff --git a/skillnet-ai/examples/evaluate_example.py b/skillnet-ai/examples/evaluate_example.py
index 7e48af4..21333b5 100644
--- a/skillnet-ai/examples/evaluate_example.py
+++ b/skillnet-ai/examples/evaluate_example.py
@@ -1,69 +1,29 @@
+"""
+Skill Evaluation Example - Using SkillNetClient
+"""
import os
-import json
-import logging
-import shutil
-from typing import Dict, Any
-from skillnet_ai import SkillEvaluator, EvaluatorConfig
+from skillnet_ai import SkillNetClient
-# Setup logging configuration
-logging.basicConfig(level=logging.INFO)
def main():
- # 1. Configure Evaluator
- api_key = os.getenv("API_KEY")
- if not api_key:
- print("Please set API_KEY environment variable to run this demo.")
- return
- base_url = os.getenv("BASE_URL") or "https://api.openai.com/v1" # Optional, custom base URL or default
+ # Initialize client
+ client = SkillNetClient(
+ api_key=os.getenv("API_KEY"),
+ base_url=os.getenv("BASE_URL", "https://api.openai.com/v1"),
+ )
- config = EvaluatorConfig(
- api_key=api_key,
- base_url=base_url,
- model="gpt-4o",
- temperature=0.2,
+ # Evaluate a remote skill from GitHub
+ print("πŸ“Š Evaluating remote skill...")
+ result = client.evaluate(
+ target="https://github.com/microsoft/autogen/tree/main/samples/tools/web_search"
)
-
- try:
- evaluator = SkillEvaluator(config)
- print("Evaluator initialized successfully.")
- except Exception as e:
- print(f"Failed to init evaluator: {e}")
- return
+ print("Result:", result)
- # =================================================================
- # A: Evaluate Local Skill Path
- # =================================================================
- local_skill_path = "/zjunlp/liangyuan/code/skills-resource/skillnet-ai/created_skills/pdf-invoice-data-extractor" # replace with your local skill path
-
- try:
- print(f"Starting evaluation for local path: {local_skill_path}")
-
- result_local = evaluator.evaluate_from_path(
- local_skill_path
- )
-
- print("Local Skill Evaluation", result_local)
-
- except Exception as e:
- print(f"Local evaluation failed: {e}")
+ # Evaluate a local skill directory
+ print("\nπŸ“Š Evaluating local skill...")
+ result = client.evaluate(target="./my_skills/example-skill")
+ print("Result:", result)
- # =================================================================
- # B: Evaluate Skill from URL
- # =================================================================
- target_url = "https://github.com/anthropics/skills/tree/main/skills/algorithmic-art"
-
- try:
- print(f"Starting evaluation for URL: {target_url}")
-
- result_url = evaluator.evaluate_from_url(
- target_url,
- description="Auto-downloaded skill for web searching"
- )
-
- print("URL Skill Evaluation", result_url)
-
- except Exception as e:
- print(f"URL evaluation failed (Create mock Downloader to fix): {e}")
if __name__ == "__main__":
main()
\ No newline at end of file
diff --git a/skillnet-ai/examples/search_demo.py b/skillnet-ai/examples/search_demo.py
index 00cae8f..010265b 100644
--- a/skillnet-ai/examples/search_demo.py
+++ b/skillnet-ai/examples/search_demo.py
@@ -1,52 +1,32 @@
-import logging
-from skillnet_ai import SkillNetSearcher, SkillDownloader
+"""
+Skill Search & Download Example - Using SkillNetClient
+"""
+from skillnet_ai import SkillNetClient
-# Setup logging configuration
-logging.basicConfig(level=logging.INFO)
def main():
- # Initialize the searcher
- searcher = SkillNetSearcher()
-
- query = "python"
- print(f"πŸ” Searching for: {query}")
-
- # Perform AI Search (Vector mode)
- # Note: We now use the unified 'search' method with mode="vector"
- results = searcher.search(
- q=query,
- limit=10,
- category="Development",
- )
-
+ # Initialize client (api_key optional for search/download)
+ client = SkillNetClient()
+
+ # Search for skills
+ print("πŸ” Searching for: pdf tool")
+ results = client.search(q="pdf tool", limit=5)
+
if not results:
print("❌ No skills found.")
return
- print(f"βœ… Found {len(results)} skills.")
-
- # Display the top result
+ print(f"βœ… Found {len(results)} skills.\n")
+ for skill in results:
+ print(f" - {skill.skill_name} (⭐ {skill.stars})")
+
+ # Download top skill
top_skill = results[0]
- print(f"Top Skill: {top_skill.skill_name} (Stars: {top_skill.stars})")
- print(f"Description: {top_skill.skill_description}")
-
- # Install the skill if a valid URL exists
if top_skill.skill_url:
- print("⬇️ Installing skill...")
- skilldownloader = SkillDownloader()
-
- # Download the skill to a local directory
- local_path = skilldownloader.download(
- top_skill.skill_url,
- target_dir="./my_skills"
- )
-
- if local_path:
- print(f"πŸŽ‰ Skill ready at: {local_path}")
- else:
- print("⚠️ Download failed or returned no path.")
- else:
- print("ℹ️ No download URL available for this skill.")
+ print(f"\n⬇️ Downloading: {top_skill.skill_name}")
+ local_path = client.download(url=top_skill.skill_url, target_dir="./my_skills")
+ print(f"πŸŽ‰ Installed at: {local_path}")
+
if __name__ == "__main__":
main()
\ No newline at end of file
diff --git a/skillnet-ai/src/skillnet_ai/client.py b/skillnet-ai/src/skillnet_ai/client.py
index 39968bd..ae4a651 100644
--- a/skillnet-ai/src/skillnet_ai/client.py
+++ b/skillnet-ai/src/skillnet_ai/client.py
@@ -115,26 +115,36 @@ class SkillNetClient:
def create(
self,
- trajectory_content: str,
+ trajectory_content: Optional[str] = None,
+ github_url: Optional[str] = None,
output_dir: Union[str, Path] = "./generated_skills",
- model: str = "gpt-4o"
+ model: str = "gpt-4o",
+ max_files: int = 20
) -> List[str]:
"""
- Generate executable skills from a trajectory log.
+ Generate executable skills from a trajectory log or GitHub repository.
Args:
trajectory_content: The text content of the execution log/trajectory.
+ github_url: Full URL to GitHub repository (e.g., https://github.com/owner/repo).
output_dir: Directory where new skills will be saved.
model: The LLM model to use.
+ max_files: Maximum number of Python files to analyze (GitHub mode only).
Returns:
List[str]: A list of paths to the generated skill folders.
+
+ Note:
+ Provide either trajectory_content OR github_url, not both.
"""
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.")
+ if trajectory_content and github_url:
+ raise SkillNetError("Provide either trajectory_content OR github_url, not both.")
+
+ if not trajectory_content and not github_url:
+ raise SkillNetError("Must provide trajectory_content or github_url.")
try:
creator = SkillCreator(
@@ -143,58 +153,23 @@ class SkillNetClient:
model=model
)
- created_paths = creator.create_from_trajectory(
- trajectory=trajectory_content,
- output_dir=str(output_dir)
- )
+ if github_url:
+ created_paths = creator.create_from_github(
+ github_url=github_url,
+ output_dir=str(output_dir),
+ api_token=self.github_token,
+ max_files=max_files
+ )
+ else:
+ 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 create_from_github(
- self,
- github_url: str,
- output_dir: Union[str, Path] = "./generated_skills",
- model: str = "gpt-4o",
- max_files: int = 20
- ) -> List[str]:
- """
- Generate a skill package from a GitHub repository.
-
- Args:
- github_url: Full URL to GitHub repository (e.g., https://github.com/owner/repo).
- output_dir: Directory where new skills will be saved.
- model: The LLM model to use.
- max_files: Maximum number of Python files to analyze for code signatures.
-
- 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 from GitHub.")
-
- if not github_url or not github_url.strip():
- raise SkillNetError("GitHub URL is empty.")
-
- try:
- creator = SkillCreator(
- api_key=self.api_key,
- base_url=self.base_url,
- model=model
- )
-
- created_paths = creator.create_from_github(
- github_url=github_url,
- output_dir=str(output_dir),
- api_token=self.github_token,
- max_files=max_files
- )
-
- return created_paths if created_paths else []
- except Exception as e:
- raise SkillNetError(f"GitHub skill creation failed: {str(e)}") from e
-
def evaluate(
self,
target: str,
diff --git a/skillnet-ai/src/skillnet_ai/creator.py b/skillnet-ai/src/skillnet_ai/creator.py
index d280637..3a759c8 100644
--- a/skillnet-ai/src/skillnet_ai/creator.py
+++ b/skillnet-ai/src/skillnet_ai/creator.py
@@ -304,7 +304,7 @@ class SkillCreator:
for attempt in range(max_retries + 1):
try:
# Use higher max_tokens for complete response
- response = self._get_llm_response(messages, max_tokens=8192)
+ response = self._get_llm_response(messages, max_tokens=16384)
# Validate response has required content
if self._validate_skill_content(response):