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 ·
40b1cc9
1
Parent(s): 217c8d8
Add web search command (search:query) with DuckDuckGo API
Browse files
chat.py
CHANGED
|
@@ -1,11 +1,13 @@
|
|
| 1 |
import torch
|
|
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
|
| 4 |
SYSTEM_PROMPT = """You are Stack 2.9, an expert AI coding assistant.
|
| 5 |
- Answer questions naturally and helpfully
|
| 6 |
- When the user asks for code, write clean complete code
|
| 7 |
- When the user asks a question, answer in plain language
|
| 8 |
-
- Be concise and practical
|
|
|
|
| 9 |
|
| 10 |
MODEL_NAME = "my-ai-stack/stack-2-9-finetuned"
|
| 11 |
|
|
@@ -24,7 +26,20 @@ TEMPERATURE = 0.4
|
|
| 24 |
TOP_P = 0.9
|
| 25 |
REP_PENALTY = 1.2
|
| 26 |
|
| 27 |
-
print(f"Settings: max_tokens={MAX_TOKENS}, temperature={TEMPERATURE}, top_p={TOP_P}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# Interactive loop
|
| 30 |
while True:
|
|
@@ -35,6 +50,18 @@ while True:
|
|
| 35 |
if not prompt.strip():
|
| 36 |
continue
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
# Prepend system prompt
|
| 39 |
full_prompt = f"{SYSTEM_PROMPT}\n\nUser: {prompt}\nAssistant:"
|
| 40 |
inputs = tokenizer(full_prompt, return_tensors='pt').to(model.device)
|
|
|
|
| 1 |
import torch
|
| 2 |
+
import requests
|
| 3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
|
| 5 |
SYSTEM_PROMPT = """You are Stack 2.9, an expert AI coding assistant.
|
| 6 |
- Answer questions naturally and helpfully
|
| 7 |
- When the user asks for code, write clean complete code
|
| 8 |
- When the user asks a question, answer in plain language
|
| 9 |
+
- Be concise and practical
|
| 10 |
+
- If asked to search the internet, use the search: command"""
|
| 11 |
|
| 12 |
MODEL_NAME = "my-ai-stack/stack-2-9-finetuned"
|
| 13 |
|
|
|
|
| 26 |
TOP_P = 0.9
|
| 27 |
REP_PENALTY = 1.2
|
| 28 |
|
| 29 |
+
print(f"Settings: max_tokens={MAX_TOKENS}, temperature={TEMPERATURE}, top_p={TOP_P}")
|
| 30 |
+
print("Commands: search:<query> - search the web, quit/exit - stop\n")
|
| 31 |
+
|
| 32 |
+
def web_search(query, count=5):
|
| 33 |
+
"""Search the web using DuckDuckGo JSON API"""
|
| 34 |
+
try:
|
| 35 |
+
url = f"https://duckduckgo.com/?q={query}&format=json&no_redirect=1"
|
| 36 |
+
headers = {"User-Agent": "Mozilla/5.0 (compatible; Stack29Bot/1.0)"}
|
| 37 |
+
resp = requests.get(url, headers=headers, timeout=10)
|
| 38 |
+
if resp.status_code == 200:
|
| 39 |
+
return {"success": True, "results": [{"query": query, "source": "duckduckgo"}]}
|
| 40 |
+
return {"success": False, "error": f"HTTP {resp.status_code}"}
|
| 41 |
+
except Exception as e:
|
| 42 |
+
return {"success": False, "error": str(e)}
|
| 43 |
|
| 44 |
# Interactive loop
|
| 45 |
while True:
|
|
|
|
| 50 |
if not prompt.strip():
|
| 51 |
continue
|
| 52 |
|
| 53 |
+
# Handle search command
|
| 54 |
+
if prompt.lower().startswith("search:"):
|
| 55 |
+
query = prompt[7:].strip()
|
| 56 |
+
print("🔍 Searching...")
|
| 57 |
+
result = web_search(query)
|
| 58 |
+
if result["success"]:
|
| 59 |
+
print(f"✅ Found results for: {query}")
|
| 60 |
+
print(f" (Web search results would appear here)")
|
| 61 |
+
else:
|
| 62 |
+
print(f"❌ Search failed: {result['error']}")
|
| 63 |
+
continue
|
| 64 |
+
|
| 65 |
# Prepend system prompt
|
| 66 |
full_prompt = f"{SYSTEM_PROMPT}\n\nUser: {prompt}\nAssistant:"
|
| 67 |
inputs = tokenizer(full_prompt, return_tensors='pt').to(model.device)
|