API参考

本文档提供了 Bohrium OpenAPI Python SDK 的完整API参考。

客户端类

class bohrium.Bohrium(access_key: str | None = None, app_key: str | None = None, base_url: str | URL | None = None, project_id: str | None = None, timeout: float | Timeout | None = 30.0, max_retries: int | None = 2, http_client: Client | None = None)[源代码]

基类:SyncAPIClient

property default_headers: dict[str, str]
job: resources.Job
uni_parser: resources.UniParser
knowledge_base: resources.KnowledgeBase
paper: resources.Paper
access_key: str
project_id: str | None
class bohrium.AsyncBohrium(*, _version: str | None = None, base_url: str | URL, limits: Limits, max_retries: int = 2, timeout: float | Timeout | None = Timeout(connect=5.0, read=600.0, write=600.0, pool=600.0), custom_headers: Mapping[str, str] | None = None)[源代码]

基类:AsyncAPIClient

class bohrium.AsyncAPIClient(*, _version: str | None = None, base_url: str | URL, limits: Limits, max_retries: int = 2, timeout: float | Timeout | None = Timeout(connect=5.0, read=600.0, write=600.0, pool=600.0), custom_headers: Mapping[str, str] | None = None)[源代码]

基类:BaseClient[AsyncClient]

class bohrium.SyncAPIClient(base_url: str | URL, max_retries: int = 2, timeout: float | Timeout | None = Timeout(connect=5.0, read=600.0, write=600.0, pool=600.0), limits: Limits = Limits(max_connections=1000, max_keepalive_connections=100, keepalive_expiry=5.0), _version: str | None = None, http_client: Client | None = None, custom_headers: Mapping[str, str] | None = None)[源代码]

基类:BaseClient[Client]

close() None[源代码]

Close the underlying HTTPX client.

The client will not be usable after this.

is_closed() bool[源代码]
class bohrium.BaseClient(*, _version: str | None = None, base_url: str | URL, limits: Limits, max_retries: int = 2, timeout: float | Timeout | None = Timeout(connect=5.0, read=600.0, write=600.0, pool=600.0), custom_headers: Mapping[str, str] | None = None)[源代码]

基类:Generic[_HttpxClientT]

property auth_headers: dict[str, str]
close()[源代码]

Close the underlying HTTPX client.

property custom_auth: Auth | None
property default_headers: dict[str, str]
property default_params: dict[str, str]
delete(path: str, headers=None, **kwargs) Response[源代码]

Make a DELETE request.

get(path: str, headers=None, **kwargs) Response[源代码]

Make a GET request.

patch(path: str, json=None, headers=None, **kwargs) Response[源代码]

Make a PATCH request.

platform_headers() Dict[str, str][源代码]
post(path: str, json=None, headers=None, **kwargs) Response[源代码]

Make a POST request.

put(path: str, json=None, headers=None, **kwargs) Response[源代码]

Make a PUT request.

max_retries: int
timeout: float | Timeout | None

主客户端

class bohrium.Bohrium(access_key: str | None = None, app_key: str | None = None, base_url: str | URL | None = None, project_id: str | None = None, timeout: float | Timeout | None = 30.0, max_retries: int | None = 2, http_client: Client | None = None)[源代码]

基类:SyncAPIClient

access_key: str
project_id: str | None
job: resources.Job
sigma_search: resources.SigmaSearch
max_retries: int
timeout: float | Timeout | None
uni_parser: resources.UniParser
knowledge_base: resources.KnowledgeBase
paper: resources.Paper
property default_headers: dict[str, str]

异步客户端

class bohrium.AsyncBohrium(*, _version: str | None = None, base_url: str | URL, limits: Limits, max_retries: int = 2, timeout: float | Timeout | None = Timeout(connect=5.0, read=600.0, write=600.0, pool=600.0), custom_headers: Mapping[str, str] | None = None)[源代码]

基类:AsyncAPIClient

基础客户端类

class bohrium.SyncAPIClient(base_url: str | URL, max_retries: int = 2, timeout: float | Timeout | None = Timeout(connect=5.0, read=600.0, write=600.0, pool=600.0), limits: Limits = Limits(max_connections=1000, max_keepalive_connections=100, keepalive_expiry=5.0), _version: str | None = None, http_client: Client | None = None, custom_headers: Mapping[str, str] | None = None)[源代码]

基类:BaseClient[Client]

is_closed() bool[源代码]
close() None[源代码]

Close the underlying HTTPX client.

The client will not be usable after this.

class bohrium.AsyncAPIClient(*, _version: str | None = None, base_url: str | URL, limits: Limits, max_retries: int = 2, timeout: float | Timeout | None = Timeout(connect=5.0, read=600.0, write=600.0, pool=600.0), custom_headers: Mapping[str, str] | None = None)[源代码]

基类:BaseClient[AsyncClient]

class bohrium.BaseClient(*, _version: str | None = None, base_url: str | URL, limits: Limits, max_retries: int = 2, timeout: float | Timeout | None = Timeout(connect=5.0, read=600.0, write=600.0, pool=600.0), custom_headers: Mapping[str, str] | None = None)[源代码]

基类:Generic[_HttpxClientT]

max_retries: int
timeout: float | Timeout | None
property custom_auth: Auth | None
property auth_headers: dict[str, str]
property default_headers: dict[str, str]
property default_params: dict[str, str]
platform_headers() Dict[str, str][源代码]
get(path: str, headers=None, **kwargs) Response[源代码]

Make a GET request.

post(path: str, json=None, headers=None, **kwargs) Response[源代码]

Make a POST request.

patch(path: str, json=None, headers=None, **kwargs) Response[源代码]

Make a PATCH request.

put(path: str, json=None, headers=None, **kwargs) Response[源代码]

Make a PUT request.

delete(path: str, headers=None, **kwargs) Response[源代码]

Make a DELETE request.

close()[源代码]

Close the underlying HTTPX client.

资源模块

任务管理 (Job)

class bohrium.resources.job.Job(client: Bohrium)[源代码]

基类:SyncAPIResource

create(project_id, name='', group_id=0)[源代码]
create_job(project_id: int, name: str | None = None, group_id: int | None = 0)[源代码]
create_job_group(project_id, job_group_name)[源代码]
delete(job_id)[源代码]
detail(job_id)[源代码]
download(job_id, save_path)[源代码]
insert(**kwargs)[源代码]
kill(job_id)[源代码]
log(job_id, log_file='STDOUTERR', page=-1, page_size=8192)[源代码]
submit(project_id: int, job_name: str, machine_type: str, cmd: str, image_address: str, job_group_id: int = 0, work_dir: str = '', result: str = '', dataset_path: list = [], log_files: list = [], out_files: list = [])[源代码]
terminate(job_id)[源代码]
upload(file_path: str, object_key: str, token: str)[源代码]
uploadr(work_dir, store_path, token)[源代码]
class bohrium.resources.job.AsyncJob(client: AsyncBohrium)[源代码]

基类:AsyncAPIResource

class bohrium.resources.job.Job(client: Bohrium)[源代码]

基类:SyncAPIResource

create(project_id, name='', group_id=0)[源代码]
detail(job_id)[源代码]
submit(project_id: int, job_name: str, machine_type: str, cmd: str, image_address: str, job_group_id: int = 0, work_dir: str = '', result: str = '', dataset_path: list = [], log_files: list = [], out_files: list = [])[源代码]
insert(**kwargs)[源代码]
delete(job_id)[源代码]
terminate(job_id)[源代码]
kill(job_id)[源代码]
log(job_id, log_file='STDOUTERR', page=-1, page_size=8192)[源代码]
create_job(project_id: int, name: str | None = None, group_id: int | None = 0)[源代码]
create_job_group(project_id, job_group_name)[源代码]
upload(file_path: str, object_key: str, token: str)[源代码]
uploadr(work_dir, store_path, token)[源代码]
download(job_id, save_path)[源代码]
class bohrium.resources.job.AsyncJob(client: AsyncBohrium)[源代码]

基类:AsyncAPIResource

通用解析器

class bohrium.resources.uni_parser.UniParser(client: Bohrium)[源代码]

基类:SyncAPIResource

通用解析器相关接口

get_formatted(token: str, return_half: bool = False, content: bool = False, objects: bool = True, pages_dict: bool = False, textual: str = 'markup', table: str = 'markup', molecule: str = 'markup', chart: str = 'markup', figure: str = 'markup', expression: str = 'markup', equation: str = 'markup', molecule_source: bool = True, **kwargs)[源代码]

根据Token索引解析结果并进行指定格式化

get_paragraphs(token: str, **kwargs)[源代码]

根据Token索引分段落的解析结果

get_result(token: str, return_half: bool = False, content: bool = True, objects: bool = True, pages_dict: bool = True, molecule_source: bool = False, **kwargs)[源代码]

根据Token索引解析结果

parse_with_request(request: FileParseRequest | URLParseRequest | ImageParseRequest | ParseResultRequest | ParseFormattedRequest | ParseParagraphsRequest)[源代码]

使用请求对象进行解析或查询

trigger_file_async(file: str | BinaryIO | bytes, lang: str = 'unknown', sync: bool = False, textual: bool = True, table: bool = True, molecule: bool = True, chart: bool = True, figure: bool = False, expression: bool = True, equation: bool = True, pages: List[int] | None = None, admin_debug: bool = False, timeout: int = 1800, table_cls: bool = False, ordering_method: str = 'gap_tree', **kwargs)[源代码]

提交PDF文件进行异步/同步解析

trigger_snip_async(img: str | bytes, lang: str = 'unknown', sync: bool = False, textual: bool = True, table: bool = True, molecule: bool = True, chart: bool = True, figure: bool = False, expression: bool = True, equation: bool = True, pages: List[int] | None = None, admin_debug: bool = False, timeout: int = 1800, table_cls: bool = False, ordering_method: str = 'gap_tree', **kwargs)[源代码]

提交图片或截图进行异步/同步解析

trigger_url_async(url: str, lang: str = 'unknown', sync: bool = False, textual: bool = True, table: bool = True, molecule: bool = True, chart: bool = True, figure: bool = False, expression: bool = True, equation: bool = True, pages: List[int] | None = None, admin_debug: bool = False, timeout: int = 1800, table_cls: bool = False, ordering_method: str = 'gap_tree', **kwargs)[源代码]

提交PDF文件链接进行异步/同步解析

class bohrium.resources.uni_parser.AsyncUniParser(client: AsyncBohrium)[源代码]

基类:AsyncAPIResource

异步通用解析器相关接口

class bohrium.resources.uni_parser.UniParser(client: Bohrium)[源代码]

基类:SyncAPIResource

通用解析器相关接口

trigger_file_async(file: str | BinaryIO | bytes, lang: str = 'unknown', sync: bool = False, textual: bool = True, table: bool = True, molecule: bool = True, chart: bool = True, figure: bool = False, expression: bool = True, equation: bool = True, pages: List[int] | None = None, admin_debug: bool = False, timeout: int = 1800, table_cls: bool = False, ordering_method: str = 'gap_tree', **kwargs)[源代码]

提交PDF文件进行异步/同步解析

trigger_url_async(url: str, lang: str = 'unknown', sync: bool = False, textual: bool = True, table: bool = True, molecule: bool = True, chart: bool = True, figure: bool = False, expression: bool = True, equation: bool = True, pages: List[int] | None = None, admin_debug: bool = False, timeout: int = 1800, table_cls: bool = False, ordering_method: str = 'gap_tree', **kwargs)[源代码]

提交PDF文件链接进行异步/同步解析

trigger_snip_async(img: str | bytes, lang: str = 'unknown', sync: bool = False, textual: bool = True, table: bool = True, molecule: bool = True, chart: bool = True, figure: bool = False, expression: bool = True, equation: bool = True, pages: List[int] | None = None, admin_debug: bool = False, timeout: int = 1800, table_cls: bool = False, ordering_method: str = 'gap_tree', **kwargs)[源代码]

提交图片或截图进行异步/同步解析

get_result(token: str, return_half: bool = False, content: bool = True, objects: bool = True, pages_dict: bool = True, molecule_source: bool = False, **kwargs)[源代码]

根据Token索引解析结果

get_formatted(token: str, return_half: bool = False, content: bool = False, objects: bool = True, pages_dict: bool = False, textual: str = 'markup', table: str = 'markup', molecule: str = 'markup', chart: str = 'markup', figure: str = 'markup', expression: str = 'markup', equation: str = 'markup', molecule_source: bool = True, **kwargs)[源代码]

根据Token索引解析结果并进行指定格式化

get_paragraphs(token: str, **kwargs)[源代码]

根据Token索引分段落的解析结果

parse_with_request(request: FileParseRequest | URLParseRequest | ImageParseRequest | ParseResultRequest | ParseFormattedRequest | ParseParagraphsRequest)[源代码]

使用请求对象进行解析或查询

class bohrium.resources.uni_parser.AsyncUniParser(client: AsyncBohrium)[源代码]

基类:AsyncAPIResource

异步通用解析器相关接口

知识库

class bohrium.resources.knowledge_base.KnowledgeBase(client: Bohrium)[源代码]

基类:SyncAPIResource

知识库相关接口

get_file_tree(folder_id: str, **kwargs)[源代码]

获取单篇切片文件树

hybrid_recall(knowledge_base_id: int, text: str, k: int = 200, keywords: Dict[str, float] | None = None, **kwargs)[源代码]

知识库混合召回

paper_recall(text: str, k: int, papers: List[Dict[str, str]], **kwargs)[源代码]

单篇论文召回

search_by_md5_paper_id(md5: str, paper_id: str = '', page_num: int = 0, page_size: int = 9999, **kwargs)[源代码]

根据md5和paper_id搜索chunk信息

class bohrium.resources.knowledge_base.AsyncKnowledgeBase(client: AsyncBohrium)[源代码]

基类:AsyncAPIResource

异步知识库相关接口

class bohrium.resources.knowledge_base.KnowledgeBase(client: Bohrium)[源代码]

基类:SyncAPIResource

知识库相关接口

hybrid_recall(knowledge_base_id: int, text: str, k: int = 200, keywords: Dict[str, float] | None = None, **kwargs)[源代码]

知识库混合召回

paper_recall(text: str, k: int, papers: List[Dict[str, str]], **kwargs)[源代码]

单篇论文召回

get_file_tree(folder_id: str, **kwargs)[源代码]

获取单篇切片文件树

search_by_md5_paper_id(md5: str, paper_id: str = '', page_num: int = 0, page_size: int = 9999, **kwargs)[源代码]

根据md5和paper_id搜索chunk信息

class bohrium.resources.knowledge_base.AsyncKnowledgeBase(client: AsyncBohrium)[源代码]

基类:AsyncAPIResource

异步知识库相关接口

论文管理

class bohrium.resources.paper.Paper(client: Bohrium)[源代码]

基类:SyncAPIResource

论文相关接口

rag_pass_keyword(type: int, rerank: int, question: str, page_size: int, words: List[str] | None = None, start_time: str | None = None, end_time: str | None = None, **kwargs)[源代码]

论文RAG关键词检索

class bohrium.resources.paper.AsyncPaper(client: AsyncBohrium)[源代码]

基类:AsyncAPIResource

异步论文相关接口

class bohrium.resources.paper.Paper(client: Bohrium)[源代码]

基类:SyncAPIResource

论文相关接口

rag_pass_keyword(type: int, rerank: int, question: str, page_size: int, words: List[str] | None = None, start_time: str | None = None, end_time: str | None = None, **kwargs)[源代码]

论文RAG关键词检索

class bohrium.resources.paper.AsyncPaper(client: AsyncBohrium)[源代码]

基类:AsyncAPIResource

异步论文相关接口

类型定义

任务类型

通用解析器类型

class bohrium.types.uni_parser.FileParseRequest(file: str | BinaryIO | bytes, lang: str = 'unknown', sync: bool = False, textual: bool = True, table: bool = True, molecule: bool = True, chart: bool = True, figure: bool = False, expression: bool = True, equation: bool = True, pages: List[int] | None = None, admin_debug: bool = False, timeout: int = 1800, table_cls: bool = False, ordering_method: str = 'gap_tree', **kwargs)[源代码]

基类:object

文件解析请求

to_dict()[源代码]
class bohrium.types.uni_parser.URLParseRequest(url: str, lang: str = 'unknown', sync: bool = False, textual: bool = True, table: bool = True, molecule: bool = True, chart: bool = True, figure: bool = False, expression: bool = True, equation: bool = True, pages: List[int] | None = None, admin_debug: bool = False, timeout: int = 1800, table_cls: bool = False, ordering_method: str = 'gap_tree', **kwargs)[源代码]

基类:object

URL解析请求

to_dict()[源代码]
class bohrium.types.uni_parser.ImageParseRequest(img: str | bytes, lang: str = 'unknown', sync: bool = False, textual: bool = True, table: bool = True, molecule: bool = True, chart: bool = True, figure: bool = False, expression: bool = True, equation: bool = True, pages: List[int] | None = None, admin_debug: bool = False, timeout: int = 1800, table_cls: bool = False, ordering_method: str = 'gap_tree', **kwargs)[源代码]

基类:object

图片解析请求

to_dict()[源代码]
class bohrium.types.uni_parser.ParseResultRequest(token: str, return_half: bool = False, content: bool = True, objects: bool = True, pages_dict: bool = True, molecule_source: bool = False, **kwargs)[源代码]

基类:object

解析结果查询请求

to_dict()[源代码]
class bohrium.types.uni_parser.ParseFormattedRequest(token: str, return_half: bool = False, content: bool = False, objects: bool = True, pages_dict: bool = False, textual: str = 'markup', table: str = 'markup', molecule: str = 'markup', chart: str = 'markup', figure: str = 'markup', expression: str = 'markup', equation: str = 'markup', molecule_source: bool = True, **kwargs)[源代码]

基类:object

格式化解析结果查询请求

to_dict()[源代码]
class bohrium.types.uni_parser.ParseParagraphsRequest(token: str, **kwargs)[源代码]

基类:object

段落解析结果查询请求

to_dict()[源代码]

知识库类型

class bohrium.types.knowledge_base.HybridRecallRequest(knowledge_base_id: int, text: str, k: int = 200, keywords: Dict[str, float] | None = None, **kwargs)[源代码]

基类:object

知识库混合召回请求

to_dict()[源代码]
class bohrium.types.knowledge_base.PaperRecallRequest(text: str, k: int, papers: List[Dict[str, str]], **kwargs)[源代码]

基类:object

单篇论文召回请求

to_dict()[源代码]
class bohrium.types.knowledge_base.PaperInfo(paper_id: str = '', md5: str = '', **kwargs)[源代码]

基类:object

论文信息

to_dict()[源代码]
class bohrium.types.knowledge_base.ChunkSearchRequest(md5: str, paper_id: str = '', page_num: int = 0, page_size: int = 9999, **kwargs)[源代码]

基类:object

根据md5和paper_id搜索chunk请求

to_dict()[源代码]

论文类型

class bohrium.types.paper.PaperRAGRequest(type: int, rerank: int, question: str, page_size: int, words: List[str] | None = None, start_time: str | None = None, end_time: str | None = None, **kwargs)[源代码]

基类:object

论文RAG检索请求

to_dict()[源代码]

异常类

exception bohrium._exceptions.BadRequestError(message: str, *, response: Response, body: object | None)[源代码]

基类:APIStatusError

status_code: Literal[400] = 400
exception bohrium._exceptions.AuthenticationError(message: str, *, response: Response, body: object | None)[源代码]

基类:APIStatusError

status_code: Literal[401] = 401
exception bohrium._exceptions.PermissionDeniedError(message: str, *, response: Response, body: object | None)[源代码]

基类:APIStatusError

status_code: Literal[403] = 403
exception bohrium._exceptions.NotFoundError(message: str, *, response: Response, body: object | None)[源代码]

基类:APIStatusError

status_code: Literal[404] = 404
exception bohrium._exceptions.ConflictError(message: str, *, response: Response, body: object | None)[源代码]

基类:APIStatusError

status_code: Literal[409] = 409
exception bohrium._exceptions.UnprocessableEntityError(message: str, *, response: Response, body: object | None)[源代码]

基类:APIStatusError

status_code: Literal[422] = 422
exception bohrium._exceptions.RateLimitError(message: str, *, response: Response, body: object | None)[源代码]

基类:APIStatusError

status_code: Literal[429] = 429
exception bohrium._exceptions.InternalServerError(message: str, *, response: Response, body: object | None)[源代码]

基类:APIStatusError

exception bohrium._exceptions.BohriumError[源代码]

基类:Exception

exception bohrium._exceptions.APIStatusError(message: str, *, response: Response, body: object | None)[源代码]

基类:APIError

Raised when an API response has a status code of 4xx or 5xx.

response: Response
status_code: int
request_id: str | None

工具函数

bohrium._utils._utils.lru_cache(*, maxsize: int | None = 128) Callable[[CallableT], CallableT][源代码]

A version of functools.lru_cache that retains the type signature for the wrapped function arguments.

bohrium._utils._logs.setup_logging() None[源代码]