Akıllı belge tonu yeniden ifade etme özelliği, bir belgenin tonunu ayarlar ve içeriği daha profesyonel, rahat veya doğrudan olacak şekilde yeniden ifade eder.
Önkoşullar
Bir Intelligent Media Management (IMM) projesini bir Object Storage Service (OSS) paketine eklemiş olmanız gerekir. OSS konsolunda bir projenin nasıl ekleneceği hakkında daha fazla bilgi için bkz. Başlarken. Bir API işlemi çağırarak bir projenin nasıl ekleneceği hakkında daha fazla bilgi için bkz. AttachOSSBucket.
Kullanım notları
-
Akıllı belge tonu yeniden ifade etme özelliği yalnızca
x-oss-processparametresi kullanılarak eşzamanlı işleme destekler. -
İstekleri POST yöntemiyle gönderin.
-
Anonim erişim reddedilir.
-
Özelliği kullanmak için gerekli izinlere sahip olmanız gerekir. Daha fazla bilgi için bkz. izinler.
Parametreler
Eylem: doc/rephrase
Aşağıdaki tabloda parametreler açıklanmıştır.
|
Parametre |
Tür |
Zorunlu |
Açıklama |
|
tone |
string |
Evet |
Belgeyi yeniden ifade etmek için hedef ton. Geçerli değerler:
|
|
content |
string |
Evet |
Yeniden ifade edilecek içerik. İçerik URL güvenli Base64 kodlamalı olmalıdır. Not
Maksimum uzunluk 19.500 bayttır. |
|
format |
string |
Hayır |
Verileri döndürme yöntemi. Geçerli değerler:
|
Aşağıdaki tabloda yanıt parametreleri açıklanmıştır.
|
Parametre |
Tür |
Açıklama |
|
RequestId |
string |
İsteğin ID'si. |
|
Output |
struct |
Çıktı sonucu. Alt düğümler: Text, FinishReason |
|
Text |
string |
İstek işlenerek elde edilen sonuç. Üst düğüm: Output |
|
FinishReason |
string |
Oluşturma işleminin mevcut durumunu gösterir. Geçerli değerler:
Üst düğüm: Output |
REST API'yi kullanın
REST API'yi kullanarak bir belgeyi yeniden ifade ederken bir dosya adı belirtmeniz gerekir. Dosya adı yalnızca yer tutucu olarak kullanılır. Özellik, yeniden ifade edilecek metin olarak content parametresinin değerini kullanır.
Belgeyi yeniden ifade etmek için normal modu kullanın
İşleme yöntemi
-
İşlenecek dosya: example.doc
-
Yeniden ifade edilecek metin: "Dört Büyük Klasik Roman (Çin edebiyatının Dört Büyük Başyapıtı olarak da bilinir), şu dört klasik Çin bölümlü romanını ifade eder: 'Üç Krallık', 'Batı'ya Yolculuk', 'Su Kıyısı' ve 'Kızıl Odanın Rüyası'."
-
Hedef ton: straightforward
İşleme örneği
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/rephrase,tone_straightforward,content_5Zub5aSn5ZCN6JGX77yM5Y2z5Zub5aSn5bCP6K-05ZCN6JGX77yM5piv5oyH44CK5LiJ5Zu95ryU5LmJ44CL44CB44CK6KW_5ri46K6w44CL44CB44CK5rC05rWS5Lyg44CL44CB44CK57qi5qW85qKm44CLNOmDqOS4reWbveWPpOWFuOeroOWbnuWwj-ivtOOAgg==
Örnek yanıt
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: 65969DD74479D83039EBE00E
x-oss-server-time: 2010
Content-Encoding: gzip
{
"RequestId":"65969DD74479D83039EBE00E",
"Output":{
"Text":"China's Four Great Classical Novels, which are four very famous novels, refer to these four ancient Chinese epic chapter-based novels: 'Romance of the Three Kingdoms', 'Journey to the West', 'Water Margin', and 'Dream of the Red Chamber'.",
"FinishReason":"stop"
}
}
Belgeyi yeniden ifade etmek için SSE kullanın
İşleme yöntemi
-
İşlenecek dosya: example.doc
-
Yeniden ifade edilecek metin: "Dört Büyük Klasik Roman (Çin edebiyatının Dört Büyük Başyapıtı olarak da bilinir), şu dört klasik Çin bölümlü romanını ifade eder: 'Üç Krallık', 'Batı'ya Yolculuk', 'Su Kıyısı' ve 'Kızıl Odanın Rüyası'."
-
Hedef ton: straightforward
-
Yanıt yöntemi: event-stream
İşleme örneği
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/rephrase,tone_straightforward,format_event-stream,content_5Zub5aSn5ZCN6JGX77yM5Y2z5Zub5aSn5bCP6K-05ZCN6JGX77yM5piv5oyH44CK5LiJ5Zu95ryU5LmJ44CL44CB44CK6KW_5ri46K6w44CL44CB44CK5rC05rWS5Lyg44CL44CB44CK57qi5qW85qKm44CLNOmDqOS4reWbveWPpOWFuOeroOWbnuWwj-ivtOOAgg==
Örnek yanıt
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: 65969D744479D83837AEE00E
x-oss-server-time: 587
id: 0
event: Result
data: {"RequestId":"65969D744479D83837AEE00E","Output":{"Text":"China's","FinishReason":"null"}}
id: 1
event: Result
data: {"RequestId":"65969D744479D83837AEE00E","Output":{"Text":"China's Four Great","FinishReason":"null"}}
id: 2
event: Result
data: {"RequestId":"65969D744479D83837AEE00E","Output":{"Text":"China's Four Great Classical","FinishReason":"null"}}
id: 3
event: Result
data: {"RequestId":"65969D744479D83837AEE00E","Output":{"Text":"China's Four Great Classical Novels, which are four","FinishReason":"null"}}
id: 4
event: Result
data: {"RequestId":"65969D744479D83837AEE00E","Output":{"Text":"China's Four Great Classical Novels, which are four very famous novels, refer to 'Romance of the Three","FinishReason":"null"}}
id: 5
event: Result
data: {"RequestId":"65969D744479D83837AEE00E","Output":{"Text":"China's Four Great Classical Novels, which are four very famous novels, refer to 'Romance of the Three Kingdoms' and 'Journey to the West","FinishReason":"null"}}
id: 6
event: Result
data: {"RequestId":"65969D744479D83837AEE00E","Output":{"Text":"China's Four Great Classical Novels, which are four very famous novels, refer to 'Romance of the Three Kingdoms', 'Journey to the West', 'Water Margin', and","FinishReason":"null"}}
id: 7
event: Result
data: {"RequestId":"65969D744479D83837AEE00E","Output":{"Text":"China's Four Great Classical Novels, which are four very famous novels, refer to 'Romance of the Three Kingdoms', 'Journey to the West', 'Water Margin', and 'Dream of the Red Chamber', these four classic ancient Chinese","FinishReason":"null"}}
id: 8
event: Result
data: {"RequestId":"65969D744479D83837AEE00E","Output":{"Text":"China's Four Great Classical Novels, which are four very famous novels, refer to 'Romance of the Three Kingdoms', 'Journey to the West', 'Water Margin', and 'Dream of the Red Chamber', these four classic ancient Chinese epic novels.","FinishReason":"null"}}
id: 9
event: Result
data: {"RequestId":"65969D744479D83837AEE00E","Output":{"Text":"China's Four Great Classical Novels, which are four very famous novels, refer to 'Romance of the Three Kingdoms', 'Journey to the West', 'Water Margin', and 'Dream of the Red Chamber', these four classic ancient Chinese epic novels.","FinishReason":"stop"}}
SDK'leri kullanın
Aşağıdaki kod örnekleri, yaygın yazılım geliştirme kitlerinde (SDK'ler) parametreleri kullanarak bir belgenin nasıl yeniden ifade edileceğini göstermektedir. Diğer SDK'leri kullanmak için kodu bu örneklere göre uyarlayın.
Java
Java SDK 3.17.4 veya sonraki bir sürümü gereklidir.
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;
public class Demo {
public static void main(String[] args) throws ClientException, com.aliyuncs.exceptions.ClientException {
// Set yourEndpoint to the endpoint of the region where your bucket is located.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the Alibaba Cloud region ID, for example, cn-hangzhou.
String region = "cn-hangzhou";
// Obtain access credentials from environment variables. Before you run this code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the bucket name.
String bucketName = "examplebucket";
// Specify the filename, which is used as a placeholder. The content of this file is not read during intelligent document tone rephrasing.
String key ="example.docx";
// Specify the text content to rephrase.
String content = "yourTxt";
String encodeContent = BinaryUtil.toBase64String(content.getBytes()).replaceAll("\\+","-")
.replaceAll("/","_").replaceAll("=","");
// Create an OSSClient instance.
// When the OSSClient instance is no longer needed, call the shutdown method to release resources.
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);
// Build the processing instruction for intelligent document tone rephrasing.
styleFormatter.format("doc/rephrase,tone_straightforward,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("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message:" + ce.getMessage());
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
}
}
PHP
PHP SDK 2.7.0 veya sonraki bir sürümü gereklidir.
<?php
// Obtain access credentials from environment variables. Before you run this code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
$ak = getenv('OSS_ACCESS_KEY_ID');
$sk = getenv('OSS_ACCESS_KEY_SECRET');
// Specify the bucket name, for example, examplebucket.
$bucket = 'examplebucket';
// Specify the filename, which is used only as a placeholder. The content of this file is not read during intelligent document tone rephrasing.
$objectKey = 'example.docx';
// Specify the text content to rephrase.
$txt = "yourTxt";
$base64url = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($txt));
// Build the instruction for intelligent document tone rephrasing.
$body = sprintf("x-oss-process=doc/rephrase,tone_straightforward,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
Go SDK 3.0.2 veya sonraki bir sürümü gereklidir.
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() {
// Obtain temporary access credentials from environment variables. Before you run this code, make sure that the OSS_ACCESS_KEY_ID, OSS_ACCESS_KEY_SECRET, and OSS_SESSION_TOKEN environment variables are set.
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Create an OSSClient instance.
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)
}
// Specify the bucket name, for example, 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
// Specify the text content to rephrase.
txt := "yourTxt"
// Build the processing instruction for intelligent document tone rephrasing.
data := fmt.Sprintf("x-oss-process=doc/rephrase,tone_straightforward,content_%v", base64.URLEncoding.EncodeToString([]byte(txt)))
// example.docx is a file in the bucket used as a placeholder. The content of this file is not read during intelligent document tone rephrasing.
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)
}