Create, Evaluate, and Connect AI Skills
Python ai-agentsai-skillsartificial-intelligenceknowledge-graphlarge-language-modelsnatural-language-processingopenkgskillnetskills
update creator
Jiang Chenc1ff8ed362b0
diff --git a/skillnet-ai/examples/create_example.py b/skillnet-ai/examples/create_example.pyindex d834c66..17d0d51 100644--- a/skillnet-ai/examples/create_example.py+++ b/skillnet-ai/examples/create_example.py@@ -2,10 +2,9 @@ import osimport loggingfrom skillnet_ai import SkillCreator-# Setup logginglogging.basicConfig(level=logging.INFO)-# Dummy trajectory data for demonstration+# Sample trajectory for demonstrationSAMPLE_TRAJECTORY = """User: Please analyze this invoice.pdf and extract the total amount and date.Agent: I will use the PDF tool. Opening invoice.pdf...@@ -13,31 +12,71 @@ Agent: Text extracted. Found 'Total: $500' and 'Date: 2023-10-12'.Agent: The total is $500 and the date is Oct 12, 2023."""-def main():- # Ensure you have API_KEY set in your environment++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 to run this demo.")+ print("Please set API_KEY environment variable.")return- base_url = os.getenv("BASE_URL") or "https://api.openai.com/v1" # Optional, custom base URL or default-++ 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("π Starting skill creation from trajectory...")+ print("π Creating skill from trajectory...")try:- # Create skills into the ./created_skills folderpaths = creator.create_from_trajectory(trajectory=SAMPLE_TRAJECTORY,output_dir="./created_skills")-print("\nβ¨ Creation Complete!")for p in paths:- print(f" - Created Skill at: {p}")-+ print(f" - Created: {p}")except Exception as e:- print(f"β Error during creation: {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}")+++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")+if __name__ == "__main__":main()\ No newline at end of filediff --git a/skillnet-ai/src/skillnet_ai/cli.py b/skillnet-ai/src/skillnet_ai/cli.pyindex b55cb47..83b0d89 100644--- a/skillnet-ai/src/skillnet_ai/cli.py+++ b/skillnet-ai/src/skillnet_ai/cli.py@@ -148,12 +148,18 @@ def download(@app.command()def create(- trajectory_file: Path = typer.Argument(..., exists=True, readable=True, help="Path to the text file containing the execution trajectory/logs."),+ trajectory_file: Path = typer.Argument(None, exists=True, readable=True, help="Path to the text file containing the execution trajectory/logs. Not required if using --github."),output_dir: Path = typer.Option(Path("./generated_skills"), help="Directory where the new skills will be saved."),model: str = typer.Option("gpt-4o", help="The LLM model to use (e.g., gpt-4o, gpt-3.5-turbo)."),+ github: str = typer.Option(None, "--github", "-g", help="GitHub repository URL to create skill from (e.g., https://github.com/owner/repo)."),+ max_files: int = typer.Option(20, "--max-files", help="Maximum Python files to analyze when using --github."),):"""- Analyze a trajectory log and generate executable Skill packages using AI.+ Create executable Skill packages using AI.++ Supports two modes:+ - From trajectory: skillnet create trajectory.txt+ - From GitHub: skillnet create --github https://github.com/owner/repo"""# 1. Validate Environmentif not API_KEY:@@ -161,8 +167,25 @@ def create(console.print("Please export API_KEY or set it in your environment.")raise typer.Exit(code=1)+ # 2. Determine mode: GitHub or Trajectory+ if github:+ # GitHub mode+ _create_from_github(github, output_dir, model, max_files)+ elif trajectory_file:+ # Trajectory mode+ _create_from_trajectory(trajectory_file, output_dir, model)+ else:+ console.print("[bold red]Error:[/bold red] Either provide a trajectory file or use --github option.")+ console.print("\nUsage examples:")+ console.print(" skillnet create trajectory.txt")+ console.print(" skillnet create --github https://github.com/owner/repo")+ raise typer.Exit(code=1)+++def _create_from_trajectory(trajectory_file: Path, output_dir: Path, model: str):+ """Internal function to create skill from trajectory file."""try:- # 2. Read Trajectory Content+ # Read Trajectory Contentconsole.print(f"[dim]Reading trajectory from: {trajectory_file}[/dim]")with open(trajectory_file, "r", encoding="utf-8") as f:trajectory_content = f.read()@@ -171,22 +194,21 @@ def create(console.print("[bold red]Error:[/bold red] Trajectory file is empty.")raise typer.Exit(code=1)- # 3. Initialize Creator+ # Initialize Creatorcreator = SkillCreator(api_key=API_KEY,base_url=BASE_URL,model=model)- # 4. Run Generation with Spinner- # The creation process involves multiple LLM calls, so it may take time.+ # Run Generation with Spinnerwith console.status("[bold green]AI is analyzing trajectory and generating skills...[/bold green]", spinner="dots"):created_paths = creator.create_from_trajectory(trajectory=trajectory_content,output_dir=str(output_dir))- # 5. Report Results+ # Report Resultsif created_paths:console.print(f"\n[bold green]Success! Generated {len(created_paths)} skill(s):[/bold green]")@@ -195,7 +217,6 @@ def create(table.add_column("Location", style="white")for path in created_paths:- # Assuming path ends with the skill nameskill_name = os.path.basename(path)table.add_row(skill_name, str(path))@@ -206,10 +227,53 @@ def create(except Exception as e:console.print(f"\n[bold red]Creation Failed:[/bold red] {str(e)}")- # Optional: Print traceback if in debug mode- # console.print_exception()raise typer.Exit(code=1)++def _create_from_github(github_url: str, output_dir: Path, model: str, max_files: int):+ """Internal function to create skill from GitHub repository."""+ try:+ console.print(f"[dim]Creating skill from GitHub: {github_url}[/dim]")++ # Initialize Creator+ creator = SkillCreator(+ api_key=API_KEY,+ base_url=BASE_URL,+ model=model+ )++ # Run Generation with Spinner+ with console.status("[bold green]Fetching repository and generating skill...[/bold green]", spinner="dots"):+ created_paths = creator.create_from_github(+ github_url=github_url,+ output_dir=str(output_dir),+ api_token=os.getenv("GITHUB_TOKEN"),+ max_files=max_files+ )++ # Report Results+ if created_paths:+ console.print(f"\n[bold green]Success! Generated {len(created_paths)} skill(s) from GitHub:[/bold green]")++ table = Table(show_header=True, header_style="bold magenta")+ table.add_column("Skill Name", style="cyan")+ table.add_column("Location", style="white")++ for path in created_paths:+ skill_name = os.path.basename(path)+ table.add_row(skill_name, str(path))++ console.print(table)+ console.print(f"\n[dim]Files saved to: {os.path.abspath(output_dir)}[/dim]")+ console.print("\n[dim]Tip: Use 'skillnet evaluate <skill_path>' to evaluate the generated skill.[/dim]")+ else:+ console.print("\n[yellow]Failed to generate skill from the GitHub repository.[/yellow]")++ except Exception as e:+ console.print(f"\n[bold red]GitHub Skill Creation Failed:[/bold red] {str(e)}")+ raise typer.Exit(code=1)++@app.command()def evaluate(target: str = typer.Argument(..., help="Path to a local skill directory OR a GitHub URL."),diff --git a/skillnet-ai/src/skillnet_ai/client.py b/skillnet-ai/src/skillnet_ai/client.pyindex 423b458..39968bd 100644--- a/skillnet-ai/src/skillnet_ai/client.py+++ b/skillnet-ai/src/skillnet_ai/client.py@@ -152,6 +152,49 @@ class SkillNetClient: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.pyindex 8f1c551..d280637 100644--- a/skillnet-ai/src/skillnet_ai/creator.py+++ b/skillnet-ai/src/skillnet_ai/creator.py@@ -1,14 +1,19 @@import osimport jsonimport re+import astimport logging-from typing import List, Optional+from typing import List, Optional, Dict, Any++import requestsfrom openai import OpenAIfrom skillnet_ai.prompts import (CANDIDATE_METADATA_SYSTEM_PROMPT,CANDIDATE_METADATA_USER_PROMPT_TEMPLATE,SKILL_CONTENT_SYSTEM_PROMPT,- SKILL_CONTENT_USER_PROMPT_TEMPLATE+ SKILL_CONTENT_USER_PROMPT_TEMPLATE,+ GITHUB_SKILL_SYSTEM_PROMPT,+ GITHUB_SKILL_USER_PROMPT_TEMPLATE)logger = logging.getLogger(__name__)@@ -28,12 +33,13 @@ class SkillCreator:self.client = OpenAI(api_key=self.api_key, base_url=self.base_url)- def _get_llm_response(self, messages: List[dict]) -> str:+ def _get_llm_response(self, messages: List[dict], max_tokens: int = 4096) -> str:"""Helper to call LLM and get string content."""try:response = self.client.chat.completions.create(model=self.model,- messages=messages+ messages=messages,+ max_tokens=max_tokens)return response.choices[0].message.contentexcept Exception as e:@@ -106,15 +112,17 @@ class SkillCreator:logger.error(f"Failed to parse metadata JSON: {e}")return []- def _save_skill_files(self, llm_output: str, output_base_dir: str):+ def _save_skill_files(self, llm_output: str, output_base_dir: str) -> List[str]:"""Parse the FILE blocks and write them to disk."""# Regex to find: ## FILE: path \n ```lang \n content \n ```pattern = re.compile(r'##\s*FILE:\s*(.+?)\s*\n```(?:\w*)\n(.*?)```', re.DOTALL)matches = pattern.findall(llm_output)+ created_files = []+if not matches:logger.warning("No file blocks found in LLM output.")- return+ return created_filesfor file_path, content in matches:file_path = file_path.strip()@@ -127,5 +135,611 @@ class SkillCreator:with open(full_path, 'w', encoding='utf-8') as f:f.write(content)logger.info(f"Saved: {full_path}")+ created_files.append(full_path)+ except IOError as e:+ logger.error(f"Failed to write {full_path}: {e}")++ return created_files++ def create_from_github(+ self,+ github_url: str,+ output_dir: str = "./generated_skills",+ api_token: Optional[str] = None,+ max_files: int = 20+ ) -> List[str]:+ """Create a skill package from a GitHub repository."""+ logger.info(f"Creating skill from GitHub: {github_url}")++ try:++ fetcher = _GitHubFetcher(api_token=api_token)+ owner, repo, branch, _ = fetcher.parse_github_url(github_url)+ logger.info(f"Parsed: {owner}/{repo} @ {branch}")++ # Fetch repository data+ repo_data = self._fetch_github_repo_data(fetcher, owner, repo, branch, max_files)++ if not repo_data:+ logger.error("Failed to fetch repository data")+ return []++ # Generate skill content+ skill_content = self._generate_github_skill_content(repo_data)+ if not skill_content:+ logger.error("Failed to generate skill content")+ return []++ # Save skill package+ skill_name = repo_data["metadata"]["name"].lower().replace(" ", "-").replace("_", "-")+ created_files = self._save_github_skill_files(skill_content, output_dir)++ # Extract unique skill directories from created files+ skill_dirs = set()+ for file_path in created_files:+ rel_path = os.path.relpath(file_path, output_dir)+ skill_dir = rel_path.split(os.sep)[0]+ skill_dirs.add(os.path.join(output_dir, skill_dir))++ logger.info(f"Skill created successfully from GitHub: {github_url}")+ return list(skill_dirs) if skill_dirs else [os.path.join(output_dir, skill_name)]++ except Exception as e:+ logger.error(f"Failed to create skill from GitHub: {e}")+ return []++ def _fetch_github_repo_data(+ self,+ fetcher: "_GitHubFetcher",+ owner: str,+ repo: str,+ branch: str,+ max_files: int+ ) -> Optional[Dict[str, Any]]:+ """Fetch repository metadata, README, file tree, and code analysis."""+ logger.info("Fetching repository data...")++ metadata = fetcher.fetch_repo_metadata(owner, repo)+ branch = metadata.get("default_branch", branch)+ readme = fetcher.fetch_readme(owner, repo, branch)+ file_tree = fetcher.fetch_file_tree(owner, repo, branch)+ languages = fetcher.fetch_languages(owner, repo)+ code_analysis = self._analyze_github_code_files(+ fetcher, owner, repo, branch, file_tree, max_files+ )++ return {+ "metadata": metadata,+ "readme": readme,+ "file_tree": file_tree,+ "languages": languages,+ "code_analysis": code_analysis,+ "github_url": f"https://github.com/{owner}/{repo}"+ }++ def _analyze_github_code_files(+ self,+ fetcher: "_GitHubFetcher",+ owner: str,+ repo: str,+ branch: str,+ file_tree: List[Dict],+ max_files: int+ ) -> Dict[str, Any]:+ """Analyze Python files to extract class and function signatures."""+ logger.info("Analyzing Python files...")++ # Filter Python files+ py_files = [+ f for f in file_tree+ if f.get("type") == "file" and f.get("path", "").endswith(".py")+ ][:max_files]++ analyzed = []+ for file_info in py_files:+ file_path = file_info.get("path", "")+ content = fetcher.fetch_file_content(owner, repo, file_path, branch)++ if content:+ analysis = _PythonCodeAnalyzer.analyze(content, file_path)+ if analysis.get("classes") or analysis.get("functions"):+ analyzed.append({"file": file_path, **analysis})+ logger.debug(+ f"Analyzed {file_path}: {len(analysis.get('classes', []))} classes, "+ f"{len(analysis.get('functions', []))} functions"+ )++ total_classes = sum(len(f.get("classes", [])) for f in analyzed)+ total_functions = sum(len(f.get("functions", [])) for f in analyzed)++ logger.info(+ f"Code analysis complete: {len(analyzed)} files, "+ f"{total_classes} classes, {total_functions} functions"+ )++ return {+ "files_analyzed": len(analyzed),+ "total_classes": total_classes,+ "total_functions": total_functions,+ "files": analyzed+ }++ def _generate_github_skill_content(+ self,+ repo_data: Dict[str, Any],+ max_retries: int = 2+ ) -> Optional[str]:+ """Generate skill content from repository data using LLM."""+ logger.info("Generating skill content with LLM...")++ metadata = repo_data["metadata"]+ code_summary = self._build_code_summary(repo_data.get("code_analysis", {}))+ file_tree_str = self._format_file_tree(repo_data.get("file_tree", [])[:100])++ languages = repo_data.get("languages", {})+ lang_str = ", ".join([f"{lang}: {pct}%" for lang, pct in languages.items()][:5])++ readme_content = repo_data.get("readme") or "No README available"+ readme_truncated = readme_content[:15000]++ user_prompt = GITHUB_SKILL_USER_PROMPT_TEMPLATE.format(+ repo_name=metadata.get("full_name", metadata.get("name", "unknown")),+ repo_url=repo_data.get("github_url", ""),+ repo_description=metadata.get("description") or "No description available",+ language=metadata.get("language") or "Unknown",+ languages_breakdown=lang_str or "N/A",+ stars=metadata.get("stars", 0),+ topics=", ".join(metadata.get("topics", [])) if metadata.get("topics") else "None",+ readme_content=readme_truncated,+ file_tree=file_tree_str,+ code_summary=code_summary+ )++ messages = [+ {"role": "system", "content": GITHUB_SKILL_SYSTEM_PROMPT},+ {"role": "user", "content": user_prompt}+ ]++ # Retry mechanism with content validation+ for attempt in range(max_retries + 1):+ try:+ # Use higher max_tokens for complete response+ response = self._get_llm_response(messages, max_tokens=8192)++ # Validate response has required content+ if self._validate_skill_content(response):+ return response++ if attempt < max_retries:+ logger.warning(f"Generated content incomplete, retrying ({attempt + 1}/{max_retries})...")+ else:+ logger.warning("Generated content may be incomplete, using best result.")+ return response++ except Exception as e:+ logger.error(f"LLM call failed (attempt {attempt + 1}): {e}")+ if attempt == max_retries:+ return None++ return None++ def _validate_skill_content(self, content: str) -> bool:+ """Check if generated content has required SKILL.md structure."""+ if not content:+ return False++ has_skill_md = "SKILL.md" in content+ has_file_block = "## FILE:" in content+ has_frontmatter = "---" in content and "name:" in content+ min_length = len(content) >= 1000++ return has_skill_md and has_file_block and has_frontmatter and min_length++ def _build_code_summary(self, code_analysis: Dict[str, Any]) -> str:+ """Build code analysis summary for LLM prompt."""+ if not code_analysis or not code_analysis.get("files"):+ return "No Python code analysis available."++ lines = [+ f"Analyzed {code_analysis.get('files_analyzed', 0)} Python files:",+ f"- Total Classes: {code_analysis.get('total_classes', 0)}",+ f"- Total Functions: {code_analysis.get('total_functions', 0)}",+ "",+ "Key components found:"+ ]++ # Add top classes and functions+ for file_data in code_analysis.get("files", [])[:5]:+ file_path = file_data.get("file", "")+ classes = file_data.get("classes", [])+ functions = file_data.get("functions", [])++ for cls in classes[:3]:+ docstring = (cls.get("docstring") or "")[:100]+ lines.append(f"- Class `{cls['name']}` in {file_path}")+ if docstring:+ lines.append(f" {docstring}...")++ for func in functions[:3]:+ params = func.get("parameters", [])[:3]+ sig = f"{func['name']}({', '.join(params)})"+ lines.append(f"- Function `{sig}` in {file_path}")++ return "\n".join(lines[:30])++ def _format_file_tree(self, file_tree: List[Dict]) -> str:+ """Format file tree for LLM prompt."""+ if not file_tree:+ return "No file tree available."++ lines = []+ for item in file_tree[:50]:+ path = item.get("path", "")+ item_type = item.get("type", "file")+ icon = "π" if item_type == "dir" else "π"+ lines.append(f"{icon} {path}")++ if len(file_tree) > 50:+ lines.append(f"... and {len(file_tree) - 50} more files")++ return "\n".join(lines)++ def _save_github_skill_files(self, llm_output: str, output_base_dir: str) -> List[str]:+ """Parse FILE blocks and write to disk, handling nested code blocks."""+ created_files = []+ parts = re.split(r'##\s*FILE:\s*', llm_output)++ if len(parts) < 2:+ logger.warning("No file blocks found in LLM output.")+ return created_files++ for part in parts[1:]:+ lines = part.split('\n', 1)+ if len(lines) < 2:+ continue++ file_path = lines[0].strip()+ rest = lines[1]++ match = re.match(r'```(?:\w*)\n', rest)+ if not match:+ continue++ content_start = match.end()+ content = rest[content_start:]++ # Find closing ``` by tracking nested code blocks+ in_nested_block = False+ end_pos = -1+ i = 0++ while i < len(content):+ # Check for ``` at start of line+ if content[i:i+3] == '```' and (i == 0 or content[i-1] == '\n'):+ if not in_nested_block:+ after = content[i+3:i+50].split('\n')[0].strip()+ if after == '':+ end_pos = i+ break+ else:+ in_nested_block = True+ else:+ in_nested_block = False+ i += 1++ if end_pos == -1:+ end_pos = content.rfind('\n```')+ if end_pos == -1:+ end_pos = len(content)++ file_content = content[:end_pos]+ full_path = os.path.join(output_base_dir, file_path.strip())++ os.makedirs(os.path.dirname(full_path), exist_ok=True)++ try:+ with open(full_path, 'w', encoding='utf-8') as f:+ f.write(file_content)+ logger.info(f"Saved: {full_path}")+ created_files.append(full_path)except IOError as e:- logger.error(f"Failed to write {full_path}: {e}")\ No newline at end of file+ logger.error(f"Failed to write {full_path}: {e}")++ return created_files+++class _GitHubFetcher:+ """Fetches content from GitHub repositories via API."""++ EXCLUDED_DIRS = {+ "node_modules", "__pycache__", ".git", ".venv", "venv",+ "env", ".env", "build", "dist", ".pytest_cache",+ ".mypy_cache", "htmlcov", ".tox", ".eggs"+ }++ def __init__(self, api_token: Optional[str] = None):+ self.api_token = api_token or os.getenv("GITHUB_TOKEN")+ self.session = requests.Session()+ self.session.headers.update({+ "Accept": "application/vnd.github.v3+json",+ "User-Agent": "SkillNet-AI/1.0"+ })+ if self.api_token:+ self.session.headers.update({"Authorization": f"token {self.api_token}"})++ def _request_with_retry(+ self,+ url: str,+ timeout: int = 10,+ max_retries: int = 3,+ base_delay: float = 1.0+ ) -> Optional[requests.Response]:+ """HTTP GET with exponential backoff and rate limit handling."""+ import time++ for attempt in range(1, max_retries + 1):+ try:+ response = self.session.get(url, timeout=timeout)++ if response.status_code == 403:+ remaining = response.headers.get("X-RateLimit-Remaining", "?")+ if remaining == "0":+ reset_time = int(response.headers.get("X-RateLimit-Reset", 0))+ wait_seconds = max(0, reset_time - int(time.time()))+ logger.warning(f"GitHub rate limit exceeded. Resets in {wait_seconds}s")+ if wait_seconds < 60:+ time.sleep(wait_seconds + 1)+ continue++ return response++ except requests.exceptions.Timeout:+ if attempt < max_retries:+ delay = base_delay * (2 ** (attempt - 1))+ logger.warning(f"Timeout (attempt {attempt}/{max_retries}), retry in {delay:.1f}s")+ time.sleep(delay)+ else:+ logger.error(f"Request failed after {max_retries} attempts: {url}")+ return None++ except requests.exceptions.ConnectionError:+ if attempt < max_retries:+ delay = base_delay * (2 ** (attempt - 1))+ logger.warning(f"Connection error (attempt {attempt}/{max_retries}), retry in {delay:.1f}s")+ time.sleep(delay)+ else:+ logger.error(f"Connection failed after {max_retries} attempts: {url}")+ return None++ except requests.exceptions.RequestException as e:+ logger.error(f"Request failed: {e}")+ return None++ return None++ def parse_github_url(self, url: str) -> tuple:+ """Parse GitHub URL to extract owner, repo, branch, and optional path."""+ url = url.rstrip("/")+ if url.endswith(".git"):+ url = url[:-4]++ if "github.com/" in url:+ parts = url.split("github.com/")[-1].split("/")+ if len(parts) < 2:+ raise ValueError(f"Invalid GitHub URL format: {url}")++ owner, repo = parts[0], parts[1]+ branch = "main"+ path = ""++ if len(parts) > 3 and parts[2] in ("tree", "blob"):+ branch = parts[3]+ path = "/".join(parts[4:]) if len(parts) > 4 else ""++ return owner, repo, branch, path++ raise ValueError(f"Invalid GitHub URL: {url}")++ def fetch_repo_metadata(self, owner: str, repo: str) -> Dict[str, Any]:+ """Fetch repository metadata from GitHub API."""+ url = f"https://api.github.com/repos/{owner}/{repo}"++ response = self._request_with_retry(url, timeout=10)+ if response is None:+ logger.warning("Failed to fetch repo metadata: request failed")+ return {"name": repo, "full_name": f"{owner}/{repo}"}++ try:+ response.raise_for_status()+ data = response.json()++ return {+ "name": data.get("name", repo),+ "full_name": data.get("full_name", f"{owner}/{repo}"),+ "description": data.get("description"),+ "url": data.get("html_url"),+ "homepage": data.get("homepage"),+ "stars": data.get("stargazers_count", 0),+ "forks": data.get("forks_count", 0),+ "language": data.get("language"),+ "topics": data.get("topics", []),+ "license_name": data.get("license", {}).get("name") if data.get("license") else None,+ "default_branch": data.get("default_branch", "main")+ }+ except requests.RequestException as e:+ logger.warning(f"Failed to fetch repo metadata: {e}")+ return {"name": repo, "full_name": f"{owner}/{repo}"}++ def fetch_readme(self, owner: str, repo: str, branch: str = "main") -> Optional[str]:+ """Fetch README content from repository."""+ readme_names = ["README.md", "README.rst", "README.txt", "README"]++ for readme_name in readme_names:+ url = f"https://raw.githubusercontent.com/{owner}/{repo}/{branch}/{readme_name}"+ response = self._request_with_retry(url, timeout=10)+ if response and response.status_code == 200:+ logger.info(f"Found README: {readme_name}")+ return response.text++ logger.warning("No README found in repository")+ return None++ def fetch_file_tree(self, owner: str, repo: str, branch: str = "main") -> List[Dict]:+ """Fetch repository file tree structure."""+ url = f"https://api.github.com/repos/{owner}/{repo}/git/trees/{branch}?recursive=1"++ response = self._request_with_retry(url, timeout=15)+ if response is None:+ logger.warning("Failed to fetch file tree: request failed")+ return []++ try:+ response.raise_for_status()+ data = response.json()++ file_tree = []+ for item in data.get("tree", []):+ path = item.get("path", "")++ # Skip excluded directories+ if any(excluded in path for excluded in self.EXCLUDED_DIRS):+ continue++ file_tree.append({+ "path": path,+ "type": "dir" if item.get("type") == "tree" else "file",+ "size": item.get("size")+ })++ logger.info(f"Fetched file tree: {len(file_tree)} items")+ return file_tree++ except requests.RequestException as e:+ logger.warning(f"Failed to fetch file tree: {e}")+ return []++ def fetch_languages(self, owner: str, repo: str) -> Dict[str, float]:+ """Fetch language breakdown from GitHub API."""+ url = f"https://api.github.com/repos/{owner}/{repo}/languages"++ response = self._request_with_retry(url, timeout=10)+ if response is None:+ logger.warning("Failed to fetch languages: request failed")+ return {}++ try:+ response.raise_for_status()+ data = response.json()++ if not data:+ return {}++ total_bytes = sum(data.values())+ return {+ lang: round((bytes_count / total_bytes) * 100, 2)+ for lang, bytes_count in data.items()+ }++ except requests.RequestException as e:+ logger.warning(f"Failed to fetch languages: {e}")+ return {}++ def fetch_file_content(+ self, owner: str, repo: str, file_path: str, branch: str = "main"+ ) -> Optional[str]:+ """Fetch content of a specific file."""+ url = f"https://raw.githubusercontent.com/{owner}/{repo}/{branch}/{file_path}"++ response = self._request_with_retry(url, timeout=10, max_retries=2)+ if response and response.status_code == 200:+ return response.text++ return None+++class _PythonCodeAnalyzer:+ """Internal class for analyzing Python code using AST."""++ @staticmethod+ def analyze(content: str, file_path: str) -> Dict[str, Any]:+ """Analyze Python file to extract classes and functions."""+ try:+ tree = ast.parse(content)+ except SyntaxError as e:+ logger.debug(f"Syntax error in {file_path}: {e}")+ return {"classes": [], "functions": []}++ classes = []+ functions = []++ for node in ast.iter_child_nodes(tree):+ if isinstance(node, ast.ClassDef):+ classes.append(_PythonCodeAnalyzer._extract_class(node))+ elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):+ functions.append(_PythonCodeAnalyzer._extract_function(node))++ return {"classes": classes, "functions": functions}++ @staticmethod+ def _extract_class(node: ast.ClassDef) -> Dict[str, Any]:+ """Extract class signature from AST node."""+ base_classes = []+ for base in node.bases:+ if isinstance(base, ast.Name):+ base_classes.append(base.id)+ elif isinstance(base, ast.Attribute):+ if isinstance(base.value, ast.Name):+ base_classes.append(f"{base.value.id}.{base.attr}")+ else:+ base_classes.append(base.attr)++ methods = []+ for item in node.body:+ if isinstance(item, (ast.FunctionDef, ast.AsyncFunctionDef)):+ methods.append(_PythonCodeAnalyzer._extract_function(item))++ docstring = ast.get_docstring(node)+ return {+ "name": node.name,+ "base_classes": base_classes,+ "docstring": docstring[:200] if docstring else None,+ "methods": methods+ }++ @staticmethod+ def _extract_function(node) -> Dict[str, Any]:+ """Extract function signature from AST node."""+ params = []+ for arg in node.args.args:+ param_name = arg.arg+ if arg.annotation:+ try:+ param_name += f": {ast.unparse(arg.annotation)}"+ except Exception:+ pass+ params.append(param_name)++ return_type = None+ if node.returns:+ try:+ return_type = ast.unparse(node.returns)+ except Exception:+ pass++ decorators = []+ for decorator in node.decorator_list:+ try:+ decorators.append(ast.unparse(decorator))+ except Exception:+ if isinstance(decorator, ast.Name):+ decorators.append(decorator.id)++ docstring = ast.get_docstring(node)+ return {+ "name": node.name,+ "parameters": params,+ "return_type": return_type,+ "docstring": docstring[:200] if docstring else None,+ "is_async": isinstance(node, ast.AsyncFunctionDef),+ "decorators": decorators+ }\ No newline at end of filediff --git a/skillnet-ai/src/skillnet_ai/prompts.py b/skillnet-ai/src/skillnet_ai/prompts.pyindex 2297b49..6b3e6da 100644--- a/skillnet-ai/src/skillnet_ai/prompts.py+++ b/skillnet-ai/src/skillnet_ai/prompts.py@@ -239,4 +239,274 @@ Return the evaluation results in JSON format exactly like this:}}}}-Remember: STRICT JSON only."""\ No newline at end of file+Remember: STRICT JSON only."""+++# GitHub Repository to Skill Prompts++GITHUB_SKILL_SYSTEM_PROMPT = """You are an expert Technical Writer specializing in creating Skills for AI agents.+Your task is to analyze a GitHub repository and generate a comprehensive skill package that captures the repository's functionality and usage patterns.++CRITICAL REQUIREMENTS:+1. Generate COMPLETE content - do not truncate or abbreviate sections+2. Include ALL installation steps with actual commands from README+3. Extract CONCRETE code examples from README - copy them exactly, don't invent new ones+4. List specific models, APIs, or tools mentioned in the repository+5. For scripts/: Generate REAL, RUNNABLE Python code that demonstrates library usage+6. For references/: Generate DETAILED API documentation with actual function signatures+7. Follow the SkillNet skill structure standard exactly+8. Output files in parseable format with ## FILE: markers++SCRIPT QUALITY REQUIREMENTS:+- Scripts must be self-contained and runnable (no os.system('conda activate'))+- Scripts should demonstrate actual library API usage, not shell command wrappers+- Include proper imports, error handling, and docstrings+- If the library requires specific data, use placeholder paths with clear comments++REFERENCE QUALITY REQUIREMENTS:+- API references must include actual function signatures from code analysis+- Include parameter types, return types, and brief descriptions+- Organize by module/class hierarchy+- Reference the source file locations++Your output will be parsed by a script, so maintain strict formatting."""++GITHUB_SKILL_USER_PROMPT_TEMPLATE = """+Your task is to generate a complete skill package from the provided GitHub repository information.+This includes the main `SKILL.md` orchestration file and any necessary bundled resources.++# Input Data: GitHub Repository++## Repository Info+- **Name:** {repo_name}+- **URL:** {repo_url}+- **Description:** {repo_description}+- **Primary Language:** {language}+- **Languages Breakdown:** {languages_breakdown}+- **Stars:** {stars}+- **Topics:** {topics}++## README Content+{readme_content}++## File Structure+{file_tree}++## Code Analysis Summary+{code_summary}++# Skill Structure Standard+You must output the skill using the following directory structure:++```text+skill-name/+βββ SKILL.md (required)+β βββ YAML frontmatter metadata (required)+β β βββ name: (required)+β β βββ description: (required)+β βββ Markdown instructions (required)+βββ Bundled Resources (required)+ βββ scripts/ - Executable Python code demonstrating library usage+ βββ references/ - API documentation with function signatures+```++# SKILL.md Content Requirements (MUST INCLUDE ALL)++## 1. YAML Frontmatter (REQUIRED)+```yaml+---+name: skill-name-in-kebab-case+description: A when-to-use trigger statement explaining when this skill should be activated+---+```++## 2. When to Use Section (REQUIRED)+Clear description of scenarios where this skill should be activated. Include:+- Primary use cases+- Types of tasks it handles+- Keywords that should trigger this skill++## 3. Quick Reference Section (REQUIRED)+- Official documentation links+- Demo/playground URLs if available+- Key resources and references++## 4. Installation/Setup Section (REQUIRED - WITH ACTUAL COMMANDS)+Include complete installation commands exactly as shown in README:+- Prerequisites (Python version, system requirements)+- pip install commands+- Docker commands if available+- Environment setup steps++## 5. Core Features Section (REQUIRED)+List the main features/capabilities:+- Feature 1: Description+- Feature 2: Description+- Include any sub-modules or specialized tools++## 6. Usage Examples Section (REQUIRED - EXTRACT FROM README)+Include ACTUAL code examples from the README:+- Quick start code+- Common usage patterns+- Command-line examples++## 7. Key APIs/Models Section (REQUIRED)+List specific models, classes, or APIs mentioned:+- Model names (e.g., specific neural network architectures)+- API endpoints or function signatures+- Configuration options++## 8. Common Patterns & Best Practices (OPTIONAL)+Tips for effective usage++# scripts/ File Requirements (CRITICAL - HIGH QUALITY)++Generate Python scripts that ACTUALLY demonstrate how to use the library's API.++GOOD SCRIPT EXAMPLE (demonstrates actual API usage):+```python+#!/usr/bin/env python3+\"\"\"+Example: Named Entity Recognition with DeepKE++This script demonstrates how to use DeepKE's NER module for entity extraction.+Requires: pip install deepke torch transformers+\"\"\"++from typing import List, Dict++# NOTE: Adjust import based on actual DeepKE installation+try:+ from deepke.name_entity_re.standard import NERPredictor+except ImportError:+ print("Please install DeepKE: pip install deepke")+ exit(1)+++def extract_entities(text: str, model_path: str = None) -> List[Dict]:+ \"\"\"+ Extract named entities from text using DeepKE.++ Args:+ text: Input text to analyze+ model_path: Path to trained model (optional, uses default if None)++ Returns:+ List of entities with type, text, and position+ \"\"\"+ # Initialize predictor+ predictor = NERPredictor(model_path=model_path)++ # Run prediction+ entities = predictor.predict(text)++ return entities+++if __name__ == "__main__":+ # Example usage+ sample_text = "Barack Obama was born in Honolulu and served as the 44th president."++ print(f"Input: {{sample_text}}")+ print("\\nExtracting entities...")++ results = extract_entities(sample_text)++ for entity in results:+ print(f" - {{entity['text']}} ({{entity['type']}})")+```++BAD SCRIPT EXAMPLE (DO NOT generate this style):+```python+# BAD - This is just shell command wrapper, NOT useful+import os+os.system('conda activate deepke') # Won't work in script context+os.system('python run.py') # No actual API demonstration+```++# references/ File Requirements (CRITICAL - HIGH QUALITY)++Generate detailed API documentation based on the code analysis provided.++GOOD API REFERENCE EXAMPLE:+```markdown+# DeepKE API Reference++## Module: deepke.name_entity_re.standard++### Class: NERPredictor++Entity recognition predictor using pretrained models.++**Constructor:**+```python+NERPredictor(+ model_path: str = None,+ device: str = "cuda" if torch.cuda.is_available() else "cpu",+ max_seq_length: int = 128+)+```++**Parameters:**+- `model_path` (str, optional): Path to trained model checkpoint. Uses default pretrained model if None.+- `device` (str): Device to run inference on. Defaults to CUDA if available.+- `max_seq_length` (int): Maximum sequence length for tokenization.++**Methods:**++#### predict(text: str) -> List[Dict]+Run NER prediction on input text.++**Parameters:**+- `text` (str): Input text to analyze++**Returns:**+- List of dictionaries containing:+ - `text` (str): The entity text+ - `type` (str): Entity type (PERSON, LOCATION, ORG, etc.)+ - `start` (int): Start character position+ - `end` (int): End character position++**Example:**+```python+predictor = NERPredictor()+entities = predictor.predict("Apple was founded by Steve Jobs.")+# Returns: [{{'text': 'Apple', 'type': 'ORG', ...}}, {{'text': 'Steve Jobs', 'type': 'PERSON', ...}}]+```++---++## Module: deepke.relation_extraction.standard++### Class: REPredictor+...+```++BAD API REFERENCE EXAMPLE (DO NOT generate this style):+```markdown+# API Reference+- Tokenizer: does tokenization+- Encoder: encodes things+- train(): trains the model+```++# Output Format (STRICT)+You must output the files using the following strict format so that a script can parse and save them.+For every file, use this exact pattern:++## FILE: <skill-name>/<path_to_file>+```<language_tag>+<file_content_here>+```++IMPORTANT:+- Generate COMPLETE files, do not use "..." or "[content continues]"+- SKILL.md should be comprehensive (at least 100+ lines)+- scripts/: At least one RUNNABLE Python script with actual library API usage+- references/: At least one DETAILED API reference with function signatures++Now, generate the complete skill package based on the provided GitHub repository information.+Focus on creating a practical, comprehensive skill that an AI agent can use to work with this repository.+DO NOT truncate content - include all relevant information from the README.+SCRIPTS must demonstrate actual Python API usage, not shell command wrappers.+REFERENCES must include actual function signatures and parameters."""\ No newline at end of file