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", device_map="auto") 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 Settings
- 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
| // MCP Client - Model Context Protocol client for Stack 2.9 | |
| // | |
| // Provides MCP server integration for tool extensibility. | |
| // Supports stdio, SSE, and HTTP transports. | |
| export type MCPTransportType = 'stdio' | 'sse' | 'http' | |
| export interface MCPConfig { | |
| name: string | |
| command?: string | |
| args?: string[] | |
| env?: Record<string, string> | |
| url?: string | |
| transport?: MCPTransportType | |
| } | |
| export interface MCPTool { | |
| name: string | |
| description: string | |
| inputSchema: Record<string, unknown> | |
| } | |
| export interface MCPResource { | |
| uri: string | |
| name: string | |
| description?: string | |
| mimeType?: string | |
| } | |
| export interface MCP_SERVER_CONFIG { | |
| name: string | |
| transport: 'stdio' | 'sse' | 'http' | |
| command?: string | |
| args?: string[] | |
| env?: Record<string, string> | |
| url?: string | |
| } | |
| interface MCPRequest { | |
| jsonrpc: '2.0' | |
| id: number | string | |
| method: string | |
| params?: Record<string, unknown> | |
| } | |
| interface MCPResponse { | |
| jsonrpc: '2.0' | |
| id: number | string | |
| result?: unknown | |
| error?: { | |
| code: number | |
| message: string | |
| data?: unknown | |
| } | |
| } | |
| // βββ MCP Client βββ | |
| export class MCPClient { | |
| private config: MCP_SERVER_CONFIG | |
| private requestId = 0 | |
| private pendingRequests: Map<number | string, { | |
| resolve: (value: unknown) => void | |
| reject: (error: Error) => void | |
| }> = new Map() | |
| constructor(config: MCP_SERVER_CONFIG) { | |
| this.config = config | |
| } | |
| get name(): string { | |
| return this.config.name | |
| } | |
| get transport(): string { | |
| return this.config.transport | |
| } | |
| // Send an MCP request and wait for response | |
| async sendRequest(method: string, params?: Record<string, unknown>): Promise<unknown> { | |
| const id = ++this.requestId | |
| const request: MCPRequest = { | |
| jsonrpc: '2.0', | |
| id, | |
| method, | |
| params, | |
| } | |
| return new Promise((resolve, reject) => { | |
| this.pendingRequests.set(id, { resolve, reject }) | |
| if (this.config.transport === 'stdio') { | |
| this.sendStdioRequest(request) | |
| } else if (this.config.transport === 'http' || this.config.transport === 'sse') { | |
| this.sendHttpRequest(request) | |
| } | |
| }) | |
| } | |
| private async sendStdioRequest(request: MCPRequest): Promise<void> { | |
| // In stdio mode, would spawn the process and communicate via stdin/stdout | |
| console.log('[mcp] Stdio request:', request) | |
| } | |
| private async sendHttpRequest(request: MCPRequest): Promise<void> { | |
| const url = this.config.url | |
| if (!url) { | |
| throw new Error('MCP HTTP client requires URL') | |
| } | |
| try { | |
| const response = await fetch(url, { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify(request), | |
| }) | |
| if (!response.ok) { | |
| throw new Error(`MCP request failed: ${response.status}`) | |
| } | |
| const data = await response.json() as MCPResponse | |
| const pending = this.pendingRequests.get(data.id) | |
| if (pending) { | |
| if (data.error) { | |
| pending.reject(new Error(data.error.message)) | |
| } else { | |
| pending.resolve(data.result) | |
| } | |
| this.pendingRequests.delete(data.id) | |
| } | |
| } catch (error) { | |
| // Reject all pending requests | |
| for (const [, pending] of this.pendingRequests) { | |
| pending.reject(error as Error) | |
| } | |
| this.pendingRequests.clear() | |
| } | |
| } | |
| // List available tools | |
| async listTools(): Promise<MCPTool[]> { | |
| try { | |
| const result = await this.sendRequest('tools/list') as { | |
| tools: Array<{ | |
| name: string | |
| description?: string | |
| inputSchema?: Record<string, unknown> | |
| }> | |
| } | |
| return (result.tools ?? []).map(t => ({ | |
| name: t.name, | |
| description: t.description ?? '', | |
| inputSchema: t.inputSchema ?? {}, | |
| })) | |
| } catch { | |
| return [] | |
| } | |
| } | |
| // Call a tool | |
| async callTool(name: string, args: Record<string, unknown>): Promise<unknown> { | |
| return this.sendRequest('tools/call', { name, arguments: args }) | |
| } | |
| // List available resources | |
| async listResources(): Promise<MCPResource[]> { | |
| try { | |
| const result = await this.sendRequest('resources/list') as { | |
| resources: Array<{ | |
| uri: string | |
| name: string | |
| description?: string | |
| mimeType?: string | |
| }> | |
| } | |
| return (result.resources ?? []).map(r => ({ | |
| uri: r.uri, | |
| name: r.name, | |
| description: r.description, | |
| mimeType: r.mimeType, | |
| })) | |
| } catch { | |
| return [] | |
| } | |
| } | |
| // Read a resource | |
| async readResource(uri: string): Promise<unknown> { | |
| return this.sendRequest('resources/read', { uri }) | |
| } | |
| } | |
| // βββ MCP Connection Manager βββ | |
| export class MCPConnectionManager { | |
| private connections: Map<string, MCPClient> = new Map() | |
| async addServer(config: MCP_SERVER_CONFIG): Promise<MCPClient> { | |
| const client = new MCPClient(config) | |
| this.connections.set(config.name, client) | |
| // Initialize the connection | |
| try { | |
| await client.sendRequest('initialize', { | |
| protocolVersion: '2024-11-05', | |
| capabilities: {}, | |
| clientInfo: { | |
| name: 'stack-2.9', | |
| version: '1.0.0', | |
| }, | |
| }) | |
| console.log(`[mcp] Connected to ${config.name}`) | |
| } catch (error) { | |
| console.error(`[mcp] Failed to connect to ${config.name}:`, error) | |
| } | |
| return client | |
| } | |
| getServer(name: string): MCPClient | undefined { | |
| return this.connections.get(name) | |
| } | |
| removeServer(name: string): void { | |
| this.connections.delete(name) | |
| } | |
| listServers(): string[] { | |
| return Array.from(this.connections.keys()) | |
| } | |
| async closeAll(): Promise<void> { | |
| for (const [name, client] of this.connections) { | |
| try { | |
| await client.sendRequest('shutdown') | |
| } catch { | |
| // Ignore shutdown errors | |
| } | |
| console.log(`[mcp] Disconnected from ${name}`) | |
| } | |
| this.connections.clear() | |
| } | |
| } | |
| // βββ Factory βββ | |
| export function createMCPClient(config: MCPConfig): MCPClient { | |
| const serverConfig: MCP_SERVER_CONFIG = { | |
| name: config.name, | |
| transport: config.transport ?? 'stdio', | |
| command: config.command, | |
| args: config.args, | |
| env: config.env, | |
| url: config.url, | |
| } | |
| return new MCPClient(serverConfig) | |
| } | |
| export default { | |
| MCPClient, | |
| MCPConnectionManager, | |
| createMCPClient, | |
| } |