Chat Completions

Tạo chat completion từ danh sách messages — tương thích hoàn toàn với OpenAI API.

POST https://bizgpt.vn/wp-json/bizcity/v1/llm/chat

Request Body

model string required

ID của model muốn sử dụng. Xem danh sách models. Ví dụ: deepseek/deepseek-chat-v3-0324:free, openai/gpt-4o, anthropic/claude-sonnet-4

messages array required

Danh sách messages theo chuẩn OpenAI. Mỗi message có role (system, user, assistant) và content (string hoặc array multimodal).

temperature number

Độ ngẫu nhiên từ 0 → 2. Mặc định: 1. Giá trị thấp → câu trả lời chính xác hơn. Giá trị cao → sáng tạo hơn.

max_tokens integer

Giới hạn tokens tối đa cho response. Mặc định phụ thuộc model.

stream boolean

Nếu true, response sẽ gửi dạng SSE (Server-Sent Events). Xem Streaming.

top_p number

Nucleus sampling. Giá trị 0.1 → chỉ lấy top 10% tokens. Thường dùng temperature HOẶC top_p, không dùng cả hai.

stop string | array

Chuỗi hoặc mảng chuỗi để dừng generation. Tối đa 4 stop sequences.

tools array

Danh sách tool/function definitions theo chuẩn OpenAI function calling. Model sẽ trả về tool_calls nếu cần gọi tool.

Ví dụ: Chat đơn giản

bash
curl -X POST https://bizgpt.vn/wp-json/bizcity/v1/llm/chat \
  -H "Authorization: Bearer biz-YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-4o",
    "messages": [
      { "role": "system", "content": "Bạn là trợ lý AI thông minh." },
      { "role": "user", "content": "Giải thích blockchain trong 3 câu." }
    ],
    "temperature": 0.7,
    "max_tokens": 500
  }'

Response

json
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1711684800,
  "model": "openai/gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Blockchain là một chuỗi các khối dữ liệu..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 28,
    "completion_tokens": 145,
    "total_tokens": 173
  }
}

Multimodal (Vision)

Để gửi ảnh kèm text, sử dụng content dạng array:

json
{
  "model": "openai/gpt-4o",
  "messages": [
    {
      "role": "user",
      "content": [
        { "type": "text", "text": "Hình này là gì?" },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://example.com/image.jpg"
          }
        }
      ]
    }
  ]
}

Function Calling / Tools

BizCity hỗ trợ đầy đủ function calling theo chuẩn OpenAI:

json
{
  "model": "openai/gpt-4o",
  "messages": [
    { "role": "user", "content": "Thời tiết Hà Nội hôm nay?" }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Lấy thời tiết hiện tại",
        "parameters": {
          "type": "object",
          "properties": {
            "city": { "type": "string", "description": "Tên thành phố" }
          },
          "required": ["city"]
        }
      }
    }
  ]
}