Use o recurso de reformulação inteligente de tom para ajustar o tom do texto, aprimorar expressões e reescrever o conteúdo com uma linguagem mais profissional, descontraída ou direta.
Pré-requisitos
Associe um bucket do Object Storage Service (OSS) ao seu projeto do Intelligent Media Management (IMM). Para obter mais informações sobre como associar um projeto do IMM a um bucket do OSS no console do OSS, consulte Introdução. Para associar um projeto do IMM a um bucket por meio de chamada de API, consulte AttachOSSBucket.
Observações de uso
A reformulação inteligente de tom aceita apenas processamento síncrono (x-oss-process).
Use o método POST para enviar solicitações.
Parâmetros
Ação: doc/rephrase
A tabela a seguir descreve os parâmetros.
|
Parâmetro |
Tipo |
Obrigatório |
Descrição |
|
tone |
string |
Sim |
Tom desejado para a reformulação do documento. Valores válidos:
|
|
content |
string |
Sim |
Conteúdo a ser reformulado. Codifique o conteúdo em Base64 seguro para URL. Nota
O tamanho máximo do conteúdo é de 19.500 bytes. |
|
format |
string |
Não |
Modo de retorno da resposta. Valores válidos:
|
A tabela a seguir descreve os parâmetros de resposta.
|
Parâmetro |
Tipo |
Descrição |
|
RequestId |
string |
ID da solicitação. |
|
Output |
struct |
Saída. Nó filho: Text e FinishReason |
|
Text |
string |
Conteúdo reformulado. Nó pai: Output |
|
FinishReason |
string |
Status da tarefa de reformulação. Valores válidos:
Nó pai: Output |
Usar a API RESTful
Ao usar a API RESTful para reformular documentos, especifique o nome do arquivo apenas como espaço reservado. A reformulação inteligente identifica exclusivamente o valor do parâmetro content como o texto a ser reformulado.
Reformular documentos no modo regular
Método de processamento
Arquivo a ser reformulado: example.doc
Texto a ser reformulado: "O Velho e o Mar", de Ernest Hemingway, narra a história de Santiago, um velho pescador, e sua luta épica para capturar um enorme marlim. Esta obra explora profundamente a resistência humana, a perseverança e a batalha contra as forças da natureza. A determinação inabalável e a dignidade de Santiago diante da adversidade atestam a força do espírito humano.
Tom a ser usado: relaxed
Exemplo de solicitação
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_relaxed,content_RXJuZXN0IEhlbWluZ3dheSdzICJUaGUgT2xkIE1hbiBhbmQgdGhlIFNlYSIgaXMgYSB0YWxlIG9mIGFuIG9sZCBmaXNoZXJtYW4sIFNhbnRpYWdvLCBhbmQgaGlzIGVwaWMgc3RydWdnbGUgdG8gY2F0Y2ggYSBnaWFudCBtYXJsaW4uIFRoaXMgc3RvcnkgaXMgYSBwcm9mb3VuZCBleHBsb3JhdGlvbiBvZiBodW1hbiBlbmR1cmFuY2UsIHBlcnNldmVyYW5jZSwgYW5kIHRoZSBiYXR0bGUgYWdhaW5zdCB0aGUgZm9yY2VzIG9mIG5hdHVyZS4gU2FudGlhZ28ncyB1bndhdmVyaW5nIGRldGVybWluYXRpb24gYW5kIGRpZ25pdHkgaW4gdGhlIGZhY2Ugb2YgYWR2ZXJzaXR5IHNlcnZlIGFzIGEgdGVzdGFtZW50IHRvIHRoZSBzdHJlbmd0aCBvZiB0aGUgaHVtYW4gc3Bpcml0Lg==
Exemplo de resposta
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: 67614664D1170E36323E2D22
x-oss-server-time: 2010
Content-Encoding: gzip
{
"RequestId":"67614664D1170E36323E2D22",
"Output":{
"Text":"Ernest Hemingway's \"The Old Man and the Sea\" is a cool little story about an old fisherman named Santiago and his big adventure trying to catch a massive marlin. It’s all about how people keep going even when things get really tough, and how we stand up to nature's challenges with grit and grace. Santiago’s stubborn bravery and his dignity through it all show just how strong the human spirit can be. It’s like, if you ever feel down, just think of this guy battling it out with a huge fish for days!",
"FinishReason":"stop"
}
}
Reformular documentos no modo SSE
Método de processamento
Arquivo a ser reformulado: example.doc
Texto a ser reformulado: "O Velho e o Mar", de Ernest Hemingway, narra a história de Santiago, um velho pescador, e sua luta épica para capturar um enorme marlim. Esta obra explora profundamente a resistência humana, a perseverança e a batalha contra as forças da natureza. A determinação inabalável e a dignidade de Santiago diante da adversidade atestam a força do espírito humano.
Tom a ser usado: relaxed
Formato de resposta: event-stream
Exemplo de solicitação
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_relaxed,format_event-stream,content_RXJuZXN0IEhlbWluZ3dheSdzICJUaGUgT2xkIE1hbiBhbmQgdGhlIFNlYSIgaXMgYSB0YWxlIG9mIGFuIG9sZCBmaXNoZXJtYW4sIFNhbnRpYWdvLCBhbmQgaGlzIGVwaWMgc3RydWdnbGUgdG8gY2F0Y2ggYSBnaWFudCBtYXJsaW4uIFRoaXMgc3RvcnkgaXMgYSBwcm9mb3VuZCBleHBsb3JhdGlvbiBvZiBodW1hbiBlbmR1cmFuY2UsIHBlcnNldmVyYW5jZSwgYW5kIHRoZSBiYXR0bGUgYWdhaW5zdCB0aGUgZm9yY2VzIG9mIG5hdHVyZS4gU2FudGlhZ28ncyB1bndhdmVyaW5nIGRldGVybWluYXRpb24gYW5kIGRpZ25pdHkgaW4gdGhlIGZhY2Ugb2YgYWR2ZXJzaXR5IHNlcnZlIGFzIGEgdGVzdGFtZW50IHRvIHRoZSBzdHJlbmd0aCBvZiB0aGUgaHVtYW4gc3Bpcml0Lg==
Exemplo de resposta
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: 6761463BD5C0693133B15752
x-oss-server-time: 587
id: 0
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Er","FinishReason":"null"}}
id: 1
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest","FinishReason":"null"}}
id: 2
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hem","FinishReason":"null"}}
id: 3
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"","FinishReason":"null"}}
id: 4
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and","FinishReason":"null"}}
id: 5
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is","FinishReason":"null"}}
id: 6
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old","FinishReason":"null"}}
id: 7
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago","FinishReason":"null"}}
id: 8
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure","FinishReason":"null"}}
id: 9
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure trying to catch a","FinishReason":"null"}}
id: 10
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure trying to catch a massive marlin.","FinishReason":"null"}}
id: 11
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure trying to catch a massive marlin. It’s a deep","FinishReason":"null"}}
id: 12
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure trying to catch a massive marlin. It’s a deep dive into how humans","FinishReason":"null"}}
id: 13
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure trying to catch a massive marlin. It’s a deep dive into how humans can push through tough","FinishReason":"null"}}
id: 14
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure trying to catch a massive marlin. It’s a deep dive into how humans can push through tough times, stay strong","FinishReason":"null"}}
id: 15
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure trying to catch a massive marlin. It’s a deep dive into how humans can push through tough times, stay strong, and take on","FinishReason":"null"}}
id: 16
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure trying to catch a massive marlin. It’s a deep dive into how humans can push through tough times, stay strong, and take on nature’s challenges.","FinishReason":"null"}}
id: 17
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure trying to catch a massive marlin. It’s a deep dive into how humans can push through tough times, stay strong, and take on nature’s challenges. Despite everything that comes","FinishReason":"null"}}
id: 18
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure trying to catch a massive marlin. It’s a deep dive into how humans can push through tough times, stay strong, and take on nature’s challenges. Despite everything that comes his way, Santiago","FinishReason":"null"}}
id: 19
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure trying to catch a massive marlin. It’s a deep dive into how humans can push through tough times, stay strong, and take on nature’s challenges. Despite everything that comes his way, Santiago keeps his chin up","FinishReason":"null"}}
id: 20
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure trying to catch a massive marlin. It’s a deep dive into how humans can push through tough times, stay strong, and take on nature’s challenges. Despite everything that comes his way, Santiago keeps his chin up and shows just how","FinishReason":"null"}}
id: 21
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure trying to catch a massive marlin. It’s a deep dive into how humans can push through tough times, stay strong, and take on nature’s challenges. Despite everything that comes his way, Santiago keeps his chin up and shows just how resilient the human spirit","FinishReason":"null"}}
id: 22
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure trying to catch a massive marlin. It’s a deep dive into how humans can push through tough times, stay strong, and take on nature’s challenges. Despite everything that comes his way, Santiago keeps his chin up and shows just how resilient the human spirit can be. It","FinishReason":"null"}}
id: 23
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure trying to catch a massive marlin. It’s a deep dive into how humans can push through tough times, stay strong, and take on nature’s challenges. Despite everything that comes his way, Santiago keeps his chin up and shows just how resilient the human spirit can be. It’s a story that","FinishReason":"null"}}
id: 24
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure trying to catch a massive marlin. It’s a deep dive into how humans can push through tough times, stay strong, and take on nature’s challenges. Despite everything that comes his way, Santiago keeps his chin up and shows just how resilient the human spirit can be. It’s a story that’ll make you cheer","FinishReason":"null"}}
id: 25
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure trying to catch a massive marlin. It’s a deep dive into how humans can push through tough times, stay strong, and take on nature’s challenges. Despite everything that comes his way, Santiago keeps his chin up and shows just how resilient the human spirit can be. It’s a story that’ll make you cheer for the underdog","FinishReason":"null"}}
id: 26
event: Result
data: {"RequestId":"6761463BD5C0693133B15752","Output":{"Text":"Ernest Hemingway’s \"The Old Man and the Sea\" is all about an old fisherman named Santiago and his big adventure trying to catch a massive marlin. It’s a deep dive into how humans can push through tough times, stay strong, and take on nature’s challenges. Despite everything that comes his way, Santiago keeps his chin up and shows just how resilient the human spirit can be. It’s a story that’ll make you cheer for the underdog!","FinishReason":"stop"}}
Usar SDKs do OSS
Os exemplos de código a seguir mostram como reformular um documento com os SDKs do OSS para linguagens de programação comuns. Para usar SDKs de outras linguagens, adapte os parâmetros com base nos códigos fornecidos.
Java
É necessário o OSS SDK for Java V3.17.4 ou posterior.
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 {
// Specify the endpoint of the region in which the bucket is located.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the ID of the Alibaba Cloud region in which the bucket is located. Example: cn-hangzhou.
String region = "cn-hangzhou";
// Obtain a credential from the environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the name of the bucket.
String bucketName = "examplebucket";
// Specify the filename, which is used only as a placeholder. Intelligent document rephrasing does not read the content of the file.
String key ="example.docx";
// Specify the text content to be rephrased.
String content = "yourTxt";
String encodeContent = BinaryUtil.toBase64String(content.getBytes()).replaceAll("\\+","-")
.replaceAll("/","_").replaceAll("=","");
// Create an OSSClient instance.
// Call the shutdown method to release the OSSClient when it is no longer in use.
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);
// Create an intelligent document rephrasing instruction.
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
É necessário o OSS SDK for PHP V2.7.0 ou posterior.
<?php
// Obtain a credential from the environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
$ak = getenv('OSS_ACCESS_KEY_ID');
$sk = getenv('OSS_ACCESS_KEY_SECRET');
// Specify the name of the bucket. Example: examplebucket.
$bucket = 'examplebucket';
// Specify the filename, which is used only as a placeholder. Intelligent document rephrasing does not read the content of the file.
$objectKey = 'example.docx';
// Specify the text content to be rephrased.
$txt = "yourTxt";
$base64url = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($txt));
// Create an intelligent document rephrasing instruction.
$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
É necessário o OSS SDK for Go V3.0.2 ou posterior.
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 a temporary credential from the environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID, OSS_ACCESS_KEY_SECRET, and OSS_SESSION_TOKEN environment variables are configured.
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 name of the bucket. 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 be rephrased.
txt := "yourTxt"
// Create an intelligent document rephrasing instruction.
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. It is used as a placeholder. Intelligent document rephrasing does not read the content of the file.
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)
}