Model penambangan data dirancang untuk ekstraksi informasi, moderasi konten, klasifikasi, dan pembuatan ringkasan. Berbeda dengan model tujuan umum, model ini menghasilkan data terstruktur standar—seperti dalam format JSON—secara cepat dan akurat, sehingga mengatasi masalah model tujuan umum yang sering mengembalikan struktur tanggapan tidak konsisten atau mengekstraksi informasi secara tidak akurat.
Dokumen ini hanya berlaku untuk wilayah Tiongkok (Beijing). Anda harus menggunakan Kunci API dari wilayah Tiongkok (Beijing).
Metode
Qwen-Doc-Turbo mendukung ekstraksi informasi dari file melalui tiga metode berikut:
Melewatkan URL file (Direkomendasikan):
Anda dapat memberikan URL publik file langsung dalam permintaan API sehingga model dapat mengakses dan mengurai kontennya. Metode ini mendukung hingga 10 file dalam satu permintaan dan merupakan satu-satunya metode yang memungkinkan pemrosesan beberapa file sekaligus. Anda dapat menentukan kebijakan penguraian (auto, text_only, atau text_and_images) melalui parameter file_parsing_strategy.
SDK: Metode URL file saat ini hanya mendukung protokol DashScope. Anda dapat menggunakan
DashScope Python SDKatau melakukan panggilan HTTP, misalnya menggunakan curl.
Teruskan ID file:
Anda dapat mengunggah file lokal ke platform Alibaba Cloud Model Studio untuk menghasilkan
file-idunik bagi Akun Alibaba Cloud Anda dan memulai proses penguraian. ID tersebut kemudian dapat digunakan dalam permintaan API selanjutnya. Metode ini kompatibel denganOpenAI SDKdan cocok untuk skenario di mana Anda perlu menggunakan kembali file yang sama atau memproses file lokal.SDK: Anda dapat menggunakan
OpenAI SDKuntuk pengunggahan dan manajemen file. Panggilan model kompatibel baik denganOpenAI SDKmaupunDashScope SDK.
Melewatkan teks biasa:
Untuk konten teks pendek atau sementara, Anda dapat melewatkan teks tersebut langsung sebagai bagian dari pesan
system.SDK: Kompatibel dengan
OpenAI SDKdanDashScope SDK.
Prasyarat
Selesaikan persiapan untuk mendapatkan dan mengonfigurasi Kunci API, serta konfigurasikan Kunci API sebagai Variabel lingkungan (akan diterbitkan dan digabungkan ke Konfigurasi Kunci API).
Jika Anda berencana memanggil model menggunakan kit pengembangan perangkat lunak (SDK), Anda harus menginstal OpenAI SDK atau DashScope SDK.
Melewatkan URL file
Anda dapat mengekstraksi data terstruktur langsung menggunakan URL file dan memproses hingga 10 file dalam satu permintaan. Contoh ini menggunakan file customer_feedback_report.txt.
Metode URL file saat ini hanya mendukung protokol DashScope. Anda dapat menggunakan DashScope Python SDK atau melakukan panggilan HTTP, misalnya menggunakan curl.
import os
import dashscope
response = dashscope.Generation.call(
api_key=os.getenv('DASHSCOPE_API_KEY'), # Jika Anda belum mengonfigurasi variabel lingkungan, ganti ini dengan Kunci API Anda
model='qwen-doc-turbo',
messages=[
{"role": "system","content": "You are a helpful assistant."},
{
"role": "user",
"content": [
{
"type": "text",
"text": "From this customer feedback report, extract all feedback information and organize it into a standard JSON array. Each object must include the following: feedback_id (string), product_name (string), user_name (string), rating_score (an integer from 1 to 5), feedback_type (string), and summary (a Chinese summary of no more than 30 characters)."
},
{
"type": "doc_url",
"doc_url": [
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250910/gokhyx/%E5%AE%A2%E6%88%B7%E5%8F%8D%E9%A6%88%E6%8A%A5%E5%91%8A.txt"
],
"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-codes")
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-codes")
curl --location 'https://dashscope.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 this customer feedback report, extract all feedback information and organize it into a standard JSON array. Each object must include the following: feedback_id (string), product_name (string), user_name (string), rating_score (an integer from 1 to 5), feedback_type (string), and summary (a Chinese summary of no more than 30 characters)."
},
{
"type": "doc_url",
"doc_url": [
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250910/gokhyx/%E5%AE%A2%E6%88%B7%E5%8F%8D%E9%A6%88%E6%8A%A5%E5%91%8A.txt"
],
"file_parsing_strategy": "auto"
}
]
}
]
}
}'
Melewatkan ID file
Unggah file
Contoh ini menggunakan file customer_feedback_report.txt. Unggah file ke bucket aman di Alibaba Cloud Model Studio melalui antarmuka kompatibel OpenAI untuk mendapatkan file-id yang dikembalikan. Untuk informasi lebih lanjut tentang parameter dan metode panggilan antarmuka pengunggahan file, 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 mengonfigurasi variabel lingkungan, ganti ini dengan Kunci API Anda
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1", # Masukkan base_url layanan DashScope
)
file_object = client.files.create(file=Path("customer_feedback_report.txt"), purpose="file-extract")
# Cetak file-id untuk digunakan dalam percakapan 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 Kunci API dari variabel lingkungan
OpenAIClient client = OpenAIOkHttpClient.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
.build();
// Tetapkan path file. Ubah path dan nama file sesuai kebutuhan.
Path filePath = Paths.get("src/main/java/org/example/customer_feedback_report.txt");
// Buat parameter pengunggahan file
FileCreateParams fileParams = FileCreateParams.builder()
.file(filePath)
.purpose(FilePurpose.of("file-extract"))
.build();
// Unggah file dan cetak file-id
FileObject fileObject = client.files().create(fileParams);
// Cetak file-id untuk digunakan dalam percakapan model selanjutnya
System.out.println(fileObject.id());
}
}curl
curl --location --request POST 'https://dashscope.aliyuncs.com/compatible-mode/v1/files' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--form 'file=@"customer_feedback_report.txt"' \
--form 'purpose="file-extract"'Jalankan kode untuk mendapatkan file-id untuk file yang diunggah.
Melewatkan informasi dan memulai percakapan menggunakan ID file
Sisipkan file-id yang diperoleh ke dalam pesan sistem. Pesan sistem pertama menetapkan peran untuk model, sedangkan pesan sistem berikutnya melewatkan file-id. Pesan pengguna berisi kueri spesifik mengenai file tersebut.
import os
from openai import OpenAI, BadRequestError
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # Jika Anda belum mengonfigurasi variabel lingkungan, ganti ini dengan Kunci API Anda
base_url="https://dashscope.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 yang digunakan dalam skenario percakapan aktual Anda
{'role': 'system', 'content': 'fileid://{FILE_ID}'},
{'role': 'user', 'content': 'From this customer feedback report, extract all feedback information and organize it into a standard JSON array. Each object must include the following: feedback_id (string), product_name (string), user_name (string), rating_score (an integer from 1 to 5), feedback_type (string), and summary (a Chinese summary of no more than 30 characters).'}
],
# Contoh kode ini menggunakan keluaran streaming untuk menunjukkan proses keluaran model secara jelas dan intuitif. 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-codes")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 Kunci API dari variabel lingkungan
OpenAIClient client = OpenAIOkHttpClient.builder()
// Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan Kunci API Alibaba Cloud Model Studio Anda: .apiKey("sk-xxx");
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
.build();
ChatCompletionCreateParams chatParams = ChatCompletionCreateParams.builder()
.addSystemMessage("You are a helpful assistant.")
// Ganti '{FILE_ID}' dengan file-id yang digunakan dalam skenario percakapan aktual Anda
.addSystemMessage("fileid://{FILE_ID}")
.addUserMessage("From this customer feedback report, extract all feedback information and organize it into a standard JSON array. Each object must include the following: feedback_id (string), product_name (string), user_name (string), rating_score (an integer from 1 to 5), feedback_type (string), and summary (a Chinese summary of no more than 30 characters).")
.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());
}
}
}curl --location 'https://dashscope.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 customer feedback report, extract all feedback information and organize it into a standard JSON array. Each object must include the following: feedback_id (string), product_name (string), user_name (string), rating_score (an integer from 1 to 5), feedback_type (string), and summary (a Chinese summary of no more than 30 characters)."}
],
"stream": true,
"stream_options": {
"include_usage": true
}
}'Melewatkan teks biasa
Selain melewatkan informasi file menggunakan file-id, Anda juga dapat melewatkan konten file langsung sebagai string. Saat menggunakan metode ini, pastikan informasi pengaturan peran berada di pesan pertama dalam larik messages untuk mencegah model mengacaukan pengaturan peran dengan konten file.
Karena batasan ukuran badan permintaan API, jika konten teks Anda melebihi 9.000 token, lewatkan informasi menggunakan ID file.
import os
from openai import OpenAI, BadRequestError
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # Jika Anda belum mengonfigurasi variabel lingkungan, ganti ini dengan Kunci API Anda
base_url="https://dashscope.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': 'Feedback ID: 001 User: Zhang Wei (vip_zhang@example.com) Product: Model Studio AI-Writer Pro...'},
{'role': 'user', 'content': 'From this customer feedback report, extract all feedback information and organize it into a standard JSON array. Each object must include the following: feedback_id (string), product_name (string), user_name (string), rating_score (an integer from 1 to 5), feedback_type (string), and summary (a Chinese summary of no more than 30 characters).'}
],
# Contoh kode ini menggunakan keluaran streaming untuk menunjukkan proses keluaran model secara jelas dan intuitif. 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-codes")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 Kunci API dari variabel lingkungan
OpenAIClient client = OpenAIOkHttpClient.builder()
// Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan Kunci API Alibaba Cloud Model Studio Anda: .apiKey("sk-xxx");
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
.build();
ChatCompletionCreateParams chatParams = ChatCompletionCreateParams.builder()
.addSystemMessage("You are a helpful assistant.")
.addSystemMessage("Feedback ID: 001 User: Zhang Wei (vip_zhang@example.com) Product: Model Studio AI-Writer Pro...")
.addUserMessage("From this customer feedback report, extract all feedback information and organize it into a standard JSON array. Each object must include the following: feedback_id (string), product_name (string), user_name (string), rating_score (an integer from 1 to 5), feedback_type (string), and summary (a Chinese summary of no more than 30 characters).")
.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());
}
}
}curl --location 'https://dashscope.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": "Feedback ID: 001 User: Zhang Wei (vip_zhang@example.com) Product: Model Studio AI-Writer Pro..."},
{"role": "user","content": "From this customer feedback report, extract all feedback information and organize it into a standard JSON array. Each object must include the following: feedback_id (string), product_name (string), user_name (string), rating_score (an integer from 1 to 5), feedback_type (string), and summary (a Chinese summary of no more than 30 characters)."}
],
"stream": true,
"stream_options": {
"include_usage": true
}
}'Harga model
Nama model | Panjang konteks | Maks input | Maks output | Biaya input | Biaya output | Kuota gratis |
(Token) | (per 1.000.000 token) | |||||
qwen-doc-turbo | 262.144 | 253.952 | 8.192 | $0,087 | Rp0,144 | Tidak ada kuota gratis |
FAQ
Di mana file disimpan setelah diunggah melalui antarmuka file kompatibel OpenAI?
Semua file yang diunggah melalui antarmuka file kompatibel OpenAI disimpan secara gratis di bucket Alibaba Cloud Model Studio di bawah Akun Alibaba Cloud Anda. Untuk informasi lebih lanjut tentang cara menanyakan dan mengelola file yang diunggah, lihat Antarmuka file OpenAI.
Saat mengunggah menggunakan metode URL file, apa perbedaan antara opsi parameter file_parsing_strategy?
Saat strategi penguraian diatur ke "auto", sistem secara otomatis mengurai file berdasarkan isinya. Saat diatur ke "text_only", sistem hanya mengurai konten teks. Saat diatur ke "text_and_images", sistem mengurai semua citra dan konten teks, yang meningkatkan waktu penguraian.
Bagaimana saya bisa menentukan apakah file telah selesai diurai?
Setelah Anda mendapatkan
file-id, Anda dapat mencoba memulai percakapan dengan model menggunakanfile-idtersebut. Jika file belum selesai diurai, sistem mengembalikan kode kesalahan 400 dengan pesan "File parsing in progress, please try again later." Jika panggilan model berhasil dan mengembalikan tanggapan, berarti file telah selesai diurai.Apakah proses penguraian setelah pengunggahan file menimbulkan biaya tambahan?
Penguraian dokumen tidak dikenai biaya.
Referensi API
Untuk informasi lebih lanjut tentang parameter input dan output model Qwen-Doc-Turbo, lihat Detail API Qwen.
Kode kesalahan
Jika panggilan gagal, lihat Pesan kesalahan untuk pemecahan masalah.
Batasan
Dependensi SDK:
URL file (doc_url): Metode URL file saat ini hanya mendukung protokol DashScope. Anda dapat menggunakan
DashScope Python SDKatau melakukan panggilan HTTP, misalnya menggunakan curl.Unggah file (file-id): Operasi pengunggahan dan manajemen file harus menggunakan SDK kompatibel
OpenAI.
Pengunggahan dan referensi file:
URL file (
doc_url): URL file tersebut. Satu permintaan dapat mencakup hingga 10 URL file.Unggah file (
file-id): Ukuran maksimum satu file adalah 150 MB. Setiap Akun Alibaba Cloud dibatasi hingga 10.000 file yang diunggah, dengan ukuran total hingga 100 GB. File yang diunggah tidak kedaluwarsa. Setiap permintaan hanya dapat mereferensikan satu file.Format yang didukung: TXT, DOC, DOCX, PDF, XLS, XLSX, MD, PPT, PPTX, JPG, JPEG, PNG, GIF, dan BMP.
Input API:
Saat melewatkan informasi menggunakan
doc_urlataufile-id, panjang konteks maksimum adalah 262.144 token.Saat memasukkan teks biasa langsung dalam pesan
useratausystem, konten satu pesan dibatasi hingga 9.000 token.
Output API:
Panjang output maksimum adalah 8.192 token.
Berbagi file:
file-idhanya berlaku dalam Akun Alibaba Cloud yang menghasilkannya. ID ini tidak dapat digunakan lintas akun atau dipanggil menggunakan Kunci API Pengguna RAM.
Pembatasan laju: Untuk informasi lebih lanjut tentang kondisi pembatasan laju model, lihat Pembatasan laju.