Model penambangan data mengekstraksi informasi, memoderasi konten, mengklasifikasikan data, dan menghasilkan ringkasan. Model ini menghasilkan data terstruktur (seperti JSON) secara cepat dan akurat, berbeda dengan model chat umum yang mungkin mengembalikan format tidak konsisten atau mengekstraksi informasi secara salah.
Dokumen ini hanya berlaku untuk wilayah China (Beijing). Untuk menggunakan model ini, Anda harus menggunakan API key dari wilayah China (Beijing).
Panduan implementasi
Qwen-Doc-Turbo mendukung ekstraksi informasi dari file melalui tiga cara. Untuk informasi lebih lanjut mengenai batasan ukuran dan jenis file, lihat Batasan.
|
Fitur |
File URL (Direkomendasikan) |
ID File |
Teks biasa |
|
Sumber file |
URL publik |
File lokal (perlu diupload) |
Diteruskan sebagai string |
|
Batas panjang input |
Hingga 10 file |
1 file |
Hingga 9.000 token |
|
Kompatibilitas SDK |
Hanya |
Upload: |
|
|
Keunggulan utama |
Tidak perlu upload ke Model Studio. Mendukung panggilan batch. |
Menghindari upload berulang. Ideal untuk penggunaan ulang. |
Tidak memerlukan manajemen file. |
Prasyarat
-
Anda telah membuat API key dan mengekspor API key sebagai variabel lingkungan.
-
Jika Anda berencana memanggil model menggunakan SDK, instal OpenAI SDK atau DashScope SDK.
Gunakan URL file
Ekstrak data terstruktur menggunakan URL file (hingga 10 file sekaligus). Contoh ini meneruskan file Manual Produk Contoh A dan Manual Produk Contoh B, lalu meminta model mengembalikan informasi yang diekstraksi dalam format JSON.
Metode URL file hanya mendukung protokol DashScope. Gunakan DashScope Python SDK atau panggilan HTTP (seperti curl).
import os
import dashscope
# URL berikut berlaku untuk wilayah China North 2 (Beijing); URL berbeda untuk wilayah lain.
dashscope.base_http_api_url = 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1'
response = dashscope.Generation.call(
api_key=os.getenv('DASHSCOPE_API_KEY'), # Jika Anda belum menyetel variabel lingkungan, ganti ini dengan API key Anda
model='qwen-doc-turbo',
messages=[
{"role": "system","content": "You are a helpful assistant."},
{
"role": "user",
"content": [
{
"type": "text",
"text": "From these two product manuals, extract all product information and organize it into a standard JSON array. Each object must include the following: model (the product model), name (the product name), and price (the price, with currency symbols and commas removed)."
},
{
"type": "doc_url",
"doc_url": [
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251107/jockge/%E7%A4%BA%E4%BE%8B%E4%BA%A7%E5%93%81%E6%89%8B%E5%86%8CA.docx",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251107/ztwxzr/%E7%A4%BA%E4%BE%8B%E4%BA%A7%E5%93%81%E6%89%8B%E5%86%8CB.docx"
],
"file_parsing_strategy": "auto"
}
]
}]
)
try:
if response.status_code == 200:
print(response.output.choices[0].message.content)
else:
print(f"Request failed, status code: {response.status_code}")
print(f"Error code: {response.code}")
print(f"Error message: {response.message}")
print("For more information, see https://www.alibabacloud.com/help/en/model-studio/developer-reference/error-code")
except Exception as e:
print(f"An error occurred: {e}")
print("For more information, see https://www.alibabacloud.com/help/en/model-studio/developer-reference/error-code")
curl --location 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer $DASHSCOPE_API_KEY' \
--header 'X-DashScope-SSE: enable' \
--data '{
"model": "qwen-doc-turbo",
"input": {
"messages": [
{
"role": "system",
"content": "you are a helpful assistant."
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "From these two product manuals, extract all product information and organize it into a standard JSON array. Each object must include the following: model (the product model), name (the product name), and price (the price, with currency symbols and commas removed)."
},
{
"type": "doc_url",
"doc_url": [
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251107/jockge/%E7%A4%BA%E4%BE%8B%E4%BA%A7%E5%93%81%E6%89%8B%E5%86%8CA.docx",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251107/ztwxzr/%E7%A4%BA%E4%BE%8B%E4%BA%A7%E5%93%81%E6%89%8B%E5%86%8CB.docx"
],
"file_parsing_strategy": "auto"
}
]
}
]
}
}'
Gunakan ID file
Upload file
Sebelum menjalankan kode, unduh Manual Produk Contoh A dan letakkan di direktori proyek Anda. Upload file melalui antarmuka kompatibel OpenAI untuk mendapatkan file-id. Untuk detail API upload, lihat Referensi API.
Python
import os
from pathlib import Path
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # Jika Anda belum menyetel variabel lingkungan, ganti ini dengan API key Anda
# URL berikut berlaku untuk wilayah China North 2 (Beijing); URL berbeda untuk wilayah lain.
base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1", # Masukkan base_url layanan DashScope
)
file_object = client.files.create(file=Path("Sample Product Manual A.docx"), purpose="file-extract")
# Cetak file-id untuk digunakan dalam pemanggilan model selanjutnya
print(file_object.id)
Java
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.files.*;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) {
// Buat klien dan gunakan API key dari variabel lingkungan
OpenAIClient client = OpenAIOkHttpClient.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
// URL berikut berlaku untuk wilayah China North 2 (Beijing); URL berbeda untuk wilayah lain.
.baseUrl("https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1")
.build();
// Atur path file. Sesuaikan path dan nama file sesuai kebutuhan.
Path filePath = Paths.get("src/main/java/org/example/Sample Product Manual A.docx");
// Buat parameter upload file
FileCreateParams fileParams = FileCreateParams.builder()
.file(filePath)
.purpose(FilePurpose.of("file-extract"))
.build();
// Upload file dan cetak file-id
FileObject fileObject = client.files().create(fileParams);
// Cetak file-id untuk digunakan dalam pemanggilan model selanjutnya
System.out.println(fileObject.id());
}
}
curl
curl --location --request POST 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/files' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--form 'file=@"Sample Product Manual A.docx"' \
--form 'purpose="file-extract"'
Jalankan kode untuk mendapatkan file-id dari file yang diupload.
Teruskan informasi dan mulai percakapan menggunakan ID file
Teruskan file-id dalam pesan system (setelah pesan pengaturan role). Pesan user berisi kueri Anda tentang file tersebut.
import os
from openai import OpenAI, BadRequestError
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # Jika Anda belum menyetel variabel lingkungan, ganti ini dengan API key Anda
# URL berikut berlaku untuk wilayah China North 2 (Beijing); URL berbeda untuk wilayah lain.
base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)
try:
completion = client.chat.completions.create(
model="qwen-doc-turbo",
messages=[
{'role': 'system', 'content': 'You are a helpful assistant.'},
# Ganti '{FILE_ID}' dengan file-id dari skenario Anda
{'role': 'system', 'content': 'fileid://{FILE_ID}'},
{'role': 'user', 'content': 'From this product manual, extract all product information and organize it into a standard JSON array. Each object must include the following: model (the product model), name (the product name), and price (the price, with currency symbols and commas removed).'}
],
# Contoh kode ini menggunakan keluaran streaming untuk menunjukkan proses output model secara jelas. Untuk contoh keluaran non-streaming, lihat https://www.alibabacloud.com/help/en/model-studio/user-guide/text-generation
stream=True,
stream_options={"include_usage": True}
)
full_content = ""
for chunk in completion:
if chunk.choices and chunk.choices[0].delta.content:
full_content += chunk.choices[0].delta.content
print(chunk.model_dump())
print(full_content)
except BadRequestError as e:
print(f"Error message: {e}")
print("For more information, see https://www.alibabacloud.com/help/en/model-studio/developer-reference/error-code")import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.http.StreamResponse;
import com.openai.models.chat.completions.*;
public class Main {
public static void main(String[] args) {
// Buat klien dan gunakan API key dari variabel lingkungan
OpenAIClient client = OpenAIOkHttpClient.builder()
// Jika Anda belum menyetel variabel lingkungan, ganti baris berikut dengan Kunci API Studio Model Anda: .apiKey("sk-xxx");
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
// URL berikut berlaku untuk wilayah China North 2 (Beijing); URL berbeda untuk wilayah lain.
.baseUrl("https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1")
.build();
ChatCompletionCreateParams chatParams = ChatCompletionCreateParams.builder()
.addSystemMessage("You are a helpful assistant.")
// Ganti '{FILE_ID}' dengan file-id dari skenario Anda
.addSystemMessage("fileid://{FILE_ID}")
.addUserMessage("From this product manual, extract all product information and organize it into a standard JSON array. Each object must include the following: model (the product model), name (the product name), and price (the price, with currency symbols and commas removed).")
.model("qwen-doc-turbo")
.build();
try (StreamResponse<ChatCompletionChunk> streamResponse = client.chat().completions().createStreaming(chatParams)) {
streamResponse.stream().forEach(chunk -> {
String content = chunk.choices().get(0).delta().content().orElse("");
if (!content.isEmpty()) {
System.out.print(content);
}
});
} catch (Exception e) {
System.err.println("Error message: " + e.getMessage());
}
}
# URL berikut berlaku untuk wilayah China North 2 (Beijing); URL berbeda untuk wilayah lain.
}curl --location 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "qwen-doc-turbo",
"messages": [
{"role": "system","content": "You are a helpful assistant."},
{"role": "system","content": "fileid://{FILE_ID}"},
{"role": "user","content": "From this product manual, extract all product information and organize it into a standard JSON array. Each object must include the following: model (the product model), name (the product name), and price (the price, with currency symbols and commas removed)."}
],
"stream": true,
"stream_options": {
"include_usage": true
}
}'Gunakan teks biasa
Anda dapat meneruskan konten file langsung sebagai string alih-alih menggunakan file-id. Untuk menghindari kebingungan, letakkan pesan pengaturan role terlebih dahulu dalam array messages.
Jika konten teks melebihi 9.000 token, gunakan URL file atau ID file sebagai gantinya (karena batasan ukuran body API).
import os
from openai import OpenAI, BadRequestError
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # Jika Anda belum menyetel variabel lingkungan, ganti ini dengan API key Anda
# URL berikut berlaku untuk wilayah China North 2 (Beijing); URL berbeda untuk wilayah lain.
base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)
try:
completion = client.chat.completions.create(
model="qwen-doc-turbo",
messages=[
{'role': 'system', 'content': 'You are a helpful assistant.'},
{'role': 'system', 'content': 'Smart Office Product Manual Version: V2.0 Release Date: January 2024 Table of Contents 1.1 Product Overview...'},
{'role': 'user', 'content': 'From this product manual, extract all product information and organize it into a standard JSON array. Each object must include the following: model (the product model), name (the product name), and price (the price, with currency symbols and commas removed).'}
],
# Contoh kode ini menggunakan keluaran streaming untuk menunjukkan proses output model secara jelas. Untuk contoh keluaran non-streaming, lihat https://www.alibabacloud.com/help/en/model-studio/user-guide/text-generation
stream=True,
stream_options={"include_usage": True}
)
full_content = ""
for chunk in completion:
if chunk.choices and chunk.choices[0].delta.content:
full_content += chunk.choices[0].delta.content
print(chunk.model_dump())
print(full_content)
except BadRequestError as e:
print(f"Error message: {e}")
print("For more information, see https://www.alibabacloud.com/help/en/model-studio/developer-reference/error-code")import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.http.StreamResponse;
import com.openai.models.chat.completions.*;
public class Main {
public static void main(String[] args) {
// Buat klien dan gunakan API key dari variabel lingkungan
OpenAIClient client = OpenAIOkHttpClient.builder()
// Jika Anda belum menyetel variabel lingkungan, ganti baris berikut dengan Kunci API Studio Model Anda: .apiKey("sk-xxx");
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
// URL berikut berlaku untuk wilayah China North 2 (Beijing); URL berbeda untuk wilayah lain.
.baseUrl("https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1")
.build();
ChatCompletionCreateParams chatParams = ChatCompletionCreateParams.builder()
.addSystemMessage("You are a helpful assistant.")
.addSystemMessage("Smart Office Product Manual Version: V2.0 Release Date: January 2024 Table of Contents 1.1 Product Overview...")
.addUserMessage("From this product manual, extract all product information and organize it into a standard JSON array. Each object must include the following: model (the product model), name (the product name), and price (the price, with currency symbols and commas removed).")
.model("qwen-doc-turbo")
.build();
try (StreamResponse<ChatCompletionChunk> streamResponse = client.chat().completions().createStreaming(chatParams)) {
streamResponse.stream().forEach(chunk -> {
String content = chunk.choices().get(0).delta().content().orElse("");
if (!content.isEmpty()) {
System.out.print(content);
}
});
} catch (Exception e) {
System.err.println("Error message: " + e.getMessage());
}
}
# URL berikut berlaku untuk wilayah China North 2 (Beijing); URL berbeda untuk wilayah lain.
}curl --location 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "qwen-doc-turbo",
"messages": [
{"role": "system","content": "You are a helpful assistant."},
{"role": "system","content": "Smart Office Product Manual Version: V2.0 Release Date: January 2024 Table of Contents 1.1 Product Overview..."},
{"role": "user","content": "From this product manual, extract all product information and organize it into a standard JSON array. Each object must include the following: model (the product model), name (the product name), and price (the price, with currency symbols and commas removed)."}
],
"stream": true,
"stream_options": {
"include_usage": true
}
}'Harga model
|
Model |
Jendela konteks |
Input maks |
Output maks |
Biaya input |
Biaya output |
Kuota gratis |
|
(Token) |
(Juta token) |
|||||
|
qwen-doc-turbo |
262.144 |
253.952 |
32.768 |
$0,087 |
$0,144 |
Tidak ada kuota gratis |
FAQ
-
Di mana file disimpan setelah diupload melalui antarmuka file kompatibel OpenAI?
File yang diupload melalui antarmuka kompatibel OpenAI disimpan gratis di bucket Model Studio Anda. Untuk menanyakan dan mengelola file, lihat Antarmuka file OpenAI.
-
Saat mengupload menggunakan metode URL file, apa perbedaan antara opsi parameter file_parsing_strategy?
"auto": secara otomatis mengurai berdasarkan konten. "text_only": hanya mengurai teks. "text_and_images": mengurai teks dan gambar (meningkatkan waktu penguraian).
-
Bagaimana cara mengetahui apakah file telah selesai diurai?
Coba mulai percakapan dengan ID file tersebut. Jika file masih dalam proses penguraian, API akan mengembalikan
File parsing in progress, please try again later.— coba lagi setelah jeda. Jika pemanggilan berhasil, file sudah siap. -
Apakah proses penguraian setelah upload file dikenai biaya tambahan?
Penguraian dokumen tidak dikenai biaya.
Referensi API
Untuk parameter input dan output Qwen-Doc-Turbo, lihat Referensi API kompatibel OpenAI atau Referensi API DashScope.
Kode error
Jika pemanggilan model gagal dan mengembalikan pesan error, lihat Kode error untuk penyelesaian.
Batasan
-
Ketergantungan SDK:
-
URL File (doc_url): Hanya mendukung protokol DashScope. Gunakan
DashScope Python SDKatau panggilan HTTP (seperti curl). -
Upload file (file-id): Harus menggunakan SDK kompatibel
OpenAIuntuk upload dan manajemen.
-
-
Upload dan referensi file:
-
URL File (
doc_url): Maksimal 10 URL per permintaan. URL harus dapat diakses publik. -
Upload file (
file-id): Maksimal 150 MB per file. Batas akun: 10.000 file atau total 100 GB (file tidak pernah kedaluwarsa). Setiap permintaan hanya mereferensikan satu file.Permintaan upload gagal jika batas tercapai. Hapus file yang tidak diperlukan untuk membebaskan kuota. Lihat Kompatibel OpenAI - File untuk detailnya.
-
Format yang didukung: TXT, DOC, DOCX, PDF, XLS, XLSX, MD, PPT, PPTX, JPG, JPEG, PNG, GIF, dan BMP.
-
-
API Input:
-
Menggunakan
doc_urlataufile-id: maksimal 262.144 token. -
Teks biasa dalam pesan
user/system: maksimal 9.000 token per pesan.
-
-
Output API:
-
Panjang output maksimum adalah 32.768 token.
-
-
Berbagi file:
-
file-idhanya berfungsi dalam akun yang menghasilkannya — tidak berlaku lintas akun atau dengan kunci API pengguna RAM.
-
-
Batas laju: Lihat Pembatasan laju.