文檔解析(大模型版)接口可進行通用文檔抽取和理解,從文檔中提取出文本markdown內容等。本文介紹文檔解析(大模型版)API的調用方式。在調用OpenAPI接口前,請先閱讀API使用指南。
調用方式
文檔解析(大模型版)接口為異步接口,需要先調用文檔解析異步提交服務SubmitDocParserJobAdvance或SubmitDocParserJob接口進行異步任務提交,然后調用文檔解析(大模型版)狀態查詢服務QueryDocParserStatus接口進行處理狀態查詢,最后根據處理狀態,調用GetDocParserResult接口進行結果查詢。如下所示為文檔解析(大模型版)使用流程圖:
文檔解析(大模型版)免費額度為每月3000頁,用完即止。若您的免費額度或資源包消耗完畢,系統將默認采用按量付費的后付費計費方式。
當異步任務處理提交后,用戶可以在處理結束后的24小時之內查詢處理結果,超過24小時后將無法查詢到處理結果。
支持的文檔格式:pdf、word、ppt、pptx、xls、xlsx、xlsm和圖片,圖片支持jpg、jpeg、png、bmp、gif,其余格式支持markdown、html、epub、mobi、rtf、txt。
步驟一:調用文檔解析(大模型版)異步提交服務SubmitDocParserJob接口
異步提交服務支持本地文件和url文件兩種方式:
本地文件上傳的異步提交服務接口為:SubmitDocParserJobAdvance接口。
url文件上傳的異步提交服務接口為:SubmitDocParserJob接口。
請求參數
名稱 | 類型 | 必填 | 描述 | 示例值 |
FileUrl | string | 是 | 以文檔url上傳方式調用接口時使用。 單個文檔(支持1.5萬頁及以內且150 MB以內的PDF、Word等文檔,支持20 MB以內的單張圖片)。 | https://example.com/example.pdf |
FileUrlObject | stream | 否 | 以本地文件上傳方式調用接口時使用。 單個文檔(支持1.5萬頁及以內且150 MB以內的PDF、Word等文檔,支持20 MB以內的單張圖片)。 | 本地文件生成的FileInputStream |
FileName | string | 否 | 文件名需帶文件類型后綴,與FileNameExtension二選一。 | example.pdf |
FileNameExtension | string | 否 | 文件類型,與FileName二選一。 | |
FormulaEnhancement | bool | 否 | 開啟公式識別增強選項,默認為False。 | True |
返回參數
名稱 | 類型 | 描述 | 示例值 |
RequestId | string | 請求唯一ID。 | 43A29C77-405E-4DC0-BC55-EE694AD0**** |
Data | object | 返回數據。 | {"Id": "docmind-20240712-b15f****"} |
Id | string | 業務訂單號,用于后續查詢接口進行查詢的唯一標識。 | doc-mind-20220712-b15f**** |
Code | string | 狀態碼。 | 200 |
Message | string | 狀態詳細信息。 | Message |
使用示例
本接口支持本地文件上傳和url文件上傳這兩種調用方式。
本地文件上傳:以Java SDK為例,本地文件上傳調用方式的請求示例代碼如下,調用PDF轉Word異步提交服務用SubmitDocParserJobAdvance接口,通過fileUrlObject參數實現本地文檔上傳。
說明獲取并使用AccessKey信息的方式,可參考SDK概述中不同語言的SDK使用指南。
import com.aliyun.docmind_api20220711.models.*; import com.aliyun.teaopenapi.models.Config; import com.aliyun.docmind_api20220711.Client; import com.aliyun.teautil.models.RuntimeOptions; import java.io.File; import java.io.FileInputStream; public static void main(String[] args) throws Exception { submit(); } public static void submit() throws Exception { // 使用默認憑證初始化Credentials Client。 com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client(); Config config = new Config() // 通過credentials獲取配置中的AccessKey ID .setAccessKeyId(credentialClient.getAccessKeyId()) // 通過credentials獲取配置中的AccessKey Secret .setAccessKeySecret(credentialClient.getAccessKeySecret()); // 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com config.endpoint = "docmind-api.cn-hangzhou.aliyuncs.com"; Client client = new Client(config); // 創建RuntimeObject實例并設置運行參數 RuntimeOptions runtime = new RuntimeOptions(); SubmitDocParserJobAdvanceRequest advanceRequest = new SubmitDocParserJobAdvanceRequest(); File file = new File("D:\\example.pdf"); advanceRequest.fileUrlObject = new FileInputStream(file); advanceRequest.fileName = "example.pdf"; // 發起請求并處理應答或異常。 SubmitDocParserJobResponse response = client.submitDocParserJobAdvance(advanceRequest, runtime); System.out.println(com.alibaba.fastjson.JSON.toJSON(response.getBody())); }
const Client = require('@alicloud/docmind-api20220711'); const Credential = require('@alicloud/credentials'); const Util = require('@alicloud/tea-util'); const fs = require('fs'); const getResult = async () => { // 使用默認憑證初始化Credentials Client const cred = new Credential.default(); const client = new Client.default({ // 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com endpoint: 'docmind-api.cn-hangzhou.aliyuncs.com', // 通過credentials獲取配置中的AccessKey ID accessKeyId: cred.credential.accessKeyId, // 通過credentials獲取配置中的AccessKey Secret accessKeySecret: cred.credential.accessKeySecret, type: 'access_key', regionId: 'cn-hangzhou' }); const advanceRequest = new Client.SubmitDocParserJobAdvanceRequest(); const file = fs.createReadStream('./example.pdf'); advanceRequest.fileUrlObject = file; advanceRequest.fileName = 'example.pdf'; const runtimeObject = new Util.RuntimeOptions({}); const response = await client.submitDocParserJobAdvance(advanceRequest, runtimeObject); return response.body; };
from alibabacloud_docmind_api20220711.client import Client as docmind_api20220711Client from alibabacloud_tea_openapi import models as open_api_models from alibabacloud_docmind_api20220711 import models as docmind_api20220711_models from alibabacloud_tea_util.client import Client as UtilClient from alibabacloud_tea_util import models as util_models from alibabacloud_credentials.client import Client as CredClient if __name__ == '__main__': # 使用默認憑證初始化Credentials Client。 cred=CredClient() config = open_api_models.Config( # 通過credentials獲取配置中的AccessKey ID access_key_id=cred.get_credential().get_access_key_id(), # 通過credentials獲取配置中的AccessKey Secret access_key_secret=cred.get_credential().get_access_key_secret() ) # 訪問的域名 config.endpoint = f'docmind-api.cn-hangzhou.aliyuncs.com' client = docmind_api20220711Client(config) request = docmind_api20220711_models.SubmitDocParserJobAdvanceRequest( # file_url_object : 本地文件流 file_url_object=open("./example.pdf", "rb"), # file_name :文件名稱。名稱必須包含文件類型 file_name='123.pdf', # file_name_extension : 文件后綴格式。與文件名二選一 file_name_extension='pdf' ) runtime = util_models.RuntimeOptions() try: # 復制代碼運行請自行打印 API 的返回值 response = client.submit_doc_parser_job_advance(request, runtime) # API返回值格式層級為 body -> data -> 具體屬性。可根據業務需要打印相應的結果。如下示例為打印返回的業務id格式 # 獲取屬性值均以小寫開頭, print(response.body) except Exception as error: # 如有需要,請打印 error UtilClient.assert_as_string(error.message)
import ( "fmt" "os" openClient "github.com/alibabacloud-go/darabonba-openapi/v2/client" "github.com/alibabacloud-go/docmind-api-20220711/client" "github.com/alibabacloud-go/tea-utils/v2/service" "github.com/aliyun/credentials-go/credentials" ) func submit(){ // 使用默認憑證初始化Credentials Client。 credential, err := credentials.NewCredential(nil) // 通過credentials獲取配置中的AccessKey ID accessKeyId, err := credential.GetAccessKeyId() // 通過credentials獲取配置中的AccessKey Secret accessKeySecret, err := credential.GetAccessKeySecret() // 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com var endpoint string = "docmind-api.cn-hangzhou.aliyuncs.com" config := openClient.Config{AccessKeyId: accessKeyId, AccessKeySecret: accessKeySecret, Endpoint: &endpoint} // 初始化client cli, err := client.NewClient(&config) if err != nil { panic(err) } // 上傳本地文檔調用接口 filename := "D:\\example.pdf" f, err := os.Open(filename) if err != nil { panic(err) } // 初始化接口request request := client.SubmitDocParserJobAdvanceRequest{ FileName: &filename, FileUrlObject: f, } // 創建RuntimeObject實例并設置運行參數 options := service.RuntimeOptions{} response, err := cli.SubmitDocParserJobAdvance(&request, &options) if err != nil { panic(err) } // 打印結果 fmt.Println(response.Body.String()) }
url文件上傳:以Java SDK為例,傳入文檔url調用方式的請求示例代碼如下,調用SubmitDocParserJob接口,通過fileUrl參數實現傳入文檔url。請注意,您傳入的文檔url必須為公網可訪問下載的url地址,無跨域限制,url不帶特殊轉義字符。
說明獲取并使用AccessKey信息的方式,可參考SDK概述中不同語言的SDK使用指南。
import com.aliyun.docmind_api20220711.models.*; import com.aliyun.teaopenapi.models.Config; import com.aliyun.docmind_api20220711.Client; public static void main(String[] args) throws Exception { submit(); } public static void submit() throws Exception { // 使用默認憑證初始化Credentials Client。 com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client(); Config config = new Config() // 通過credentials獲取配置中的AccessKey ID .setAccessKeyId(credentialClient.getAccessKeyId()) // 通過credentials獲取配置中的AccessKey Secret .setAccessKeySecret(credentialClient.getAccessKeySecret()); // 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com config.endpoint = "docmind-api.cn-hangzhou.aliyuncs.com"; Client client = new Client(config); SubmitDocParserJobRequest request = new SubmitDocParserJobRequest(); request.fileName = "example.pdf"; request.fileUrl = "https://example.com/example.pdf"; SubmitDocParserJobResponse response = client.submitDocParserJob(request); System.out.println(com.alibaba.fastjson.JSON.toJSON(response.getBody())); }
const Client = require('@alicloud/docmind-api20220711'); const Credential = require('@alicloud/credentials'); const getResult = async () => { // 使用默認憑證初始化Credentials Client const cred = new Credential.default(); const client = new Client.default({ // 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com endpoint: 'docmind-api.cn-hangzhou.aliyuncs.com', // 通過credentials獲取配置中的AccessKey ID accessKeyId: cred.credential.accessKeyId, // 通過credentials獲取配置中的AccessKey Secret accessKeySecret: cred.credential.accessKeySecret, type: 'access_key', regionId: 'cn-hangzhou' }); const request = new Client.SubmitDocParserJobRequest(); request.fileName = 'example.pdf'; request.fileUrl = 'https://example.com/example.pdf'; const response = await client.submitDocParserJob(request); return response.body; }
from alibabacloud_docmind_api20220711.client import Client as docmind_api20220711Client from alibabacloud_tea_openapi import models as open_api_models from alibabacloud_docmind_api20220711 import models as docmind_api20220711_models from alibabacloud_tea_util.client import Client as UtilClient from alibabacloud_credentials.client import Client as CredClient if __name__ == '__main__': # 使用默認憑證初始化Credentials Client。 cred=CredClient() config = open_api_models.Config( # 通過credentials獲取配置中的AccessKey ID access_key_id=cred.get_credential().get_access_key_id(), # 通過credentials獲取配置中的AccessKey Secret access_key_secret=cred.get_credential().get_access_key_secret() ) # 訪問的域名 config.endpoint = f'docmind-api.cn-hangzhou.aliyuncs.com' client = docmind_api20220711Client(config) request = docmind_api20220711_models.SubmitDocParserJobRequest( # file_url : 文件url地址 file_url='https://example.com/example.pdf', # file_name :文件名稱。名稱必須包含文件類型 file_name='123.pdf', # file_name_extension : 文件后綴格式。與文件名二選一 file_name_extension='pdf' ) try: # 復制代碼運行請自行打印 API 的返回值 response = client.submit_doc_parser_job(request) # API返回值格式層級為 body -> data -> 具體屬性。可根據業務需要打印相應的結果。如下示例為打印返回的業務id格式 # 獲取屬性值均以小寫開頭, print(response.body) except Exception as error: # 如有需要,請打印 error UtilClient.assert_as_string(error.message)
import ( "fmt" openClient "github.com/alibabacloud-go/darabonba-openapi/v2/client" "github.com/alibabacloud-go/docmind-api-20220711/client" "github.com/aliyun/credentials-go/credentials" ) func submit(){ // 使用默認憑證初始化Credentials Client。 credential, err := credentials.NewCredential(nil) // 通過credentials獲取配置中的AccessKey ID accessKeyId, err := credential.GetAccessKeyId() // 通過credentials獲取配置中的AccessKey Secret accessKeySecret, err := credential.GetAccessKeySecret() // 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com var endpoint string = "docmind-api.cn-hangzhou.aliyuncs.com" config := openClient.Config{AccessKeyId: accessKeyId, AccessKeySecret: accessKeySecret, Endpoint: &endpoint} // 初始化client cli, err := client.NewClient(&config) if err != nil { panic(err) } // 文件URL fileURL := "https://example.com/example.pdf" // 文件名 fileName := "example.pdf" // 初始化接口request request := client.SubmitDocParserJobRequest{ FileUrl: &fileURL, FileName: &fileName, } response, err := cli.SubmitDocParserJob(&request) if err != nil { panic(err) } // 打印結果 fmt.Println(response.Body.String()) }
using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using Tea; using Tea.Utils; public static void SubmitUrl() { // 使用默認憑證初始化Credentials Client。 var akCredential = new Aliyun.Credentials.Client(null); AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config { // 通過credentials獲取配置中的AccessKey Secret AccessKeyId = akCredential.GetAccessKeyId(), // 通過credentials獲取配置中的AccessKey Secret AccessKeySecret = akCredential.GetAccessKeySecret(), }; // 訪問的域名 config.Endpoint = "docmind-api.cn-hangzhou.aliyuncs.com"; AlibabaCloud.SDK.Docmind_api20220711.Client client = new AlibabaCloud.SDK.Docmind_api20220711.Client(config); AlibabaCloud.SDK.Docmind_api20220711.Models.SubmitDocParserJobRequest request = new AlibabaCloud.SDK.Docmind_api20220711.Models.SubmitDocParserJobRequest { FileUrl = "https://example.pdf", FileNameExtension = "pdf" }; try { // 復制代碼運行請自行打印 API 的返回值 client.SubmitDocParserJob(request); } catch (TeaException error) { // 如有需要,請打印 error AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message); } catch (Exception _error) { TeaException error = new TeaException(new Dictionary<string, object> { { "message", _error.Message } }); // 如有需要,請打印 error AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message); } }
use AlibabaCloud\SDK\Docmindapi\V20220711\Docmindapi; use AlibabaCloud\SDK\Docmindapi\V20220711\Models\SubmitDocStructureJobRequest; use Darabonba\OpenApi\Models\Config; use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions; use AlibabaCloud\Tea\Exception\TeaUnableRetryError; use AlibabaCloud\Credentials\Credential; // 使用默認憑證初始化Credentials Client。 $bearerToken = new Credential(); $config = new Config(); // 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com $config->endpoint = "docmind-api.cn-hangzhou.aliyuncs.com"; // 通過credentials獲取配置中的AccessKey ID $config->accessKeyId = $bearerToken->getCredential()->getAccessKeyId(); // 通過credentials獲取配置中的AccessKey Secret $config->accessKeySecret = $bearerToken->getCredential()->getAccessKeySecret(); $config->type = "access_key"; $config->regionId = "cn-hangzhou"; $client = new Docmindapi($config); $request = new SubmitDocParserJobRequest(); $runtime = new RuntimeOptions(); $runtime->maxIdleConns = 3; $runtime->connectTimeout = 10000; $runtime->readTimeout = 10000; $request->fileName = "example.pdf"; $request->fileUrl = "https://example.com/example.pdf"; try { $response = $client->submitDocParserJob($request, $runtime); var_dump($response->toMap()); } catch (TeaUnableRetryError $e) { var_dump($e->getMessage()); var_dump($e->getErrorInfo()); var_dump($e->getLastException()); var_dump($e->getLastRequest()); }
返回結果
{
"RequestId": "43A29C77-405E-4DC0-BC55-EE694AD0****",
"Data": {
"Id": "docmind-20240712-b15f****"
}
}
步驟二:調用文檔解析(大模型版)狀態查詢服務QueryDocParserStatus接口
調用查詢接口的入參ID就是前面異步任務提交接口返回的出參ID,查詢結果有Status狀態和NumberOfSuccessfulParsing已處理的模塊數,Status狀態有處理中、處理成功、處理失敗三種情況。
請求參數
名稱 | 類型 | 必填 | 描述 | 示例值 |
Id | string | 是 | 需要查詢的業務訂單號,訂單號從提交接口的返回結果中獲取。 | docmind-20220712-b15f**** |
返回參數
名稱 | 類型 | 描述 | 示例值 |
RequestId | string | 請求唯一ID。 | 43A29C77-405E-4CC0-BC55-EE694AD0**** |
Data | string | 返回數據。 | - |
Status | string | 任務處理完成的狀態。Success表示處理成功,Fail表示處理失敗。 | Success |
NumberOfSuccessfulParsing | integer | 已處理的模塊數。 | 166 |
Tokens | long | 英文單詞數,或中文字數。 | 4429 |
ParagraphCount | integer | 段落數量。 | 91 |
TableCount | integer | 表格數量。當上傳的文檔中存在表格時,該參數會返回對應表格數量,否則不返回該參數。 | 2 |
ImageCount | integer | 圖片數量。當上傳的文檔中存在圖片時,該參數會返回對應圖片數量,否則不返回該參數。 | 0 |
PageCountEstimate | integer | 當前處理的頁碼(頁碼從0開始)。 | 3 |
Code | string | 狀態碼。 | 200 |
Message | string | 詳細信息。 | Message |
訂單狀態Status類型:
Init:訂單處于待處理隊列中。
Processing: 正在解析處理。
Success:文件處理成功,此時NumberOfSuccessfulParsing將不再變化。
Fail:文件處理失敗。
使用示例
以Java SDK為例,調用文檔解析接口的結果查詢類API示例代碼如下:調用接口,通過傳入ID參數查詢流水號。
獲取并使用AccessKey信息的方式,請參見SDK概述中不同語言的SDK使用指南。
import com.aliyun.docmind_api20220711.models.*;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.docmind_api20220711.Client;
public static void main(String[] args) throws Exception {
submit();
}
public static void submit() throws Exception {
// 使用默認憑證初始化Credentials Client。
com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();
Config config = new Config()
// 通過credentials獲取配置中的AccessKey ID
.setAccessKeyId(credentialClient.getAccessKeyId())
// 通過credentials獲取配置中的AccessKey Secret
.setAccessKeySecret(credentialClient.getAccessKeySecret());
// 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com
config.endpoint = "docmind-api.cn-hangzhou.aliyuncs.com";
Client client = new Client(config);
QueryDocParserStatusRequest resultRequest = new QueryDocParserStatusRequest();
resultRequest.id = "docmind-20220902-824b****";
QueryDocParserStatusResponse response = client.queryDocParserStatus(resultRequest);
System.out.println(com.alibaba.fastjson.JSON.toJSON(response.getBody()));
}
const Client = require('@alicloud/docmind-api20220711');
const Credential = require('@alicloud/credentials');
const getResult = async () => {
// 使用默認憑證初始化Credentials Client
const cred = new Credential.default();
const client = new Client.default({
// 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com
endpoint: 'docmind-api.cn-hangzhou.aliyuncs.com',
// 通過credentials獲取配置中的AccessKey ID
accessKeyId: cred.credential.accessKeyId,
// 通過credentials獲取配置中的AccessKey Secret
accessKeySecret: cred.credential.accessKeySecret,
type: 'access_key',
regionId: 'cn-hangzhou'
});
const resultRequest = new Client.QueryDocParserStatusRequest();
resultRequest.id = "docmind-20220902-824b****";
const response = await client.queryDocParserStatus(resultRequest);
return response.body;
}
from typing import List
from alibabacloud_docmind_api20220711.client import Client as docmind_api20220711Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_docmind_api20220711 import models as docmind_api20220711_models
from alibabacloud_tea_util.client import Client as UtilClient
from alibabacloud_credentials.client import Client as CredClient
if __name__ == '__main__':
# 使用默認憑證初始化Credentials Client。
cred=CredClient()
config = open_api_models.Config(
# 通過credentials獲取配置中的AccessKey ID
access_key_id=cred.get_credential().get_access_key_id(),
# 通過credentials獲取配置中的AccessKey Secret
access_key_secret=cred.get_credential().get_access_key_secret()
)
# 訪問的域名
config.endpoint = f'docmind-api.cn-hangzhou.aliyuncs.com'
client = docmind_api20220711Client(config)
request = docmind_api20220711_models.QueryDocParserStatusRequest(
# id : 任務提交接口返回的id
id='docmind-20220902-824b****'
)
try:
# 復制代碼運行請自行打印 API 的返回值
response = client.query_doc_parser_status(request)
# API返回值格式層級為 body -> data -> 具體屬性。可根據業務需要打印相應的結果。獲取屬性值均以小寫開頭
# 獲取返回結果。建議先把response.body.data轉成json,然后再從json里面取具體需要的值。
print(response.body)
except Exception as error:
# 如有需要,請打印 error
UtilClient.assert_as_string(error.message)
import (
"fmt"
openClient "github.com/alibabacloud-go/darabonba-openapi/v2/client"
"github.com/alibabacloud-go/docmind-api-20220711/client"
"github.com/aliyun/credentials-go/credentials"
)
func submit(){
// 使用默認憑證初始化Credentials Client。
credential, err := credentials.NewCredential(nil)
// 通過credentials獲取配置中的AccessKey ID
accessKeyId, err := credential.GetAccessKeyId()
// 通過credentials獲取配置中的AccessKey Secret
accessKeySecret, err := credential.GetAccessKeySecret()
// 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com
var endpoint string = "docmind-api.cn-hangzhou.aliyuncs.com"
config := openClient.Config{AccessKeyId: accessKeyId, AccessKeySecret: accessKeySecret, Endpoint: &endpoint}
// 初始化client
cli, err := client.NewClient(&config)
if err != nil {
panic(err)
}
id := "docmind-20220925-76b1****"
// 調用查詢接口
request := client.QueryDocParserStatusRequest{Id: &id}
response, err := cli.QueryDocParserStatus(&request)
if err != nil {
panic(err)
}
// 打印查詢結果
fmt.Println(response.Body.String())
}
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Tea;
using Tea.Utils;
public static void GetResult()
{
// 使用默認憑證初始化Credentials Client。
var akCredential = new Aliyun.Credentials.Client(null);
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
// 通過credentials獲取配置中的AccessKey Secret
AccessKeyId = akCredential.GetAccessKeyId(),
// 通過credentials獲取配置中的AccessKey Secret
AccessKeySecret = akCredential.GetAccessKeySecret(),
};
// 訪問的域名
config.Endpoint = "docmind-api.cn-hangzhou.aliyuncs.com";
AlibabaCloud.SDK.Docmind_api20220711.Client client = new AlibabaCloud.SDK.Docmind_api20220711.Client(config);
AlibabaCloud.SDK.Docmind_api20220711.Models.QueryDocParserStatusRequest request = new AlibabaCloud.SDK.Docmind_api20220711.Models.QueryDocParserStatusRequest
{
Id = "docmind-20240902-824b****"
};
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
try
{
// 復制代碼運行請自行打印 API 的返回值
client.QueryDocParserStatus(request);
}
catch (TeaException error)
{
// 如有需要,請打印 error
AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
}
catch (Exception _error)
{
TeaException error = new TeaException(new Dictionary<string, object>
{
{ "message", _error.Message }
});
// 如有需要,請打印 error
AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
}
}
use AlibabaCloud\SDK\Docmindapi\V20220711\Docmindapi;
use AlibabaCloud\SDK\Docmindapi\V20220711\Models\GetDocStructureResultRequest;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use AlibabaCloud\Tea\Exception\TeaUnableRetryError;
use AlibabaCloud\Credentials\Credential;
// 使用默認憑證初始化Credentials Client。
$bearerToken = new Credential();
$config = new Config();
// 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com
$config->endpoint = "docmind-api.cn-hangzhou.aliyuncs.com";
// 通過credentials獲取配置中的AccessKey ID
$config->accessKeyId = $bearerToken->getCredential()->getAccessKeyId();
// 通過credentials獲取配置中的AccessKey Secret
$config->accessKeySecret = $bearerToken->getCredential()->getAccessKeySecret();
$config->type = "access_key";
$config->regionId = "cn-hangzhou";
$client = new Docmindapi($config);
$request = new QueryDocParserStatusRequest();
$request->id = "docmind-20220902-824b****";
$runtime = new RuntimeOptions();
$runtime->maxIdleConns = 3;
$runtime->connectTimeout = 10000;
$runtime->readTimeout = 10000;
try {
$response = $client->queryDocParserStatus($request, $runtime);
var_dump($response->toMap());
} catch (TeaUnableRetryError $e) {
var_dump($e->getMessage());
var_dump($e->getErrorInfo());
var_dump($e->getLastException());
var_dump($e->getLastRequest());
}
返回示例:
{
"RequestId": "43A29C77-405E-4DC0-BC55-EE694AD0****",
"Data": {
"Status": "success",
"NumberOfSuccessfulParsing": 93,
"ImageCount": 0,
"PageCountEstimate": 8,
"ParagraphCount": 91,
"TableCount": 2,
"Tokens": 4429
}
}
步驟三:調用文檔解析(大模型版)結果獲取服務GetDocParserResult接口
請求參數
名稱 | 類型 | 必填 | 描述 | 示例值 |
Id | string | 是 | 需要查詢的業務訂單號,訂單號從提交接口的返回結果中獲取。 | docmind-20220712-b15f**** |
LayoutStepSize | integer | 是 |
| 100 |
LayoutNum | integer | 是 |
| 0 |
GetDocParserResult接口中,可通過LayoutNum標記值和LayoutStepSize步長,獲取layouts,即當文檔處理中時,即可獲得已經解析完成的內容;
返回參數
名稱 | 類型 | 描述 | 示例值 |
RequestId | string | 請求唯一ID。 | 43A29C77-405E-4CC0-BC55-EE694AD0**** |
Data | string | 返回數據,文檔解析(大模型版)的解析結果。 | - |
Code | string | 狀態碼。 | 200 |
Message | string | 詳細信息。 | Message |
使用示例
以Java SDK為例,調用文檔解析接口的結果查詢類API示例代碼如下。
import com.aliyun.docmind_api20220711.models.*;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.docmind_api20220711.Client;
public static void main(String[] args) throws Exception {
submit();
}
public static void submit() throws Exception {
// 使用默認憑證初始化Credentials Client。
com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();
Config config = new Config()
// 通過credentials獲取配置中的AccessKey ID
.setAccessKeyId(credentialClient.getAccessKeyId())
// 通過credentials獲取配置中的AccessKey Secret
.setAccessKeySecret(credentialClient.getAccessKeySecret());
// 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com
config.endpoint = "docmind-api.cn-hangzhou.aliyuncs.com";
Client client = new Client(config);
GetDocParserResultRequest resultRequest = new GetDocParserResultRequest();
resultRequest.id = "docmind-20220902-824b****";
resultRequest.layoutStepSize = 10;
resultRequest.layoutNum = 0;
GetDocParserResultResponse response = client.getDocParserResult(resultRequest);
System.out.println(com.alibaba.fastjson.JSON.toJSON(response.getBody()));
}
const Client = require('@alicloud/docmind-api20220711');
const Credential = require('@alicloud/credentials');
const getResult = async () => {
// 使用默認憑證初始化Credentials Client
const cred = new Credential.default();
const client = new Client.default({
// 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com
endpoint: 'docmind-api.cn-hangzhou.aliyuncs.com',
// 通過credentials獲取配置中的AccessKey ID
accessKeyId: cred.credential.accessKeyId,
// 通過credentials獲取配置中的AccessKey Secret
accessKeySecret: cred.credential.accessKeySecret,
type: 'access_key',
regionId: 'cn-hangzhou'
});
const resultRequest = new Client.GetDocParserResultRequest();
resultRequest.id = "docmind-20220902-824b****";
resultRequest.layoutStepSize = 10;
resultRequest.layoutNum = 0;
const response = await client.getDocParserResult(resultRequest);
return response.body;
}
from typing import List
from alibabacloud_docmind_api20220711.client import Client as docmind_api20220711Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_docmind_api20220711 import models as docmind_api20220711_models
from alibabacloud_tea_util.client import Client as UtilClient
from alibabacloud_credentials.client import Client as CredClient
if __name__ == '__main__':
# 使用默認憑證初始化Credentials Client。
cred=CredClient()
config = open_api_models.Config(
# 通過credentials獲取配置中的AccessKey ID
access_key_id=cred.get_credential().get_access_key_id(),
# 通過credentials獲取配置中的AccessKey Secret
access_key_secret=cred.get_credential().get_access_key_secret()
)
# 訪問的域名
config.endpoint = f'docmind-api.cn-hangzhou.aliyuncs.com'
client = docmind_api20220711Client(config)
request = docmind_api20220711_models.GetDocParserResultRequest(
# id : 任務提交接口返回的id
id='docmind-20220902-824b****',
layout_step_size=10,
layout_num=0
)
try:
# 復制代碼運行請自行打印 API 的返回值
response = client.get_doc_parser_result(request)
# API返回值格式層級為 body -> data -> 具體屬性。可根據業務需要打印相應的結果。獲取屬性值均以小寫開頭
# 獲取返回結果。建議先把response.body.data轉成json,然后再從json里面取具體需要的值。
print(response.body)
except Exception as error:
# 如有需要,請打印 error
UtilClient.assert_as_string(error.message)
import (
"fmt"
openClient "github.com/alibabacloud-go/darabonba-openapi/v2/client"
"github.com/alibabacloud-go/docmind-api-20220711/client"
"github.com/aliyun/credentials-go/credentials"
)
func submit(){
// 使用默認憑證初始化Credentials Client。
credential, err := credentials.NewCredential(nil)
// 通過credentials獲取配置中的AccessKey ID
accessKeyId, err := credential.GetAccessKeyId()
// 通過credentials獲取配置中的AccessKey Secret
accessKeySecret, err := credential.GetAccessKeySecret()
// 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com
var endpoint string = "docmind-api.cn-hangzhou.aliyuncs.com"
config := openClient.Config{AccessKeyId: accessKeyId, AccessKeySecret: accessKeySecret, Endpoint: &endpoint}
// 初始化client
cli, err := client.NewClient(&config)
if err != nil {
panic(err)
}
id := "docmind-20220925-76b1****"
layoutStepSize := 10
layoutNum := 0
// 調用查詢接口
request := client.GetDocParserResultRequest{Id: &id}
response, err := cli.GetDocParserResult(&request)
if err != nil {
panic(err)
}
// 打印查詢結果
fmt.Println(response.Body.String())
}
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Tea;
using Tea.Utils;
public static void GetResult()
{
// 使用默認憑證初始化Credentials Client。
var akCredential = new Aliyun.Credentials.Client(null);
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
// 通過credentials獲取配置中的AccessKey Secret
AccessKeyId = akCredential.GetAccessKeyId(),
// 通過credentials獲取配置中的AccessKey Secret
AccessKeySecret = akCredential.GetAccessKeySecret(),
};
// 訪問的域名
config.Endpoint = "docmind-api.cn-hangzhou.aliyuncs.com";
AlibabaCloud.SDK.Docmind_api20220711.Client client = new AlibabaCloud.SDK.Docmind_api20220711.Client(config);
AlibabaCloud.SDK.Docmind_api20220711.Models.GetDocParserResultRequest request = new AlibabaCloud.SDK.Docmind_api20220711.Models.GetDocParserResultRequest
{
Id = "docmind-20240902-824b****",
LayoutStepSize = 10,
LayoutNum = 0
};
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
try
{
// 復制代碼運行請自行打印 API 的返回值
client.GetDocParserResult(request);
}
catch (TeaException error)
{
// 如有需要,請打印 error
AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
}
catch (Exception _error)
{
TeaException error = new TeaException(new Dictionary<string, object>
{
{ "message", _error.Message }
});
// 如有需要,請打印 error
AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
}
}
use AlibabaCloud\SDK\Docmindapi\V20220711\Docmindapi;
use AlibabaCloud\SDK\Docmindapi\V20220711\Models\GetDocStructureResultRequest;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use AlibabaCloud\Tea\Exception\TeaUnableRetryError;
use AlibabaCloud\Credentials\Credential;
// 使用默認憑證初始化Credentials Client。
$bearerToken = new Credential();
$config = new Config();
// 訪問的域名,支持ipv4和ipv6兩種方式,ipv6請使用docmind-api-dualstack.cn-hangzhou.aliyuncs.com
$config->endpoint = "docmind-api.cn-hangzhou.aliyuncs.com";
// 通過credentials獲取配置中的AccessKey ID
$config->accessKeyId = $bearerToken->getCredential()->getAccessKeyId();
// 通過credentials獲取配置中的AccessKey Secret
$config->accessKeySecret = $bearerToken->getCredential()->getAccessKeySecret();
$config->type = "access_key";
$config->regionId = "cn-hangzhou";
$client = new Docmindapi($config);
$request = new GetDocParserResultRequest();
$request->id = "docmind-20220902-824b****";
$request->layoutStepSize = 10;
$request->layoutNum = 0;
$runtime = new RuntimeOptions();
$runtime->maxIdleConns = 3;
$runtime->connectTimeout = 10000;
$runtime->readTimeout = 10000;
try {
$response = $client->getDocParserResult($request, $runtime);
var_dump($response->toMap());
} catch (TeaUnableRetryError $e) {
var_dump($e->getMessage());
var_dump($e->getErrorInfo());
var_dump($e->getLastException());
var_dump($e->getLastRequest());
}
獲取并使用AccessKey信息的方式,請參見SDK概述中不同語言的SDK使用指南。
返回示例:
處理失敗的返回結果
{
"RequestId": "A8EF3A36-1380-1116-A39E-B377BE27****",
"Code": "UrlNotLegal",
"Message": "Failed to process the document. The document url you provided is not legal.",
"HostId": "docmind-api.cn-hangzhou.aliyuncs.com",
"Recommend": "https://next.api.aliyun.com/troubleshoot?q=IDP.UrlNotLegal&product=docmind-api"
}
如果請求處理失敗,會返回失敗Code和詳細原因Message。詳細介紹,請參見錯誤碼。
處理成功的返回結果
{
"Data": {
"layouts": [
{
"firstLinesChars": 0,
"level": 0,
"blocks": [
{
"pos": [
{
"x": 460,
"y": 116
},
{
"x": 984,
"y": 116
},
{
"x": 984,
"y": 172
},
{
"x": 460,
"y": 172
}
],
"text": "PRACTITIONERS’ SECTION"
}
],
"markdownContent": "# PRACTITIONERS’ SECTION \n\n",
"index": 2,
"subType": "doc_title",
"lineHeight": 0,
"text": "PRACTITIONERS’ SECTION",
"alignment": "center",
"type": "title",
"pageNum": 0,
"uniqueId": "3d8ded229371f879eac478dee2574a82"
},
{
"firstLinesChars": 0,
"level": 0,
"blocks": [
{
"pos": [
{
"x": 277,
"y": 192
},
{
"x": 1161,
"y": 192
},
{
"x": 1161,
"y": 236
},
{
"x": 277,
"y": 236
}
],
"text": "RAGGING: A PUBLIC HEALTH PROBLEM IN INDIA"
}
],
"markdownContent": "# RAGGING: A PUBLIC HEALTH PROBLEM IN INDIA \n\n",
"index": 3,
"subType": "doc_subtitle",
"lineHeight": 0,
"text": "RAGGING: A PUBLIC HEALTH PROBLEM IN INDIA",
"alignment": "center",
"type": "title",
"pageNum": 0,
"uniqueId": "44256f2d41419956ff30c6590683217b"
},
{
"firstLinesChars": 0,
"level": 1,
"blocks": [
{
"pos": [
{
"x": 623,
"y": 265
},
{
"x": 815,
"y": 265
},
{
"x": 815,
"y": 297
},
{
"x": 623,
"y": 297
}
],
"text": "RAJESH GARG"
}
],
"markdownContent": "RAJESH GARG \n\n",
"index": 4,
"subType": "para",
"lineHeight": 0,
"text": "RAJESH GARG",
"alignment": "center",
"type": "text",
"pageNum": 0,
"uniqueId": "d0d64505df8cb4d73f80e0f63007bf60"
}
]
},
"RequestId": "7B8CC68D-D498-5EDA-8352-FAF41591D97A"
}
參數說明:
Data | object | 解析結果 |
layouts | array | 版面信息列表。 |
text | string | 文本內容。 |
markdownContent | string | Markdown文本內容。 |
index | int | 版面閱讀順序。 |
uniqueId | string | 版面信息唯一Id。 |
alignment | string | 間距枚舉。 |
pageNum | int | 版面所在頁。 |
level | int | 版面層級(最小層級為0,表示根節點)。 |
type | string | 版面類型(詳見備注版面類型)。 |
subType | string | 版面子類型(詳見備注版面類型)。 |
文檔解析(大模型版)返回結果中,版面的類型及子類型列表如下:
type(類型) | 類型描述 | subType(子類型) | 子類型描述 |
title | 標題 | doc_name | 文檔名稱 |
doc_title | 文檔標題 | ||
doc_subtitle | 文檔副標題 | ||
para_title | 段落標題 | ||
table | 表格 | - | - |
table_name | 表格名 | table_name | 表格標題 |
table_note | 表注 | table_note | 表注 |
multicolumn | 多欄文字 | - | - |
formula | 公式 | formula | 公式 |
contents_title | 目錄標題 | cate_title | 目錄標題 |
contents | 目錄主體 | cate | 目錄主體 |
text | 普通文字 | para | 段落 |
figure | 圖表 | picture | 圖片 |
logo | logo | ||
figure_name | 圖名 | pic_title | 圖片標題 |
figure_note | 圖注 | pic_caption | 圖注 |
foot | 頁腳 | page_footer | 頁腳 |
foot_image | 頁腳圖片 | - | - |
head | 頁眉 | page_header | 頁眉 |
head_image | 頁眉圖片 | - | - |
head_pagenum | 頁眉頁碼 | page | 頁碼 |
foot_pagenum | 頁腳頁碼 | page | 頁碼 |
corner_note | 腳注 | footer_note | 腳注 |
end_note | 尾注 | endnode | 尾注 |
side | 側欄 | sidebar | 側欄 |