Text Generation
Transformers
English
qwen2
code-generation
python
fine-tuning
Qwen
tools
agent-framework
multi-agent
conversational
Eval Results (legacy)
Instructions to use my-ai-stack/Stack-2-9-finetuned with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use my-ai-stack/Stack-2-9-finetuned with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="my-ai-stack/Stack-2-9-finetuned") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("my-ai-stack/Stack-2-9-finetuned") model = AutoModelForCausalLM.from_pretrained("my-ai-stack/Stack-2-9-finetuned") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use my-ai-stack/Stack-2-9-finetuned with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "my-ai-stack/Stack-2-9-finetuned" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "my-ai-stack/Stack-2-9-finetuned", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/my-ai-stack/Stack-2-9-finetuned
- SGLang
How to use my-ai-stack/Stack-2-9-finetuned with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "my-ai-stack/Stack-2-9-finetuned" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "my-ai-stack/Stack-2-9-finetuned", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "my-ai-stack/Stack-2-9-finetuned" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "my-ai-stack/Stack-2-9-finetuned", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use my-ai-stack/Stack-2-9-finetuned with Docker Model Runner:
docker model run hf.co/my-ai-stack/Stack-2-9-finetuned
| """GlobTool - File pattern matching for Stack 2.9""" | |
| import fnmatch | |
| import os | |
| import re | |
| from pathlib import Path | |
| from typing import Any, Dict, List, Optional | |
| from .base import BaseTool, ToolResult | |
| from .registry import tool_registry | |
| # Default exclusions | |
| DEFAULT_EXCLUDES = { | |
| '.git', '.svn', '.hg', '__pycache__', 'node_modules', '.venv', 'venv', | |
| 'env', '.idea', '.vscode', '.DS_Store', '*.pyc', '*.pyo', '*.so', | |
| '*.dylib', '.cache', '.pytest_cache', '.mypy_cache', 'dist', 'build', | |
| '*.egg-info', '.tox', '.nox' | |
| } | |
| def _should_exclude(path: Path, exclude_patterns: List[str]) -> bool: | |
| """Check if path should be excluded.""" | |
| name = path.name | |
| # Check default exclusions | |
| if name in DEFAULT_EXCLUDES: | |
| return True | |
| # Check custom patterns | |
| for pattern in exclude_patterns: | |
| if fnmatch.fnmatch(name, pattern) or fnmatch.fnmatch(str(path), pattern): | |
| return True | |
| return False | |
| def _glob_pattern_to_regex(pattern: str) -> str: | |
| """Convert glob pattern to regex.""" | |
| # Handle ** for recursive matching | |
| regex_parts = [] | |
| i = 0 | |
| while i < len(pattern): | |
| c = pattern[i] | |
| if c == '*': | |
| if i + 1 < len(pattern) and pattern[i + 1] == '*': | |
| # ** matches everything including / | |
| regex_parts.append('.*') | |
| i += 2 | |
| else: | |
| # * matches everything except / | |
| regex_parts.append('[^/]*') | |
| i += 1 | |
| elif c == '?': | |
| regex_parts.append('.') | |
| i += 1 | |
| elif c == '[': | |
| # Character class | |
| j = i + 1 | |
| if j < len(pattern) and pattern[j] == '!': | |
| regex_parts.append('[^') | |
| j += 1 | |
| else: | |
| regex_parts.append('[') | |
| while j < len(pattern) and pattern[j] != ']': | |
| regex_parts.append(re.escape(pattern[j])) | |
| j += 1 | |
| regex_parts.append(']') | |
| i = j + 1 | |
| else: | |
| regex_parts.append(re.escape(c)) | |
| i += 1 | |
| return ''.join(regex_parts) | |
| def _match_glob(path: Path, pattern: str) -> bool: | |
| """Check if path matches glob pattern.""" | |
| import re | |
| # Normalize pattern - handle **/*.py style patterns | |
| if pattern.startswith('**/'): | |
| # Recursive pattern | |
| regex_pattern = _glob_pattern_to_regex(pattern) | |
| regex = re.compile(regex_pattern) | |
| return bool(regex.match(str(path))) or bool(regex.match(path.name)) | |
| elif '**' in pattern: | |
| regex_pattern = _glob_pattern_to_regex(pattern) | |
| regex = re.compile(regex_pattern) | |
| return bool(regex.match(str(path))) | |
| else: | |
| # Simple pattern | |
| return fnmatch.fnmatch(path.name, pattern) or fnmatch.fnmatch(str(path), pattern) | |
| class GlobTool(BaseTool): | |
| """Find files matching glob patterns.""" | |
| name = "glob" | |
| description = "Find files matching glob patterns" | |
| input_schema = { | |
| "type": "object", | |
| "properties": { | |
| "pattern": {"type": "string", "description": "Glob pattern (e.g., **/*.py, *.js)"}, | |
| "base_path": {"type": "string", "description": "Base directory to search"}, | |
| "exclude": {"type": "array", "items": {"type": "string"}, "description": "Patterns to exclude"}, | |
| "max_results": {"type": "number", "default": 1000, "description": "Maximum results"}, | |
| "files_only": {"type": "boolean", "default": True, "description": "Only return files"} | |
| }, | |
| "required": ["pattern"] | |
| } | |
| async def execute(self, pattern: str, base_path: Optional[str] = None, exclude: Optional[List[str]] = None, max_results: int = 1000, files_only: bool = True) -> ToolResult: | |
| """Find files matching pattern.""" | |
| if base_path: | |
| search_path = Path(base_path) | |
| else: | |
| search_path = Path.cwd() | |
| if not search_path.exists(): | |
| return ToolResult(success=False, error=f"Path not found: {search_path}") | |
| exclude_patterns = exclude or [] | |
| matches = [] | |
| visited_dirs = set() | |
| def search_dir(dir_path: Path, depth: int = 0): | |
| """Recursively search directory.""" | |
| if str(dir_path) in visited_dirs: | |
| return | |
| visited_dirs.add(str(dir_path)) | |
| try: | |
| for item in dir_path.iterdir(): | |
| if _should_exclude(item, exclude_patterns): | |
| continue | |
| if item.is_file(): | |
| if _match_glob(item, pattern): | |
| matches.append(str(item)) | |
| if len(matches) >= max_results: | |
| return True | |
| elif item.is_dir(): | |
| # Handle ** pattern | |
| if '**' in pattern: | |
| search_dir(item, depth + 1) | |
| elif depth < 20: # Limit depth for non-** patterns | |
| search_dir(item, depth + 1) | |
| except PermissionError: | |
| pass | |
| return False | |
| search_dir(search_path) | |
| return ToolResult(success=True, data={ | |
| "pattern": pattern, | |
| "base_path": str(search_path), | |
| "matches": matches, | |
| "count": len(matches), | |
| "truncated": len(matches) >= max_results | |
| }) | |
| class GlobListTool(BaseTool): | |
| """List all files in directory with optional filtering.""" | |
| name = "glob_list" | |
| description = "List files in directory with optional pattern filter" | |
| input_schema = { | |
| "type": "object", | |
| "properties": { | |
| "path": {"type": "string", "description": "Directory path"}, | |
| "pattern": {"type": "string", "description": "Optional pattern filter"}, | |
| "recursive": {"type": "boolean", "default": False, "description": "Recursive listing"}, | |
| "max_results": {"type": "number", "default": 500} | |
| }, | |
| "required": ["path"] | |
| } | |
| async def execute(self, path: str, pattern: Optional[str] = None, recursive: bool = False, max_results: int = 500) -> ToolResult: | |
| """List directory contents.""" | |
| dir_path = Path(path) | |
| if not dir_path.exists(): | |
| return ToolResult(success=False, error=f"Path not found: {path}") | |
| matches = [] | |
| def search_dir(d: Path, depth: int = 0): | |
| if len(matches) >= max_results: | |
| return | |
| try: | |
| for item in d.iterdir(): | |
| if item.name.startswith('.'): | |
| continue | |
| if pattern: | |
| if _match_glob(item, pattern): | |
| matches.append(str(item)) | |
| else: | |
| matches.append(str(item)) | |
| if item.is_dir() and recursive and depth < 10: | |
| search_dir(item, depth + 1) | |
| if len(matches) >= max_results: | |
| return | |
| except PermissionError: | |
| pass | |
| search_dir(dir_path) | |
| return ToolResult(success=True, data={ | |
| "path": str(dir_path), | |
| "files": matches, | |
| "count": len(matches) | |
| }) | |
| # Register tools | |
| tool_registry.register(GlobTool()) | |
| tool_registry.register(GlobListTool()) | |