AS AgentScopeAPI 手册 / API Reference

ExternalApiReader

public class ExternalApiReader extends AbstractChunkingReader
源码Source io/agentscope/core/rag/reader/ExternalApiReader.java:98–448

外部 API 读取器,把私有文档转化为可检索的知识。位于 io.agentscope.core.rag.reader 包,继承自 AbstractChunkingReader。核心成员包括 read、getSupportedFormats、builder。

Generic external API document parsing reader that supports integration with any third-party document parsing service.

This reader is designed to be highly abstract and configurable, adapting to different APIs through functional interfaces:

  • Supports custom HTTP request construction (headers, body, method, etc.)

  • Supports custom response parsing (extracting markdown from JSON/XML/other formats)

  • Supports polling for asynchronous task completion

  • Supports file upload or URL passing

Example usage - Integrating with MinerU Tianshu:

`ExternalApiReader reader = ExternalApiReader.builder()
.requestBuilder((filePath, client) -> {
// Build task submission request
String json = String.format(
"{\"file_path\":\"%s\",\"engine\":\"pipeline\"}",
filePath
);
return new Request.Builder()
.url("http://localhost:8000/api/v1/tasks/submit")
.header("Content-Type", "application/json")
.post(RequestBody.create(json, MediaType.get("application/json")))
.build();
})
.responseParser((response, client) -> {
// Extract task_id from response, then poll for results
String responseBody = response.body().string();
// Parse JSON and poll...
return markdown;
})
.chunkSize(512)
.splitStrategy(SplitStrategy.PARAGRAPH)
.overlapSize(50)
.supportedFormats("pdf", "docx", "pptx", "xlsx", "txt") // Specify supported formats
.build();

List<Document> docs = reader.read(ReaderInput.fromString("path/to/file.pdf")).block();
`

Example usage - Integrating with other APIs:

`ExternalApiReader reader = ExternalApiReader.builder()
.requestBuilder((filePath, client) -> {
// Custom request building logic
byte[] fileBytes = Files.readAllBytes(Paths.get(filePath));
RequestBody body = RequestBody.create(fileBytes, MediaType.get("application/octet-stream"));
return new Request.Builder()
.url("https://api.example.com/parse")
.header("Authorization", "Bearer YOUR_TOKEN")
.post(body)
.build();
})
.responseParser((response, client) -> {
// Custom response parsing logic
return response.body().string();
})
.build();
`

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
RequestBuilder接口interface
定义请求构建器契约的接口。
Request builder functional interface.
ResponseParser接口interface
定义响应解析器契约的接口。
Response parser functional interface.
Builder类class
构建器,用于构建并配置目标实例。
Builder class for constructing ExternalApiReader instances.

方法摘要Method Summary

方法Method说明Description
public Mono<List<Document>> read(ReaderInput input)
设置读取。
Performs the read operation.
public List<String> getSupportedFormats()
获取 `getSupportedFormats`。
Returns the supported formats.
public static Builder builder()
static
创建构建器实例。
Creates Builder instance.

方法详情Method Detail

read

public Mono<List<Document>> read(ReaderInput input)

设置读取。

Performs the read operation.

参数Parameters
名称Name类型Type说明Description
inputReaderInput输入消息(类型 `ReaderInput`)。The input.
返回Returns Mono<List<Document>>
返回Mono>。Returns mono.
源码Source io/agentscope/core/rag/reader/ExternalApiReader.java:136–166

getSupportedFormats

public List<String> getSupportedFormats()

获取 getSupportedFormats。

Returns the supported formats.

返回Returns List<String>
返回列出。Returns list.
源码Source io/agentscope/core/rag/reader/ExternalApiReader.java:168–173

builder

public static Builder builder()
static

创建构建器实例。

Creates Builder instance.

返回Returns Builder
返回当前实例,以支持链式调用。A new `Builder` instance for constructing `ExternalApiReader`
源码Source io/agentscope/core/rag/reader/ExternalApiReader.java:261–263

嵌套类详情Nested Class Detail

RequestBuilder

@FunctionalInterface public interface RequestBuilder

定义请求构建器契约的接口。位于 io.agentscope.core.rag.reader 包。核心成员包括 buildRequest。

Request builder functional interface. Allows users to customize how to build HTTP requests.

ResponseParser

@FunctionalInterface public interface ResponseParser

定义响应解析器契约的接口。位于 io.agentscope.core.rag.reader 包。核心成员包括 parseResponse。

Response parser functional interface. Allows users to customize how to extract markdown from API response.

Builder

public static class Builder

构建器,用于构建并配置目标实例。位于 io.agentscope.core.rag.reader 包。核心成员包括 requestBuilder、responseParser、chunkSize、splitStrategy、overlapSize、connectTimeout。

Builder class for constructing ExternalApiReader instances.

继承成员Inherited Members

基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.