スマートドキュメント要約は、長いドキュメントをドキュメントの主要なポイントを強調した簡潔な要約に自動的に要約します。 このプロセスにより、読者はドキュメント全体を読む手間を省き、コンテンツをすばやく把握できます。
前提条件
対応する Object Storage Service (OSS) バケットが Intelligent Media Management (IMM) プロジェクトにバインドされています。 OSS コンソールで OSS バケットを IMM プロジェクトにバインドする方法の詳細については、「クイックスタート」をご参照ください。 IMM API を使用して OSS バケットを IMM プロジェクトにバインドする方法の詳細については、「AttachOSSBucket」をご参照ください。
使用上の注意
インテリジェントドキュメント要約は、同期処理 (x-oss-process) のみをサポートします。
インテリジェントドキュメント要約機能を使用するには、POST メソッドを使用してリクエストを送信する必要があります。
匿名アクセスは拒否されます。
この機能を使用するには、必要な権限を持っている必要があります。 詳細については、「権限」をご参照ください。
パラメーター
アクション: doc/summarize
次の表に、インテリジェントドキュメント要約機能を使用するときに指定できるパラメーターを示します。
パラメーター | タイプ | 必須 | 説明 |
content | 文字列 | はい | 要約するコンテンツ。 コンテンツは URL セーフ Base64 でエンコードする必要があります。 説明 コンテンツの長さは最大 19,500 バイトです。 |
format | 文字列 | いいえ | レスポンスを返すモード。 有効な値:
|
次の表に、レスポンスパラメーターを示します。
パラメーター | タイプ | 説明 |
RequestId | 文字列 | リクエスト ID。 |
Output | 構造体 | 出力。 子ノード: Text と FinishReason |
Text | 文字列 | 要約。 親ノード: Output |
FinishReason | 文字列 | 要約タスクのステータス。 有効な値:
親ノード: Output |
RESTful API の使用
RESTful API を使用してドキュメントを要約する場合、ドキュメント名を指定する必要があります。これはプレースホルダーとしてのみ使用されます。 インテリジェントドキュメント要約は、content パラメーターの値のみを要約対象のテキストとして識別します。
通常モードでのドキュメントの要約
処理方法
処理対象のドキュメント: example.doc
要約対象のテキスト: アーネスト・ヘミングウェイの「老人と海」は、老漁師サンチャゴと巨大なカジキを捕まえるための壮大な闘いについての物語です。 この物語は、人間の忍耐力、不屈の精神、そして自然の力との闘いについての深い探求です。 逆境に直面したサンチャゴの揺るぎない決意と尊厳は、人間の精神の強さを証明するものとなっています。
レスポンスフォーマット: JSON
リクエスト例
POST /example.doc?x-oss-process HTTP/1.1
Host: doc-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
x-oss-process=doc/summarize,content__5Zub5aSn5ZCN6JGX77yM6KKr6KqJ5Li65Lit5Zu95paH5a2m5a6d5bqT5Lit55qE55KA55Ko5piO54-g77yM5piv5Lit5Zu95Y-k5Luj5bCP6K-06Im65pyv5beF5bOw55qE6LGh5b6B44CC6L-Z5Zub6YOo5Li-5LiW6Ze75ZCN55qE5bCP6K-05beo6JGX77yM5YiG5Yir5piv572X6LSv5Lit5omA5Yib5L2c55qE5Y6G5Y-y6aKY5p2Q5bCP6K-044CK5LiJ5Zu95ryU5LmJ44CL77yM5ZC05om_5oGp56yU5LiL55qE56We6a2U5aWH5bm75L2c5ZOB44CK6KW_5ri46K6w44CL77yM5pa96ICQ5bq15Yib5L2c55qE6Iux6ZuE5Lyg5aWH5bCP6K-044CK5rC05rWS5Lyg44CL77yM5Lul5Y-K5pu56Zuq6Iq55pKw5YaZ55qE5Lq65oOF5LiW5pWF5LiO5a625peP5YW06KGw55qE57uP5YW45LmL5L2c44CK57qi5qW85qKm44CL44CC44CK5LiJ5Zu95ryU5LmJ44CL5Lul5Lic5rGJ5pyr5bm05Y-K5LiJ5Zu95pe25Luj5Li66IOM5pmv77yM55Sf5Yqo5o-P57uY5LqG576k6ZuE5LqJ6Zy455qE5Y6G5Y-y55S75Y2377yb44CK6KW_5ri46K6w44CL5YiZ5Lul5ZSQ5YOn5biI5b6S5Y-W57uP55qE5pWF5LqL5Li65Li757q_77yM6J6N5ZCI5LqG5aSn6YeP55qE56We6K-d5Lyg6K-05ZKM5rCR6Ze05pWF5LqL77yM5bGV546w5Ye65LiA5bmF55Gw5Li95aWH54m555qE56We6a2U5LiW55WM77yb44CK5rC05rWS5Lyg44CL6K6y6L-w5LqG5YyX5a6L5pyr5bm05qKB5bGx5aW95rGJ5Lus5Y-N5oqX5bCB5bu657uf5rK76ICF55qE5aOu5Li95Y-y6K-X77yM5bGV546w5LqG6I2J6I696Iux6ZuE5Lus55qE6LGq6L-I5rCU5qaC77yb6ICM44CK57qi5qW85qKm44CL5YiZ5piv6YCa6L-H5a-56LS-5a6d546J5Y-K5YW25ZGo5Zu05Lq654mp5ZG96L-Q55qE5rex5YWl5YmW5p6Q77yM5Y-N5pig5LqG5bCB5bu656S-5Lya5pyr5pyf5aSn5a625peP55qE6I2j5p6v5YW06KGw5ZKM56S-5Lya546w5a6e55qE5rex5Yi75o-t56S644CC6L-Z5Zub5aSn5ZCN6JGX77yM5ZCE5YW354m56Imy77yM5ZCE5pyJ5Y2D56eL77yM5LiN5LuF5Zyo5Lit5Zu95paH5a2m5Y-y5LiK55WZ5LiL5LqG5rWT5aKo6YeN5b2p55qE5LiA56yU77yM5pu05Zyo5LiW55WM5paH5a2m6aKG5Z-f5YaF5Lqn55Sf5LqG5rex6L-c5b2x5ZON77yM5oiQ5Li65LqG5Lit5Y2O5paH5YyW5LiN5Y-v5oiW57y655qE6YeN6KaB57uE5oiQ6YOo5YiG44CCレスポンス例
HTTP/1.1 200 OK
Server: AliyunOSS
Date: Thu, 10 Aug 2023 11:09:00 GMT
Content-Type: application/json;charset=UTF-8
Connection: close
Vary: Accept-Encoding
x-oss-request-id: 676144309D4E643133E487D4
x-oss-server-time: 2010
Content-Encoding: gzip
{
"RequestId":"676144309D4E643133E487D4",
"Output":{
"Text":"\"The Old Man and the Sea\" by Ernest Hemingway is a narrative about an elderly fisherman, Santiago, who embarks on an epic journey to catch a massive marlin. The story delves into themes of human endurance, perseverance, and the struggle against nature. Santiago's steadfast resolve and dignity amidst challenges highlight the resilience of the human spirit.",
"FinishReason":"stop"
}
}SSE モードでのドキュメントの要約
処理方法
処理対象のドキュメント: example.doc
要約対象のテキスト: アーネスト・ヘミングウェイの「老人と海」は、老漁師サンチャゴと巨大なカジキを捕まえるための壮大な闘いについての物語です。 この物語は、人間の忍耐力、不屈の精神、そして自然の力との闘いについての深い探求です。 逆境に直面したサンチャゴの揺るぎない決意と尊厳は、人間の精神の強さを証明するものとなっています。
レスポンスフォーマット: event-stream
リクエスト例
POST /example.doc?x-oss-process HTTP/1.1
Host: doc-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
x-oss-process=doc/summarize,format_event-stream,content__5Zub5aSn5ZCN6JGX77yM6KKr6KqJ5Li65Lit5Zu95paH5a2m5a6d5bqT5Lit55qE55KA55Ko5piO54-g77yM5piv5Lit5Zu95Y-k5Luj5bCP6K-06Im65pyv5beF5bOw55qE6LGh5b6B44CC6L-Z5Zub6YOo5Li-5LiW6Ze75ZCN55qE5bCP6K-05beo6JGX77yM5YiG5Yir5piv572X6LSv5Lit5omA5Yib5L2c55qE5Y6G5Y-y6aKY5p2Q5bCP6K-044CK5LiJ5Zu95ryU5LmJ44CL77yM5ZC05om_5oGp56yU5LiL55qE56We6a2U5aWH5bm75L2c5ZOB44CK6KW_5ri46K6w44CL77yM5pa96ICQ5bq15Yib5L2c55qE6Iux6ZuE5Lyg5aWH5bCP6K-044CK5rC05rWS5Lyg44CL77yM5Lul5Y-K5pu56Zuq6Iq55pKw5YaZ55qE5Lq65oOF5LiW5pWF5LiO5a625peP5YW06KGw55qE57uP5YW45LmL5L2c44CK57qi5qW85qKm44CL44CC44CK5LiJ5Zu95ryU5LmJ44CL5Lul5Lic5rGJ5pyr5bm05Y-K5LiJ5Zu95pe25Luj5Li66IOM5pmv77yM55Sf5Yqo5o-P57uY5LqG576k6ZuE5LqJ6Zy455qE5Y6G5Y-y55S75Y2377yb44CK6KW_5ri46K6w44CL5YiZ5Lul5ZSQ5YOn5biI5b6S5Y-W57uP55qE5pWF5LqL5Li65Li757q_77yM6J6N5ZCI5LqG5aSn6YeP55qE56We6K-d5Lyg6K-05ZKM5rCR6Ze05pWF5LqL77yM5bGV546w5Ye65LiA5bmF55Gw5Li95aWH54m555qE56We6a2U5LiW55WM77yb44CK5rC05rWS5Lyg44CL6K6y6L-w5LqG5YyX5a6L5pyr5bm05qKB5bGx5aW95rGJ5Lus5Y-N5oqX5bCB5bu657uf5rK76ICF55qE5aOu5Li95Y-y6K-X77yM5bGV546w5LqG6I2J6I696Iux6ZuE5Lus55qE6LGq6L-I5rCU5qaC77yb6ICM44CK57qi5qW85qKm44CL5YiZ5piv6YCa6L-H5a-56LS-5a6d546J5Y-K5YW25ZGo5Zu05Lq654mp5ZG96L-Q55qE5rex5YWl5YmW5p6Q77yM5Y-N5pig5LqG5bCB5bu656S-5Lya5pyr5pyf5aSn5a625peP55qE6I2j5p6v5YW06KGw5ZKM56S-5Lya546w5a6e55qE5rex5Yi75o-t56S644CC6L-Z5Zub5aSn5ZCN6JGX77yM5ZCE5YW354m56Imy77yM5ZCE5pyJ5Y2D56eL77yM5LiN5LuF5Zyo5Lit5Zu95paH5a2m5Y-y5LiK55WZ5LiL5LqG5rWT5aKo6YeN5b2p55qE5LiA56yU77yM5pu05Zyo5LiW55WM5paH5a2m6aKG5Z-f5YaF5Lqn55Sf5LqG5rex6L-c5b2x5ZON77yM5oiQ5Li65LqG5Lit5Y2O5paH5YyW5LiN5Y-v5oiW57y655qE6YeN6KaB57uE5oiQ6YOo5YiG44CCレスポンス例
HTTP/1.1 200 OK
Server: AliyunOSS
Date: Thu, 10 Aug 2023 11:20:11 GMT
Content-Type: text/event-stream;charset=UTF-8
Transfer-Encoding: chunked
Connection: close
x-oss-request-id: 669F7CE338492236349AF037
x-oss-server-time: 587
id: 0
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The","FinishReason":"null"}}
id: 1
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old","FinishReason":"null"}}
id: 2
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man","FinishReason":"null"}}
id: 3
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man and","FinishReason":"null"}}
id: 4
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man and the Sea\" by","FinishReason":"null"}}
id: 5
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man and the Sea\" by Ernest Hemingway","FinishReason":"null"}}
id: 6
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man and the Sea\" by Ernest Hemingway narrates the story","FinishReason":"null"}}
id: 7
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man and the Sea\" by Ernest Hemingway narrates the story of Santiago, an","FinishReason":"null"}}
id: 8
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man and the Sea\" by Ernest Hemingway narrates the story of Santiago, an elderly fisherman,","FinishReason":"null"}}
id: 9
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man and the Sea\" by Ernest Hemingway narrates the story of Santiago, an elderly fisherman, and his ardu","FinishReason":"null"}}
id: 10
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man and the Sea\" by Ernest Hemingway narrates the story of Santiago, an elderly fisherman, and his arduous journey to catch","FinishReason":"null"}}
id: 11
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man and the Sea\" by Ernest Hemingway narrates the story of Santiago, an elderly fisherman, and his arduous journey to catch a massive marlin","FinishReason":"null"}}
id: 12
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man and the Sea\" by Ernest Hemingway narrates the story of Santiago, an elderly fisherman, and his arduous journey to catch a massive marlin. The narrative del","FinishReason":"null"}}
id: 13
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man and the Sea\" by Ernest Hemingway narrates the story of Santiago, an elderly fisherman, and his arduous journey to catch a massive marlin. The narrative delves into themes of","FinishReason":"null"}}
id: 14
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man and the Sea\" by Ernest Hemingway narrates the story of Santiago, an elderly fisherman, and his arduous journey to catch a massive marlin. The narrative delves into themes of human endurance, perseverance","FinishReason":"null"}}
id: 15
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man and the Sea\" by Ernest Hemingway narrates the story of Santiago, an elderly fisherman, and his arduous journey to catch a massive marlin. The narrative delves into themes of human endurance, perseverance, and the struggle","FinishReason":"null"}}
id: 16
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man and the Sea\" by Ernest Hemingway narrates the story of Santiago, an elderly fisherman, and his arduous journey to catch a massive marlin. The narrative delves into themes of human endurance, perseverance, and the struggle against nature. Santiago","FinishReason":"null"}}
id: 17
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man and the Sea\" by Ernest Hemingway narrates the story of Santiago, an elderly fisherman, and his arduous journey to catch a massive marlin. The narrative delves into themes of human endurance, perseverance, and the struggle against nature. Santiago's steadfast resolve and","FinishReason":"null"}}
id: 18
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man and the Sea\" by Ernest Hemingway narrates the story of Santiago, an elderly fisherman, and his arduous journey to catch a massive marlin. The narrative delves into themes of human endurance, perseverance, and the struggle against nature. Santiago's steadfast resolve and dignity amidst challenges highlight","FinishReason":"null"}}
id: 19
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man and the Sea\" by Ernest Hemingway narrates the story of Santiago, an elderly fisherman, and his arduous journey to catch a massive marlin. The narrative delves into themes of human endurance, perseverance, and the struggle against nature. Santiago's steadfast resolve and dignity amidst challenges highlight the resilience of the","FinishReason":"null"}}
id: 20
event: Result
data: {"RequestId":"669F7CE338492236349AF037","Output":{"Text":"\"The Old Man and the Sea\" by Ernest Hemingway narrates the story of Santiago, an elderly fisherman, and his arduous journey to catch a massive marlin. The narrative delves into themes of human endurance, perseverance, and the struggle against nature. Santiago's steadfast resolve and dignity amidst challenges highlight the resilience of the human spirit.","FinishReason":"stop"}}OSS SDK の使用
次のサンプルコードは、一般的なプログラミング言語の Object Storage Service (OSS) SDK を使用してドキュメントを要約する方法の例を示しています。 他のプログラミング言語の OSS SDK を使用してドキュメントを要約する場合は、次のサンプルコードに基づいてパラメーターを変更してください。
Java
OSS SDK for Java V3.17.4 以降が必要です。
import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.common.utils.BinaryUtil;
import com.aliyun.oss.common.utils.IOUtils;
import com.aliyun.oss.model.GenericResult;
import com.aliyun.oss.model.ProcessObjectRequest;
import java.io.IOException;
import java.util.Formatter;
publicclass Demo {
public static void main(String[] args) throws ClientException, com.aliyuncs.exceptions.ClientException {
// バケットが配置されているリージョンのエンドポイントを指定します。
String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
// バケットが配置されている Alibaba Cloud リージョンの ID を指定します。 例: cn-hangzhou。
String region = "cn-hangzhou";
// 環境変数からアクセス認証情報を取得します。 サンプルコードを実行する前に、OSS_ACCESS_KEY_ID および OSS_ACCESS_KEY_SECRET 環境変数が設定されていることを確認してください。
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// バケットの名前を指定します。
String bucketName = "examplebucket";
// ドキュメントオブジェクトの名前を指定します。これはプレースホルダーとしてのみ使用されます。 インテリジェントドキュメント要約は、ドキュメントのコンテンツを読み取りません。
String key ="example.docx";
// 要約するテキストコンテンツを指定します。
String content = "yourContent";
String encodeContent = BinaryUtil.toBase64String(content.getBytes()).replaceAll("\\+","-")
.replaceAll("/","_").replaceAll("=","");
// OSSClient インスタンスを作成します。
// OSSClient が不要になったら、shutdown メソッドを呼び出してリソースを解放します。
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
StringBuilder sbStyle = new StringBuilder();
Formatter styleFormatter = new Formatter(sbStyle);
// インテリジェントドキュメント要約の処理命令を作成します。
styleFormatter.format("doc/summarize,content_%s",
encodeContent);
System.out.println(sbStyle.toString());
ProcessObjectRequest request = new ProcessObjectRequest(bucketName, key, sbStyle.toString());
GenericResult processResult = ossClient.processObject(request);
String json = IOUtils.readStreamAsString(processResult.getResponse().getContent(), "UTF-8");
processResult.getResponse().getContent().close();
System.out.println(json);
} catch (OSSException oe) {
System.out.println("OSSException が発生しました。これは、リクエストが OSS に到達しましたが、"
+ "何らかの理由でエラーレスポンスで拒否されたことを意味します。");
System.out.println("エラーメッセージ:" + oe.getErrorMessage());
System.out.println("エラーコード:" + oe.getErrorCode());
System.out.println("リクエスト ID:" + oe.getRequestId());
System.out.println("ホスト ID:" + oe.getHostId());
} catch (ClientException ce) {
System.out.println("ClientException が発生しました。これは、クライアントが OSS と通信しようとしているときに、"
+ "ネットワークにアクセスできないなど、重大な内部問題が発生したことを意味します。");
System.out.println("エラーメッセージ:" + ce.getMessage());
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
}
}
PHP
OSS SDK for PHP V2.7.0 以降が必要です。
<?php
// 環境変数からアクセス認証情報を取得します。 サンプルコードを実行する前に、OSS_ACCESS_KEY_ID および OSS_ACCESS_KEY_SECRET 環境変数が設定されていることを確認してください。
$ak = getenv('OSS_ACCESS_KEY_ID');
$sk = getenv('OSS_ACCESS_KEY_SECRET');
// バケットの名前を指定します。 例: examplebucket。
$bucket = 'examplebucket';
// ドキュメントオブジェクトの名前を指定します。これはプレースホルダーとしてのみ使用されます。 インテリジェントドキュメント要約は、ドキュメントのコンテンツを読み取りません。
$objectKey = 'example.docx';
// 要約するテキストコンテンツを指定します。
$txt = "yourTxt";
$base64url = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($txt));
// インテリジェントドキュメント要約の処理命令を作成します。
$body = sprintf("x-oss-process=doc/summarize,content_%s", $base64url);
$httpVerb = 'POST';
$contentMd5 = base64_encode(md5($body, true));
$contentType = '';
$date = gmdate('D, d M Y H:i:s T');
$stringToSign = $httpVerb . "\n" . $contentMd5 . "\n" . $contentType . "\n" . $date . "\n" . "/{$bucket}/{$objectKey}?x-oss-process";
$signature = base64_encode(hash_hmac('sha1', $stringToSign, $sk, true));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://{$bucket}.oss-cn-hangzhou.aliyuncs.com/{$objectKey}?x-oss-process");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Date: ' . $date,
'Authorization: OSS ' . $ak . ':' . $signature,
'Content-Type: ' . $contentType,
'Content-Md5:' . $contentMd5,
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($response === false) {
echo "Error: " . curl_error($ch);
} else {
if ($httpcode == 200) {
var_dump($response);
} else {
echo "Error: HTTP code " . $httpcode;
}
}Go
OSS SDK for Go V3.0.2 以降が必要です。
package main
import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
"os"
"strings"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
type TextData struct {
RequestId string `json:"RequestId"`
Output struct {
Text string `json:"Text"`
FinishReason string `json:"FinishReason"`
} `json:"Output"`
}
func main() {
// 環境変数から一時的なアクセス認証情報を取得します。 サンプルコードを実行する前に、OSS_ACCESS_KEY_ID、OSS_ACCESS_KEY_SECRET、および OSS_SESSION_TOKEN 環境変数が設定されていることを確認してください。
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// OSSClient インスタンスを作成します。
client, err := oss.New("https://oss-cn-hangzhou.aliyuncs.com", "", "", oss.SetCredentialsProvider(&provider), oss.AuthVersion(oss.AuthV4), oss.Region("cn-hangzhou"))
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// バケットの名前を指定します。 例: examplebucket。
bucketName := "examplebucket"
bucket, err := client.Bucket(bucketName)
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
params := make(map[string]interface{})
params["x-oss-process"] = nil
// 要約するテキストコンテンツを指定します。
txt := "yourTxt"
// インテリジェントドキュメント要約の処理命令を作成します。
data := fmt.Sprintf("x-oss-process=doc/summarize,content_%v", base64.URLEncoding.EncodeToString([]byte(txt)))
// example.docx はバケット内のドキュメントです。 プレースホルダーとして使用されます。 インテリジェントドキュメント要約は、ドキュメントのコンテンツを読み取りません。
response, err := bucket.Do("POST", "example.docx", params, nil, strings.NewReader(data), nil)
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
defer response.Body.Close()
jsonData, err := io.ReadAll(response.Body)
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
var text TextData
err = json.Unmarshal(jsonData, &text)
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
fmt.Printf("RequestId:%v\n", text.RequestId)
fmt.Printf("Text:%v\n", text.Output.Text)
fmt.Printf("FinishReason:%v\n", text.Output.FinishReason)
}