全部产品
Search
文档中心

Alibaba Cloud Model Studio:Mode sebagian

更新时间:Feb 04, 2026

Dalam skenario seperti penyelesaian kode dan kelanjutan teks, model menghasilkan teks berdasarkan fragmen yang sudah ada—atau awalan. Mode sebagian memberikan kontrol yang tepat untuk memastikan bahwa output model merupakan kelanjutan langsung dari awalan tersebut, sehingga meningkatkan akurasi dan kemampuan pengendalian atas hasil yang dihasilkan.

Cara kerjanya

Anda harus mengatur role pesan terakhir dalam array messages menjadi assistant, menyediakan awalan dalam content-nya, dan mengatur parameter "partial": true pada pesan tersebut. Format array messages adalah sebagai berikut:

[
    {
        "role": "user",
        "content": "Please complete this Fibonacci function. Do not add any other content."
    },
    {
        "role": "assistant",
        "content": "def calculate_fibonacci(n):\n    if n <= 1:\n        return n\n    else:\n",
        "partial": true
    }
]

Model mulai menghasilkan dari awalan tersebut.

Model yang didukung

  • Seri Qwen-Max

    qwen3-max (mode non-thinking), qwen3-max-2025-09-23, qwen3-max-preview (mode non-thinking), qwen-max, qwen-max-latest, qwen-max-2025-01-25, dan model snapshot versi selanjutnya

  • Qwen-Plus Series (non-thinking mode)

    qwen-plus, qwen-plus-latest, qwen-plus-2025-01-25, dan model snapshot versi selanjutnya

  • Seri Qwen-Flash (mode non-thinking)

    qwen-flash, qwen-flash-2025-07-28, dan model snapshot versi selanjutnya

  • Seri Qwen-Coder

    qwen3-coder-plus, qwen3-coder-flash, qwen3-coder-480b-a35b-instruct, qwen3-coder-30b-a3b-instruct

  • Seri Qwen-VL

    • qwen3-vl-plus series (non-thinking mode)

      qwen3-vl-plus, qwen3-vl-plus-2025-09-23, dan model snapshot versi selanjutnya

    • qwen3-vl-flash series (non-thinking mode)

      qwen3-vl-flash, qwen3-vl-flash-2025-10-15, dan model snapshot versi selanjutnya

    • Seri qwen-vl-max

      qwen-vl-max, qwen-vl-max-latest, qwen-vl-max-2025-04-08, dan model snapshot versi selanjutnya

    • Seri qwen-vl-plus

      qwen-vl-plus, qwen-vl-plus-latest, qwen-vl-plus-2025-01-25, dan model snapshot versi selanjutnya

  • seri Qwen-Turbo (non-thinking mode)

    qwen-turbo, qwen-turbo-latest, qwen-turbo-2024-11-01, dan model snapshot versi selanjutnya

  • Seri open source Qwen

    Model open source Qwen3 (mode non-thinking), model teks seri Qwen2.5, model open source Qwen3-VL (mode non-thinking)

Penting

Model dalam mode thinking saat ini tidak mendukung fitur mode sebagian.

Mulai menggunakan

Prasyarat

Dapatkan Kunci API dan host API serta konfigurasikan Kunci API sebagai variabel lingkungan. Jika Anda memanggil layanan menggunakan OpenAI SDK atau DashScope SDK, Anda harus menginstal SDK. Jika Anda anggota ruang kerja anak, pastikan super administrator telah memberikan otorisasi model untuk ruang kerja tersebut.

Catatan

DashScope Java SDK saat ini belum didukung.

Kode contoh

Penyelesaian kode merupakan aplikasi inti dari mode sebagian. Contoh berikut menunjukkan cara menggunakan model qwen3-coder-plus untuk melengkapi fungsi Python.

Kompatibel dengan OpenAI

Python

import os
from openai import OpenAI

# 1. Inisialisasi client
client = OpenAI(
    # Kunci API berbeda berdasarkan wilayah. Untuk mendapatkan Kunci API, lihat https://www.alibabacloud.com/help/zh/model-studio/get-api-key
    # Jika Anda belum mengonfigurasi variabel lingkungan, ganti di sini dengan Kunci API Anda
    api_key=os.getenv("DASHSCOPE_API_KEY"), 
    # Jika Anda menggunakan model di wilayah Beijing, ganti URL dengan: https://dashscope.aliyuncs.com/compatible-mode/v1
    base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",  
)
# 2. Tentukan awalan kode yang akan dilengkapi
prefix = """def calculate_fibonacci(n):
    if n <= 1:
        return n
    else:
"""

# 3. Ajukan permintaan mode sebagian
# Catatan: Pesan terakhir dalam array messages memiliki role "assistant" dan mencakup "partial": True
completion = client.chat.completions.create(
    model="qwen3-coder-plus",
    messages=[
        {"role": "user", "content": "Please complete this Fibonacci function. Do not add any other content."},
        {"role": "assistant", "content": prefix, "partial": True},
    ],
)

# 4. Gabungkan secara manual awalan dan konten yang dihasilkan model
generated_code = completion.choices[0].message.content
complete_code = prefix + generated_code

print(complete_code)

Respons

def calculate_fibonacci(n):
    if n <= 1:
        return n
    else:
        return calculate_fibonacci(n-1) + calculate_fibonacci(n-2)

Node.js

import OpenAI from "openai";

const openai = new OpenAI({
    // Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan Kunci API Model Studio Anda: apiKey: "sk-xxx",
    apiKey: process.env.DASHSCOPE_API_KEY,
    // Jika Anda menggunakan model di wilayah Beijing, ganti URL dengan: https://dashscope.aliyuncs.com/compatible-mode/v1
    baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
});

// Tentukan awalan kode yang akan dilengkapi
const prefix = `def calculate_fibonacci(n):
    if n <= 1:
        return n
    else:
`;

const completion = await openai.chat.completions.create({
    model: "qwen3-coder-plus",  // Gunakan model kode
    messages: [
        { role: "user", content: "Please complete this Fibonacci function. Do not add any other content." },
        { role: "assistant", content: prefix, partial: true }
    ],
});

// Gabungkan secara manual awalan dan konten yang dihasilkan model
const generatedCode = completion.choices[0].message.content;
const completeCode = prefix + generatedCode;

console.log(completeCode);

curl

# ======= Penting =======
# Kunci API berbeda berdasarkan wilayah. Untuk mendapatkan Kunci API, lihat https://www.alibabacloud.com/help/zh/model-studio/get-api-key
# Jika Anda menggunakan model di wilayah Beijing, ganti URL dengan: https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions
# === Hapus komentar ini sebelum eksekusi ===

curl -X POST https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen3-coder-plus",
    "messages": [
        {
            "role": "user", 
            "content": "Please complete this Fibonacci function. Do not add any other content."
        },
        {
            "role": "assistant",
            "content": "def calculate_fibonacci(n):\n    if n <= 1:\n        return n\n    else:\n",
            "partial": true
        }
    ]
}'

Respons

{
    "choices": [
        {
            "message": {
                "content": "        return calculate_fibonacci(n-1) + calculate_fibonacci(n-2)",
                "role": "assistant"
            },
            "finish_reason": "stop",
            "index": 0,
            "logprobs": null
        }
    ],
    "object": "chat.completion",
    "usage": {
        "prompt_tokens": 48,
        "completion_tokens": 19,
        "total_tokens": 67,
        "prompt_tokens_details": {
            "cache_type": "implicit",
            "cached_tokens": 0
        }
    },
    "created": 1756800231,
    "system_fingerprint": null,
    "model": "qwen3-coder-plus",
    "id": "chatcmpl-d103b1cf-4bda-942f-92d6-d7ecabfeeccb"
}

DashScope

Python

import os
import dashscope

# Jika Anda menggunakan model di Wilayah Beijing, ganti URL dengan: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

# Tentukan awalan kode untuk dilengkapi
prefix = """def calculate_fibonacci(n):
    if n <= 1:
        return n
    else:
"""

messages = [
    {
        "role": "user", 
        "content": "Please complete this Fibonacci function. Do not add any other content."
    },
    {
        "role": "assistant",
        "content": prefix,
        "partial": True
    }
]

response = dashscope.Generation.call(
    # Kunci API berbeda menurut Wilayah. Untuk mendapatkan Kunci API, lihat https://www.alibabacloud.com/help/zh/model-studio/get-api-key
    # Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan Kunci API Model Studio Anda: api_key="sk-xxx",
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model='qwen3-coder-plus',  # Gunakan model kode
    messages=messages,
    result_format='message',  
)

# Gabungkan awalan dan konten yang dihasilkan model secara manual
generated_code = response.output.choices[0].message.content
complete_code = prefix + generated_code

print(complete_code)

Respons

def calculate_fibonacci(n):
    if n <= 1:
        return n
    else:
        return calculate_fibonacci(n-1) + calculate_fibonacci(n-2)

curl

# ======= Penting =======
# Kunci API berbeda berdasarkan wilayah. Untuk mendapatkan Kunci API, lihat https://www.alibabacloud.com/help/zh/model-studio/get-api-key
# Jika Anda menggunakan model di wilayah Beijing, ganti URL dengan: https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation
# === Hapus komentar ini sebelum eksekusi ===

curl -X POST "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen3-coder-plus",
    "input":{
        "messages":[
            {
                "role": "user",
                "content": "Please complete this Fibonacci function. Do not add any other content."
            },
            {
                "role": "assistant",
                "content": "def calculate_fibonacci(n):\n    if n <= 1:\n        return n\n    else:\n",
                "partial": true
            }
        ]
    },
    "parameters": {
        "result_format": "message"
    }
}'

Respons

{
    "output": {
        "choices": [
            {
                "message": {
                    "content": "        return calculate_fibonacci(n-1) + calculate_fibonacci(n-2)",
                    "role": "assistant"
                },
                "finish_reason": "stop"
            }
        ]
    },
    "usage": {
        "total_tokens": 67,
        "output_tokens": 19,
        "input_tokens": 48,
        "prompt_tokens_details": {
            "cached_tokens": 0
        }
    },
    "request_id": "c61c62e5-cf97-90bc-a4ee-50e5e117b93f"
}

Contoh penggunaan

Kirim gambar atau video

Model Qwen-VL mendukung mode sebagian saat memproses data gambar atau video. Fitur ini dapat digunakan untuk skenario seperti perkenalan produk, pembuatan konten media sosial, pembuatan siaran pers, dan penulisan iklan kreatif.

Kompatibel dengan OpenAI

Python

import os
from openai import OpenAI

client = OpenAI(
    # Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan Kunci API Model Studio Anda: api_key="sk-xxx",
    # Kunci API berbeda berdasarkan wilayah. Untuk mendapatkan Kunci API, lihat https://www.alibabacloud.com/help/zh/model-studio/get-api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # Jika Anda menggunakan model di wilayah Beijing, ganti base_url dengan: https://dashscope.aliyuncs.com/compatible-mode/v1
    base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
)

completion = client.chat.completions.create(
    model="qwen3-vl-plus",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://img.alicdn.com/imgextra/i3/O1CN01zFX2Bs1Q0f9pESgPC_!!6000000001914-2-tps-450-450.png"
                    },
                },
                {"type": "text", "text": "I want to post on social media. Please help me write some copy."},
            ],
        },
        {
            "role": "assistant",
            "content": "Discovered a hidden gem of a coffee shop today",
            "partial": True,
        },
    ],
)
print(completion.choices[0].message.content)

Respons

, and this tiramisu is a treat for the taste buds! Every bite is a perfect blend of coffee and cream, pure bliss~ #foodsharing #tiramisu #coffeetime

Hope you like this copy! Let me know if you need any changes.

Node.js

import OpenAI from "openai";

const openai = new OpenAI({
  // Kunci API berbeda berdasarkan wilayah. Untuk mendapatkan Kunci API, lihat https://www.alibabacloud.com/help/zh/model-studio/get-api-key
  // Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan Kunci API Model Studio Anda: apiKey: "sk-xxx"
  apiKey: process.env.DASHSCOPE_API_KEY,
  // Jika Anda menggunakan model di wilayah Beijing, ganti base_url dengan https://dashscope.aliyuncs.com/compatible-mode/v1
  baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
});

async function main() {
    const response = await openai.chat.completions.create({
        model: "qwen3-vl-plus",  
        messages: [
            {
                role: "user",
                content: [
                    {
                        type: "image_url",
                        image_url: {
                            "url": "https://img.alicdn.com/imgextra/i3/O1CN01zFX2Bs1Q0f9pESgPC_!!6000000001914-2-tps-450-450.png"
                        }
                    },
                    {
                        type: "text",
                        text: "I want to post on social media. Please help me write some copy."
                    }
                ]
            },
            {
                role: "assistant",
                content: "Discovered a hidden gem of a coffee shop today",
                "partial": true
            }
        ]
    });
    console.log(response.choices[0].message.content);
}

main();

curl

# ======= Penting =======
# Jika Anda menggunakan model di wilayah Beijing, ganti base_url dengan: https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions
# Kunci API berbeda berdasarkan wilayah. Untuk mendapatkan Kunci API, lihat https://www.alibabacloud.com/help/zh/model-studio/get-api-key
# === Hapus komentar ini sebelum eksekusi ===

curl -X POST 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
  "model": "qwen3-vl-plus",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "image_url",
          "image_url": {
            "url": "https://img.alicdn.com/imgextra/i3/O1CN01zFX2Bs1Q0f9pESgPC_!!6000000001914-2-tps-450-450.png"
          }
        },
        {
          "type": "text",
          "text": "I want to post on social media. Please help me write some copy."
        }
      ]
    },
    {
      "role": "assistant",
      "content": "Discovered a hidden gem of a coffee shop today",
      "partial": true
    }
  ]
}'

Respons

{
    "choices": [
        {
            "message": {
                "content": ", and this tiramisu is a treat for the taste buds! Every bite is a perfect blend of coffee and cream, pure bliss~ #foodsharing #tiramisu #coffeetime\n\nHope you like this copy! Let me know if you need any changes.",
                "role": "assistant"
            },
            "finish_reason": "stop",
            "index": 0,
            "logprobs": null
        }
    ],
    "object": "chat.completion",
    "usage": {
        "prompt_tokens": 282,
        "completion_tokens": 56,
        "total_tokens": 338,
        "prompt_tokens_details": {
            "cached_tokens": 0
        }
    },
    "created": 1756802933,
    "system_fingerprint": null,
    "model": "qwen3-vl-plus",
    "id": "chatcmpl-5780cbb7-ebae-9c63-b098-f8cc49e321f0"
}

DashScope

Python

import os
import dashscope

# Jika Anda menggunakan model di wilayah Beijing, ganti base_url dengan: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

messages = [
    {
        "role": "user",
        "content": [
            {
                "image": "https://img.alicdn.com/imgextra/i3/O1CN01zFX2Bs1Q0f9pESgPC_!!6000000001914-2-tps-450-450.png"
            },
            {"text": "I want to post on social media. Please help me write some copy."},
        ],
    },
    {"role": "assistant", "content": "Discovered a hidden gem of a coffee shop today", "partial": True},
]

response = dashscope.MultiModalConversation.call(
    #Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan Kunci API Model Studio Anda: api_key ="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"), 
    model="qwen3-vl-plus", 
    messages=messages
)

print(response.output.choices[0].message.content[0]["text"])

Respons

, and this tiramisu is a treat for the taste buds! Every bite is a perfect blend of coffee and cream, pure bliss~ #foodsharing #tiramisu #coffeetime

Hope you like this copy! Let me know if you need any changes.

curl

# ======= Penting =======
# Jika Anda menggunakan model di wilayah Beijing, ganti base_url dengan: https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
# Kunci API berbeda berdasarkan wilayah. Untuk mendapatkan Kunci API, lihat https://www.alibabacloud.com/help/zh/model-studio/get-api-key
# === Hapus komentar ini sebelum eksekusi ===

curl -X POST https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
    "model": "qwen3-vl-plus",
    "input":{
        "messages":[
            {"role": "user",
             "content": [
               {"image": "https://img.alicdn.com/imgextra/i3/O1CN01zFX2Bs1Q0f9pESgPC_!!6000000001914-2-tps-450-450.png"},
               {"text": "I want to post on social media. Please help me write some copy."}]
            },
            {"role": "assistant",
             "content": "Discovered a hidden gem of a coffee shop today",
             "partial": true
            }
        ]
    }
}'

Respons

{
    "output": {
        "choices": [
            {
                "message": {
                    "content": [
                        {
                            "text": ", and this tiramisu is a treat for the taste buds! Every bite is a perfect blend of coffee and cream, pure bliss~ #foodsharing #tiramisu #coffeetime\n\nHope you like this copy! Let me know if you need any changes."
                        }
                    ],
                    "role": "assistant"
                },
                "finish_reason": "stop"
            }
        ]
    },
    "usage": {
        "total_tokens": 339,
        "input_tokens_details": {
            "image_tokens": 258,
            "text_tokens": 24
        },
        "output_tokens": 57,
        "input_tokens": 282,
        "output_tokens_details": {
            "text_tokens": 57
        },
        "image_tokens": 258
    },
    "request_id": "c741328c-23dc-9286-bfa7-626a4092ca09"
}

Lanjutkan penulisan dari output yang belum lengkap

Jika parameter max_tokens diatur terlalu rendah, LLM mungkin mengembalikan konten yang belum lengkap. Anda dapat menggunakan mode sebagian untuk melanjutkan generasi dari konten yang belum lengkap tersebut dan memastikannya lengkap secara semantik.

Kompatibel dengan OpenAI

Python

import os
from openai import OpenAI

client = OpenAI(
    # Kunci API berbeda berdasarkan wilayah. Untuk mendapatkan Kunci API, lihat https://www.alibabacloud.com/help/zh/model-studio/get-api-key
    # Jika Anda belum mengonfigurasi variabel lingkungan, ganti di sini dengan Kunci API Anda
    api_key=os.getenv("DASHSCOPE_API_KEY"), 
    # Jika Anda menggunakan model di wilayah Beijing, ganti URL dengan: https://dashscope.aliyuncs.com/compatible-mode/v1
    base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",  
)

def chat_completion(messages,max_tokens=None):
    response = client.chat.completions.create(
        model="qwen-plus",
        messages=messages,
        max_tokens=max_tokens
    )
    print(f"###Alasan berhenti: {response.choices[0].finish_reason}")
    
    return response.choices[0].message.content

# Contoh penggunaan
messages = [{"role": "user", "content": "Please write a short science fiction story"}]

# Panggilan pertama, atur max_tokens ke 40
first_content = chat_completion(messages, max_tokens=40)
print(first_content)
# Tambahkan respons dari panggilan pertama ke pesan assistant dan atur partial=True
messages.append({"role": "assistant", "content": first_content, "partial": True})

# Panggilan kedua
second_content = chat_completion(messages)
print("###Konten lengkap:")
print(first_content+second_content)

Respons

Alasan berhenti length menunjukkan bahwa batas max_tokens telah tercapai. Alasan berhenti stop menunjukkan bahwa LLM selesai menghasilkan secara alami atau parameter stop telah dipicu.

###Alasan berhenti: length
**"The End of Memory"**

In the distant future, Earth was no longer habitable. The atmosphere layer was polluted, the oceans had dried up, and cities had turned into ruins. Humanity was forced to migrate to a habitable planet called "
###Alasan berhenti: stop
###Konten lengkap:
**"The End of Memory"**

In the distant future, Earth was no longer habitable. The atmosphere layer was polluted, the oceans had dried up, and cities had turned into ruins. Humanity was forced to migrate to a habitable planet called "Eden," which had blue skies, fresh air, and endless resources.

However, Eden was not a true paradise. It had no human history, no past, and no memory.

......

**"If we forget who we are, are we still human?"**

--The End--

Node.js

import OpenAI from "openai";

const openai = new OpenAI({
    // Kunci API berbeda berdasarkan wilayah. Untuk mendapatkan Kunci API, lihat https://www.alibabacloud.com/help/zh/model-studio/get-api-key
    // Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan Kunci API Model Studio Anda: apiKey: "sk-xxx",
    apiKey: process.env.DASHSCOPE_API_KEY,
    // Jika Anda menggunakan model di wilayah Beijing, ganti URL dengan: https://dashscope.aliyuncs.com/compatible-mode/v1
    baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
});

async function chatCompletion(messages, maxTokens = null) {
    const completion = await openai.chat.completions.create({
        model: "qwen-plus",
        messages: messages,
        max_tokens: maxTokens
    });
    
    console.log(`###Alasan berhenti: ${completion.choices[0].finish_reason}`);
    return completion.choices[0].message.content;
}

// Contoh penggunaan
async function main() {
    let messages = [{"role": "user", "content": "Please write a short science fiction story"}];

    try {
        // Panggilan pertama, atur max_tokens ke 40
        const firstContent = await chatCompletion(messages, 40);
        console.log(firstContent);
        
        // Tambahkan respons dari panggilan pertama ke pesan assistant dan atur partial=true
        messages.push({"role": "assistant", "content": firstContent, "partial": true});

        // Panggilan kedua
        const secondContent = await chatCompletion(messages);
        console.log("###Konten lengkap:");
        console.log(firstContent + secondContent);
        
    } catch (error) {
        console.error('Execution error:', error);
    }
}

// Jalankan contoh
main();

DashScope

Python

Kode contoh

import os
import dashscope
# Jika Anda menggunakan model di wilayah Beijing, ganti URL dengan: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

def chat_completion(messages, max_tokens=None):
    response = dashscope.Generation.call(
        # Kunci API berbeda berdasarkan wilayah. Untuk mendapatkan Kunci API, lihat https://www.alibabacloud.com/help/zh/model-studio/get-api-key
        # Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan Kunci API Model Studio Anda: api_key="sk-xxx",
        api_key=os.getenv("DASHSCOPE_API_KEY"),
        model='qwen-plus',
        messages=messages,
        max_tokens=max_tokens,
        result_format='message',  
    )
    
    print(f"###Alasan berhenti: {response.output.choices[0].finish_reason}")
    return response.output.choices[0].message.content

# Contoh penggunaan
messages = [{"role": "user", "content": "Please write a short science fiction story"}]

# Panggilan pertama, atur max_tokens ke 40
first_content = chat_completion(messages, max_tokens=40)
print(first_content)

# Tambahkan respons dari panggilan pertama ke pesan assistant dan atur partial=True
messages.append({"role": "assistant", "content": first_content, "partial": True})

# Panggilan kedua
second_content = chat_completion(messages)
print("###Konten lengkap:")
print(first_content + second_content)

Respons

###Alasan berhenti: length
Title: **"Time Origami"**

---

In the year 2179, humanity finally mastered the technology of time travel. But this technology was not achieved through massive machines or complex energy fields, but through a piece of paper.
###Alasan berhenti: stop
###Konten lengkap:
Title: **"Time Origami"**

---

In the year 2179, humanity finally mastered the technology of time travel. But this technology was not achieved through massive machines or complex energy fields, but through a piece of paper.

A piece of paper that could fold time.

It was called "Time Origami" and was made from an unknown substance from an alien civilization. Scientists could not explain its principle, only that by drawing a scene on the paper and then folding it in a specific way, a door to the past or future could be opened.

......

"You are not the key to time, just a reminder that the future is always in our hands."

Then, I tore it into fragments.

---

**(The End)**

Penagihan

Penagihan didasarkan pada jumlah token input dan output dalam suatu permintaan. Awalan dihitung sebagai token input.

Kode error

Jika pemanggilan gagal, lihat Pesan error untuk troubleshooting.