更新readme
This commit is contained in:
@@ -11,6 +11,7 @@ import httpx
|
||||
|
||||
from docutranslate.global_values import USE_PROXY
|
||||
from docutranslate.logger import global_logger
|
||||
from docutranslate.utils.utils import get_httpx_proxies
|
||||
|
||||
MAX_RETRY_COUNT = 2
|
||||
MAX_TOTAL_ERROR_COUNT = 10
|
||||
@@ -87,13 +88,13 @@ class Agent:
|
||||
self.model_id = config.model_id.strip()
|
||||
self.system_prompt = config.system_prompt or ""
|
||||
self.temperature = config.temperature
|
||||
# self.client = httpx.Client(trust_env=False, proxy=None, verify=False)
|
||||
# self.client_async = httpx.AsyncClient(trust_env=False, proxy=None, verify=False)
|
||||
self.client = httpx.Client(verify=False) if USE_PROXY else httpx.Client(trust_env=False, proxy=None,
|
||||
verify=False)
|
||||
self.client_async = httpx.AsyncClient(verify=False) if USE_PROXY else httpx.AsyncClient(trust_env=False,
|
||||
proxy=None,
|
||||
verify=False)
|
||||
if USE_PROXY:
|
||||
self.client = httpx.Client(proxies=get_httpx_proxies(), verify=False)
|
||||
self.client_async = httpx.AsyncClient(proxies=get_httpx_proxies(), verify=False)
|
||||
else:
|
||||
self.client = httpx.Client(trust_env=False, proxy=None, verify=False)
|
||||
self.client_async = httpx.AsyncClient(trust_env=False, proxy=None, verify=False)
|
||||
|
||||
self.max_concurrent = config.max_concurrent
|
||||
self.timeout = config.timeout
|
||||
self.thinking = config.thinking
|
||||
|
||||
@@ -7,7 +7,6 @@ from typing import Hashable
|
||||
import httpx
|
||||
|
||||
from docutranslate.converter.x2md.base import X2MarkdownConverter, X2MarkdownConverterConfig
|
||||
from docutranslate.global_values import USE_PROXY
|
||||
from docutranslate.ir.document import Document
|
||||
from docutranslate.ir.markdown_document import MarkdownDocument
|
||||
from docutranslate.utils.markdown_utils import embed_inline_image_from_zip
|
||||
@@ -30,12 +29,14 @@ timeout = httpx.Timeout(
|
||||
write=200.0, # 写入超时 (发送数据的最长时间)
|
||||
pool=1.0 # 从连接池获取连接的超时时间
|
||||
)
|
||||
if USE_PROXY:
|
||||
client = httpx.Client(timeout=timeout, verify=False)
|
||||
client_async = httpx.AsyncClient(timeout=timeout, verify=False)
|
||||
else:
|
||||
client = httpx.Client(trust_env=False, timeout=timeout, proxy=None, verify=False)
|
||||
client_async = httpx.AsyncClient(trust_env=False, timeout=timeout, proxy=None, verify=False)
|
||||
# if USE_PROXY:
|
||||
# client = httpx.Client(proxies=get_httpx_proxies(), timeout=timeout, verify=False)
|
||||
# client_async = httpx.AsyncClient(proxies=get_httpx_proxies(), timeout=timeout, verify=False)
|
||||
# else:
|
||||
# client = httpx.Client(trust_env=False, timeout=timeout, proxy=None, verify=False)
|
||||
# client_async = httpx.AsyncClient(trust_env=False, timeout=timeout, proxy=None, verify=False)
|
||||
client = httpx.Client(trust_env=False, timeout=timeout, proxy=None, verify=False)
|
||||
client_async = httpx.AsyncClient(trust_env=False, timeout=timeout, proxy=None, verify=False)
|
||||
|
||||
|
||||
class ConverterMineru(X2MarkdownConverter):
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from docutranslate.exporter.txt.base import TXTExporter
|
||||
from docutranslate.exporter.xlsx.base import XlsxExporter
|
||||
from docutranslate.ir.document import Document
|
||||
|
||||
|
||||
@@ -2,5 +2,7 @@ import os
|
||||
|
||||
from .conditional_import import available_packages, conditional_import
|
||||
|
||||
USE_PROXY = True if (os.getenv("DOCUTRANSLATE_USE_PROXY") and os.getenv(
|
||||
"DOCUTRANSLATE_USE_PROXY").lower() == "true") else False
|
||||
USE_PROXY = True if (os.getenv("DOCUTRANSLATE_PROXY_ENABLED") and os.getenv(
|
||||
"DOCUTRANSLATE_PROXY_ENABLED").lower() == "true") else False
|
||||
|
||||
print(f"USE_PROXY:{USE_PROXY}")
|
||||
|
||||
12
docutranslate/utils/utils.py
Normal file
12
docutranslate/utils/utils.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from urllib.request import getproxies
|
||||
|
||||
|
||||
def get_httpx_proxies():
|
||||
https_proxy = getproxies().get("https")
|
||||
http_proxy = getproxies().get("http")
|
||||
proxies = {}
|
||||
if https_proxy:
|
||||
proxies["https://"] = https_proxy
|
||||
if http_proxy:
|
||||
proxies["http://"] = http_proxy
|
||||
return proxies
|
||||
Reference in New Issue
Block a user