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
walidsobhie-code commited on
Commit ·
6807e9a
1
Parent(s): 31f5bef
Add persistent chat history to ~/.stack-2.9/chat_history.json
Browse files- src/stack-2.9-cli.py +44 -1
src/stack-2.9-cli.py
CHANGED
|
@@ -25,6 +25,10 @@ from pattern_miner import PatternMiner
|
|
| 25 |
from data_quality import DataQualityAnalyzer
|
| 26 |
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
@dataclass
|
| 29 |
class ChatMessage:
|
| 30 |
"""Chat message for display."""
|
|
@@ -32,6 +36,13 @@ class ChatMessage:
|
|
| 32 |
content: str
|
| 33 |
timestamp: str = ""
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
class Stack29TUI:
|
| 37 |
"""Terminal User Interface for Stack 2.9"""
|
|
@@ -42,6 +53,30 @@ class Stack29TUI:
|
|
| 42 |
self.model = os.environ.get("MODEL_NAME", "")
|
| 43 |
self.chat_history: List[ChatMessage] = []
|
| 44 |
self.pattern_miner = PatternMiner()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
def clear_screen(self):
|
| 47 |
"""Clear terminal screen."""
|
|
@@ -152,9 +187,13 @@ class Stack29TUI:
|
|
| 152 |
if not user_input:
|
| 153 |
continue
|
| 154 |
if user_input.lower() in ["exit", "quit"]:
|
|
|
|
| 155 |
break
|
| 156 |
if user_input.lower() == "clear":
|
| 157 |
messages = [system_msg]
|
|
|
|
|
|
|
|
|
|
| 158 |
self.print_header()
|
| 159 |
print("\n💬 Chat Mode (cleared)")
|
| 160 |
print("-" * 40)
|
|
@@ -162,6 +201,7 @@ class Stack29TUI:
|
|
| 162 |
|
| 163 |
# Add user message
|
| 164 |
messages.append(ChatMessage(role="user", content=user_input))
|
|
|
|
| 165 |
|
| 166 |
# Generate response
|
| 167 |
try:
|
|
@@ -174,7 +214,10 @@ class Stack29TUI:
|
|
| 174 |
print(result.text)
|
| 175 |
|
| 176 |
# Add assistant response
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
except Exception as e:
|
| 180 |
print(f"Error: {e}")
|
|
|
|
| 25 |
from data_quality import DataQualityAnalyzer
|
| 26 |
|
| 27 |
|
| 28 |
+
HISTORY_DIR = Path.home() / ".stack-2.9"
|
| 29 |
+
HISTORY_FILE = HISTORY_DIR / "chat_history.json"
|
| 30 |
+
|
| 31 |
+
|
| 32 |
@dataclass
|
| 33 |
class ChatMessage:
|
| 34 |
"""Chat message for display."""
|
|
|
|
| 36 |
content: str
|
| 37 |
timestamp: str = ""
|
| 38 |
|
| 39 |
+
def to_dict(self) -> dict:
|
| 40 |
+
return {"role": self.role, "content": self.content, "timestamp": self.timestamp}
|
| 41 |
+
|
| 42 |
+
@classmethod
|
| 43 |
+
def from_dict(cls, d: dict) -> "ChatMessage":
|
| 44 |
+
return cls(role=d["role"], content=d["content"], timestamp=d.get("timestamp", ""))
|
| 45 |
+
|
| 46 |
|
| 47 |
class Stack29TUI:
|
| 48 |
"""Terminal User Interface for Stack 2.9"""
|
|
|
|
| 53 |
self.model = os.environ.get("MODEL_NAME", "")
|
| 54 |
self.chat_history: List[ChatMessage] = []
|
| 55 |
self.pattern_miner = PatternMiner()
|
| 56 |
+
self._ensure_history_dir()
|
| 57 |
+
self.load_history()
|
| 58 |
+
|
| 59 |
+
def _ensure_history_dir(self):
|
| 60 |
+
HISTORY_DIR.mkdir(parents=True, exist_ok=True)
|
| 61 |
+
|
| 62 |
+
def load_history(self):
|
| 63 |
+
"""Load chat history from disk if available."""
|
| 64 |
+
if HISTORY_FILE.exists():
|
| 65 |
+
try:
|
| 66 |
+
with open(HISTORY_FILE, "r") as f:
|
| 67 |
+
data = json.load(f)
|
| 68 |
+
self.chat_history = [ChatMessage.from_dict(m) for m in data]
|
| 69 |
+
print(f"✓ Loaded {len(self.chat_history)} messages from history")
|
| 70 |
+
except Exception as e:
|
| 71 |
+
print(f"Warning: Could not load history: {e}")
|
| 72 |
+
|
| 73 |
+
def save_history(self):
|
| 74 |
+
"""Save chat history to disk."""
|
| 75 |
+
try:
|
| 76 |
+
with open(HISTORY_FILE, "w") as f:
|
| 77 |
+
json.dump([m.to_dict() for m in self.chat_history], f, indent=2)
|
| 78 |
+
except Exception as e:
|
| 79 |
+
print(f"Warning: Could not save history: {e}")
|
| 80 |
|
| 81 |
def clear_screen(self):
|
| 82 |
"""Clear terminal screen."""
|
|
|
|
| 187 |
if not user_input:
|
| 188 |
continue
|
| 189 |
if user_input.lower() in ["exit", "quit"]:
|
| 190 |
+
self.save_history()
|
| 191 |
break
|
| 192 |
if user_input.lower() == "clear":
|
| 193 |
messages = [system_msg]
|
| 194 |
+
self.chat_history = []
|
| 195 |
+
if HISTORY_FILE.exists():
|
| 196 |
+
HISTORY_FILE.unlink()
|
| 197 |
self.print_header()
|
| 198 |
print("\n💬 Chat Mode (cleared)")
|
| 199 |
print("-" * 40)
|
|
|
|
| 201 |
|
| 202 |
# Add user message
|
| 203 |
messages.append(ChatMessage(role="user", content=user_input))
|
| 204 |
+
self.chat_history.append(ChatMessage(role="user", content=user_input))
|
| 205 |
|
| 206 |
# Generate response
|
| 207 |
try:
|
|
|
|
| 214 |
print(result.text)
|
| 215 |
|
| 216 |
# Add assistant response
|
| 217 |
+
assistant_msg = ChatMessage(role="assistant", content=result.text)
|
| 218 |
+
messages.append(assistant_msg)
|
| 219 |
+
self.chat_history.append(assistant_msg)
|
| 220 |
+
self.save_history()
|
| 221 |
|
| 222 |
except Exception as e:
|
| 223 |
print(f"Error: {e}")
|