データマイニングモデルは、情報の抽出、コンテンツのモデレーション、データの分類、および要約の生成を行います。汎用チャットモデルが不整合なフォーマットを返したり、情報を誤って抽出したりする可能性があるのとは異なり、構造化データ (JSON など) を迅速かつ正確に出力します。
このドキュメントは、中国 (北京) リージョンにのみ適用されます。モデルを使用するには、中国 (北京) リージョンの API キー を使用する必要があります。
実装ガイド
Qwen-Doc-Turbo は、3 つの方法でファイルから情報を抽出できます。ファイルサイズと種類の制限に関する詳細については、「制限事項」をご参照ください。
前提条件
-
API キーを作成し、API キーを環境変数としてエクスポート済みであること。
-
SDK を使用してモデルを呼び出す場合は、OpenAI SDK または DashScope SDK をインストールしてください。
ファイル URL を渡す方法
ファイル URL を使用して構造化データを抽出します (同時に最大 10 ファイル)。この例では、サンプル製品マニュアル A と サンプル製品マニュアル B ファイルを渡し、抽出された情報を JSON 形式で返すようにモデルにプロンプトを出します。
ファイル URL メソッドは DashScope プロトコルのみをサポートします。DashScope Python SDK または HTTP 呼び出し (curl など) を使用してください。
import os
import dashscope
# これは、中国北部 2 (北京) リージョンの URL です。リージョンごとに URL は異なります。
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'), # 環境変数を設定していない場合は、ここを API キーに置き換えてください
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/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/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"
}
]
}
]
}
}'
ファイル ID を渡す方法
ファイルのアップロード
コードを実行する前に、サンプル製品マニュアル A をダウンロードし、プロジェクトディレクトリに配置します。OpenAI 互換インターフェイス経由でファイルをアップロードして file-id を取得します。アップロード API の詳細については、「API リファレンス」をご参照ください。
Python
import os
from pathlib import Path
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # 環境変数を設定していない場合は、ここを API キーに置き換えてください
# これは、中国北部 2 (北京) リージョンの URL です。リージョンごとに URL は異なります。
base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1", # DashScope サービスの base_url を入力してください
)
file_object = client.files.create(file=Path("Sample Product Manual A.docx"), purpose="file-extract")
# 後続のモデル呼び出しで使用するために file-id を出力します
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) {
// クライアントを作成し、環境変数から API キーを使用します
OpenAIClient client = OpenAIOkHttpClient.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
// これは、中国北部 2 (北京) リージョンの URL です。リージョンごとに URL は異なります。
.baseUrl("https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1")
.build();
// ファイルパスを設定します。必要に応じてパスとファイル名を変更してください。
Path filePath = Paths.get("src/main/java/org/example/Sample Product Manual A.docx");
// ファイルアップロードパラメーターを作成します
FileCreateParams fileParams = FileCreateParams.builder()
.file(filePath)
.purpose(FilePurpose.of("file-extract"))
.build();
// ファイルをアップロードし、file-id を出力します
FileObject fileObject = client.files().create(fileParams);
// 後続のモデル呼び出しで使用するために file-id を出力します
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"'
コードを実行して、アップロードされたファイルの file-id を取得します。
ファイル ID を使用した情報の受け渡しと対話の開始
システムメッセージ (ロール設定メッセージの後) で file-id を渡します。ユーザーメッセージには、ファイルに関するクエリが含まれます。
import os
from openai import OpenAI, BadRequestError
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # 環境変数を設定していない場合は、ここを API キーに置き換えてください
# これは、中国北部 2 (北京) リージョンの URL です。リージョンごとに URL は異なります。
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.'},
# '{FILE_ID}' を実際のシナリオの file-id に置き換えてください
{'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).'}
],
# このコード例では、モデルの出力プロセスを明確に示すためにストリーミング出力を使用しています。非ストリーミング出力の例については、https://www.alibabacloud.com/help/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/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) {
// クライアントを作成し、環境変数から API キーを使用します
OpenAIClient client = OpenAIOkHttpClient.builder()
// 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください: .apiKey("sk-xxx");
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
// これは、中国北部 2 (北京) リージョンの URL です。リージョンごとに URL は異なります。
.baseUrl("https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1")
.build();
ChatCompletionCreateParams chatParams = ChatCompletionCreateParams.builder()
.addSystemMessage("You are a helpful assistant.")
// '{FILE_ID}' を実際のシナリオの file-id に置き換えてください
.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());
}
}
# これは、中国北部 2 (北京) リージョンの URL です。リージョンごとに URL は異なります。
}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
}
}'プレーンテキストを渡す方法
file-id を使用する代わりに、ファイルの内容を文字列として直接渡すことができます。混乱を避けるために、messages 配列の最初にロール設定メッセージを配置してください。
テキストコンテンツが 9,000 トークンを超える場合は、(API ボディサイズの制限により) 代わりにファイル URL またはファイル ID を使用してください。
import os
from openai import OpenAI, BadRequestError
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # 環境変数を設定していない場合は、ここを API キーに置き換えてください
# これは、中国北部 2 (北京) リージョンの URL です。リージョンごとに URL は異なります。
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).'}
],
# このコード例では、モデルの出力プロセスを明確に示すためにストリーミング出力を使用しています。非ストリーミング出力の例については、https://www.alibabacloud.com/help/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"エラーメッセージ: {e}")
print("For more information, see https://www.alibabacloud.com/help/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) {
// クライアントを作成し、環境変数から API キーを使用します
OpenAIClient client = OpenAIOkHttpClient.builder()
// 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください: .apiKey("sk-xxx");
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
// これは、中国北部 2 (北京) リージョンの URL です。リージョンごとに URL は異なります。
.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());
}
}
# これは、中国北部 2 (北京) リージョンの URL です。リージョンごとに URL は異なります。
}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
}
}'モデルの料金
|
機能 |
ファイル URL (推奨) |
ファイル ID |
プレーンテキスト |
|
ファイルソース |
パブリック URL |
ローカルファイル (アップロードが必要) |
文字列として渡す |
|
入力長制限 |
最大 10 ファイル |
1 ファイル |
最大 9,000 トークン |
|
SDK 互換性 |
|
アップロード: |
|
|
主な利点 |
Model Studio へのアップロードは不要です。バッチ呼び出しをサポートします。 |
繰り返しのアップロードを回避します。再利用に最適です。 |
ファイル管理は不要です。 |
|
モデル |
コンテキストウィンドウ |
最大入力 |
最大出力 |
入力コスト |
出力コスト |
無料クォータ |
|
(トークン) |
(百万トークン) |
|||||
|
qwen-doc-turbo |
262,144 |
253,952 |
32,768 |
0.087 ドル |
0.144 ドル |
無料クォータなし |
よくある質問
-
OpenAI 互換ファイルインターフェイスを介してアップロードされたファイルはどこに保存されますか?
OpenAI 互換インターフェイス経由でアップロードされたファイルは、ご利用の Model Studio バケットに無料で保存されます。ファイルのクエリと管理については、「OpenAI ファイルインターフェイス」をご参照ください。
-
ファイル URL メソッドを使用してアップロードする場合、file_parsing_strategy パラメーターのオプションにはどのような違いがありますか?
"auto":コンテンツに基づいて自動的に解析します。"text_only":テキストのみを解析します。"text_and_images":イメージとテキストの両方を解析します (解析時間が増加します)。
-
ファイルの解析が完了したかどうかは、どのように判断できますか?
ファイル ID を使用して会話を開始してみてください。ファイルがまだ解析中の場合、API は
File parsing in progress, please try again later.を返します。この場合は、少し時間をおいてからリトライしてください。呼び出しが成功した場合、ファイルの準備は完了です。 -
ファイルアップロード後の解析プロセスで追加費用は発生しますか?
ドキュメント解析は無料です。
API リファレンス
Qwen-Doc-Turbo の入力および出力パラメーターについては、OpenAI 互換 API リファレンスまたはDashScope API リファレンスをご参照ください。
エラーコード
モデルの呼び出しが失敗し、エラーメッセージが返された場合は、エラーコードをご参照ください。
制限事項
-
SDK の依存関係:
-
ファイル URL (doc_url):DashScope プロトコルのみをサポートします。
DashScope Python SDKまたは HTTP 呼び出し (curl など) を使用してください。 -
ファイルのアップロード (file-id):アップロードと管理には、
OpenAI互換の SDK を使用する必要があります。
-
-
ファイルのアップロードと参照:
-
ファイル URL (
doc_url):リクエストごとに最大 10 個の URL を指定できます。URL はパブリックにアクセス可能である必要があります。 -
ファイルのアップロード (
file-id):ファイルあたり最大 150 MB。アカウントの制限:合計 10,000 ファイルまたは 100 GB (ファイルの有効期限は切れません)。各リクエストで参照できるファイルは 1 つだけです。制限に達すると、アップロードリクエストは失敗します。不要なファイルを削除して、無料クォータを解放してください。詳細については、「OpenAI 互換 - ファイル」をご参照ください。
-
サポートされているフォーマット:TXT、DOC、DOCX、PDF、XLS、XLSX、MD、PPT、PPTX、JPG、JPEG、PNG、GIF、BMP。
-
-
API 入力:
-
doc_urlまたはfile-idを使用する場合:最大 262,144 トークン。 -
user/systemメッセージ内のプレーンテキスト:メッセージあたり最大 9,000 トークン。
-
-
API 出力:
-
最大出力長は 32,768 トークンです。
-
-
ファイル共有:
-
file-idは、生成元のアカウント内でのみ機能します。アカウント間や RAM ユーザーの API キーでは機能しません。
-
-
レート制限:詳細については、「レート制限」をご参照ください。