Tổng quan

Qwen 2.5-7B Instruct LLM Service

Dịch vụ LLM chạy local với Qwen2.5-7B-Instruct-AWQ (4-bit quantized). Được sử dụng làm fallback LLM cho AI Agent khi Gemma4 không khả dụng. Hỗ trợ tool-calling, tiếng Việt chất lượng cao, đa ngôn ngữ và endpoint chuyên dụng cho AI Agent tasks.

Đặc điểm kỹ thuật

Model Qwen2.5-7B-Instruct-AWQ (Qwen/Qwen2.5-7B-Instruct-AWQ)
Quantization AWQ 4-bit (~5 GiB loaded)
Framework vLLM (OpenAI-compatible backend)
Architecture ports vLLM backend :8091, FastAPI gateway :8043
GPU RTX 3060 12GB (CUDA_VISIBLE_DEVICES=2, nvidia-smi GPU 2)
VRAM Usage ~5GB (model weights + KV cache)
Context Window 8,192 tokens (max_model_len=8192)
Ngôn ngữ Tiếng Việt, tiếng Anh, tiếng Trung và 29+ ngôn ngữ khác
Vai trò trong hệ thống Fallback LLM cho AI Agent (khi Gemma4 không khả dụng)

Tính năng nổi bật

Tool-Calling

Hỗ trợ function/tool calling — tích hợp tốt với AI Agent pipeline

Đa ngôn ngữ

Tiếng Việt, Anh, Trung chất lượng cao — 29+ ngôn ngữ

8K Context

Context window 8.192 tokens — phân tích tài liệu dài

Agent Endpoint

Endpoint /agent chuyên biệt cho structured reasoning tasks

OpenAI API

Drop-in replacement cho OpenAI Python/JS SDK

Local & Bảo mật

Xử lý 100% local — dữ liệu bệnh nhân không ra ngoài

API Endpoints

Base URL

https://pnt.badt.vn/qwen

Danh sách Endpoints

GET /health

Health check — trả về trạng thái service và vLLM backend.

GET /status

Service status chi tiết — thông tin model, GPU, uptime.

POST /chat

Simple single-turn chat endpoint.

Request body

{
  "message": "string (required)",
  "system": "Bạn là trợ lý AI hữu ích, trả lời bằng tiếng Việt.",
  "temperature": 0.7,
  "max_tokens": 800
}

Response

{
  "response": "string",
  "model": "qwen2.5-7b",
  "usage": {
    "prompt_tokens": 20,
    "completion_tokens": 150,
    "total_tokens": 170
  }
}
POST /v1/chat/completions

OpenAI-compatible chat completions endpoint.

Request body

{
  "model": "qwen2.5-7b",
  "messages": [
    {"role": "system", "content": "..."},
    {"role": "user", "content": "..."}
  ],
  "temperature": 0.7,
  "max_tokens": 800,
  "top_p": 0.95,
  "stream": false
}
POST /agent

Structured reasoning endpoint dành riêng cho AI Agent tasks — phân tích, tóm tắt, dịch thuật, lập kế hoạch.

Request body

{
  "task": "string (required) — mô tả nhiệm vụ",
  "context": "string (optional) — dữ liệu/ngữ cảnh nền",
  "output_format": "string (optional) — e.g. 'JSON', 'bullet list'",
  "temperature": 0.3,
  "max_tokens": 1200
}

Response

{
  "task": "string",
  "result": "string",
  "model": "qwen2.5-7b",
  "usage": { ... }
}
GET /v1/models

List available models (OpenAI format).

Xác thực

Bearer Token Authentication Required

API này yêu cầu Bearer token trong Authorization header. Liên hệ admin để nhận API token.

Cách dùng

Authorization: Bearer YOUR_API_TOKEN
Lưu ý bảo mật
  • Không chia sẻ token công khai hoặc commit vào source code
  • Dùng environment variables để lưu token
  • Rate limiting áp dụng để đảm bảo công bằng

Ví dụ sử dụng

1. Simple Chat (cURL)

curl -X POST https://pnt.badt.vn/qwen/chat \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Triệu chứng của bệnh viêm phổi là gì?",
    "max_tokens": 300,
    "temperature": 0.7
  }'

Response

{
  "response": "Triệu chứng của bệnh viêm phổi thường bao gồm:\n\n1. Ho có đờm (có thể có máu)\n2. Sốt cao...",
  "model": "qwen2.5-7b",
  "usage": {
    "prompt_tokens": 18,
    "completion_tokens": 112,
    "total_tokens": 130
  }
}

2. Chat với System Prompt (Python)

import requests
import os

url = "https://pnt.badt.vn/qwen/chat"
headers = {
    "Authorization": f"Bearer {os.getenv('QWEN_API_TOKEN')}",
    "Content-Type": "application/json"
}
data = {
    "message": "Bệnh nhân 45 tuổi, ho kéo dài 3 tuần. Hướng chẩn đoán?",
    "system": "Bạn là bác sĩ nội khoa. Trả lời ngắn gọn, chuyên nghiệp.",
    "max_tokens": 400,
    "temperature": 0.7
}

response = requests.post(url, json=data, headers=headers)
result = response.json()
print(result["response"])

3. Health Check

curl https://pnt.badt.vn/qwen/health \
  -H "Authorization: Bearer YOUR_API_TOKEN"

Response

{
  "status": "healthy",
  "service": "qwen_service",
  "vllm_server": "healthy",
  "model": "Qwen/Qwen2.5-7B-Instruct-AWQ",
  "timestamp": "2026-04-12T09:15:00.000000"
}

Agent Endpoint /agent

🤖 Endpoint chuyên biệt cho AI Agent Tasks

Endpoint /agent được thiết kế cho các tác vụ structured reasoning: trích xuất dữ liệu, tóm tắt hồ sơ bệnh án, dịch thuật y tế, lập kế hoạch điều trị. Model được cấu hình với temperature=0.3 mặc định để đảm bảo kết quả nhất quán.

Ví dụ — Tóm tắt hồ sơ bệnh án

curl -X POST https://pnt.badt.vn/qwen/agent \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "task": "Tóm tắt chẩn đoán chính và hướng điều trị",
    "context": "BN nam 62 tuổi, nhập viện ngày 10/04/2026 vì khó thở tăng dần 3 ngày. Tiền sử THA, ĐTĐ type 2. ECG: ST chênh lên V2-V4. Troponin T: 2.8 ng/mL. Siêu âm tim: EF 35%. Xử trí...",
    "output_format": "bullet list",
    "temperature": 0.3,
    "max_tokens": 500
  }'

Ví dụ — Trích xuất dữ liệu JSON

import requests, os

url = "https://pnt.badt.vn/qwen/agent"
headers = {
    "Authorization": f"Bearer {os.getenv('QWEN_API_TOKEN')}",
    "Content-Type": "application/json"
}
data = {
    "task": "Trích xuất thông tin bệnh nhân thành JSON",
    "context": "Nguyễn Văn An, 55 tuổi, nam, nhập viện 10/4/2026. Chẩn đoán: NMCT cấp ST chênh lên. Điều trị: Aspirin 300mg, Heparin IV.",
    "output_format": "JSON",
    "temperature": 0.1,
    "max_tokens": 300
}

response = requests.post(url, json=data, headers=headers)
print(response.json()["result"])
Các use-case phù hợp với /agent
  • Trích xuất thông tin có cấu trúc từ văn bản y tế
  • Tóm tắt hồ sơ bệnh án, ghi chú lâm sàng
  • Dịch thuật Việt-Anh-Trung cho thuật ngữ y khoa
  • Lập kế hoạch và phân rã nhiệm vụ phức tạp
  • Trả lời câu hỏi dựa trên ngữ cảnh cho sẵn

OpenAI Compatible API

Qwen service hỗ trợ đầy đủ OpenAI-compatible API — dùng trực tiếp với OpenAI Python/JS SDK:

Python với OpenAI SDK

from openai import OpenAI
import os

client = OpenAI(
    api_key="not-needed",
    base_url="https://pnt.badt.vn/qwen/v1",
    default_headers={
        "Authorization": f"Bearer {os.getenv('QWEN_API_TOKEN')}"
    }
)

response = client.chat.completions.create(
    model="qwen2.5-7b",
    messages=[
        {"role": "system", "content": "Bạn là bác sĩ AI chuyên y học nội khoa."},
        {"role": "user", "content": "Triệu chứng suy tim sung huyết?"}
    ],
    temperature=0.7,
    max_tokens=400
)

print(response.choices[0].message.content)

JavaScript với OpenAI SDK

import OpenAI from 'openai';

const client = new OpenAI({
    apiKey: 'not-needed',
    baseURL: 'https://pnt.badt.vn/qwen/v1',
    defaultHeaders: {
        'Authorization': `Bearer ${process.env.QWEN_API_TOKEN}`
    }
});

const response = await client.chat.completions.create({
    model: 'qwen2.5-7b',
    messages: [
        { role: 'system', content: 'Bạn là trợ lý y tế AI.' },
        { role: 'user', content: 'Xin chào!' }
    ],
    max_tokens: 200
});

console.log(response.choices[0].message.content);
So sánh với Gemma4
Tính năngQwen 2.5-7BGemma4 E4B
Parameters7B (AWQ 4-bit)4.5B effective (BnB INT4)
Context8K tokens128K tokens
Thinking mode✅ Chain-of-thought
Tool-calling
Multimodal❌ Text only✅ Text + Image
VRAM~5GB~10GB
Vai trò AgentFallback LLMPrimary LLM
Base URL/qwen/v1/gemma4/v1

Rate Limits

Fair Usage Policy
  • Max concurrent requests: phụ thuộc cấu hình vLLM
  • Request timeout: 300 giây
  • Max tokens per request: 4,096
  • Max model context: 8,192 tokens
  • Max prompt size: 10MB

Error Codes

Code Error Description
400 Bad Request Tham số request không hợp lệ
401 Unauthorized Bearer token thiếu hoặc không hợp lệ
422 Validation Error Request validation failed
500 Internal Server Error Lỗi model server
503 Service Unavailable vLLM backend chưa sẵn sàng
504 Gateway Timeout Request timeout (>300s)

Tài liệu bổ sung