-
Notifications
You must be signed in to change notification settings - Fork 683
Expand file tree
/
Copy pathdeepocr_api.py
More file actions
51 lines (43 loc) · 1.32 KB
/
deepocr_api.py
File metadata and controls
51 lines (43 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from __future__ import annotations
import os
from .gpt import OpenAIWrapper
class DeepOCRAPI(OpenAIWrapper):
"""OpenAI-compatible API wrapper for DeepOCR pipeline endpoint.
Credentials and endpoint are provided only via environment variables:
- DEEPOCR_API_BASE
- DEEPOCR_API_KEY
"""
is_api: bool = True
def __init__(
self,
model: str = "deepocr",
retry: int = 5,
verbose: bool = False,
system_prompt: str | None = None,
temperature: float = 0,
timeout: int = 300,
max_tokens: int = 2048,
img_size: int = -1,
img_detail: str = "high",
**kwargs,
):
api_base = os.getenv("DEEPOCR_API_BASE", "")
api_key = os.getenv("DEEPOCR_API_KEY", "")
if not api_base or not api_key:
raise ValueError(
"DEEPOCR_API_BASE and DEEPOCR_API_KEY must be set in the environment."
)
super().__init__(
model=model,
retry=retry,
key=api_key,
verbose=verbose,
system_prompt=system_prompt,
temperature=temperature,
timeout=timeout,
api_base=api_base,
max_tokens=max_tokens,
img_size=img_size,
img_detail=img_detail,
**kwargs,
)