Explorar el Código

修改token位置

hellofinch hace 1 año
padre
commit
b3ae029ab5
Se han modificado 3 ficheros con 5 adiciones y 7 borrados
  1. 1 1
      README.md
  2. 1 1
      README_zh-CN.md
  3. 3 5
      pdf2zh/translator.py

+ 1 - 1
README.md

@@ -194,7 +194,7 @@ The table below outlines the required [environment variables](https://chatgpt.co
 |**Google (Default)**|`google`|None|N/A|None|
 |**Google (Default)**|`google`|None|N/A|None|
 |**Bing**|`bing`|None|N/A|None|
 |**Bing**|`bing`|None|N/A|None|
 |**DeepL**|`deepl`|`DEEPL_SERVER_URL`,`DEEPL_AUTH_KEY`|`https://api.deepl.com`, `[Your Key]`|See [DeepL](https://support.deepl.com/hc/en-us/articles/360020695820-API-Key-for-DeepL-s-API)|
 |**DeepL**|`deepl`|`DEEPL_SERVER_URL`,`DEEPL_AUTH_KEY`|`https://api.deepl.com`, `[Your Key]`|See [DeepL](https://support.deepl.com/hc/en-us/articles/360020695820-API-Key-for-DeepL-s-API)|
-|**DeepLX**|`deeplx`|`DEEPLX_ENDPOINT`,`DEEPLX_AUTH_KEY`|`https://api.deepl.com/translate`, `[Your Key]`|See [DeepLX](https://github.com/OwO-Network/DeepLX)|
+|**DeepLX**|`deeplx`|`DEEPLX_ENDPOINT`,`DEEPLX_ACCESS_TOKEN`|`https://api.deepl.com/translate`, `[Your Acccess Token]`|See [DeepLX](https://github.com/OwO-Network/DeepLX)|
 |**Ollama**|`ollama`|`OLLAMA_HOST`, `OLLAMA_MODEL`|`http://127.0.0.1:11434`, `gemma2`|See [Ollama](https://github.com/ollama/ollama)|
 |**Ollama**|`ollama`|`OLLAMA_HOST`, `OLLAMA_MODEL`|`http://127.0.0.1:11434`, `gemma2`|See [Ollama](https://github.com/ollama/ollama)|
 |**OpenAI**|`openai`|`OPENAI_BASE_URL`, `OPENAI_API_KEY`, `OPENAI_MODEL`|`https://api.openai.com/v1`, `[Your Key]`, `gpt-4o-mini`|See [OpenAI](https://platform.openai.com/docs/overview)|
 |**OpenAI**|`openai`|`OPENAI_BASE_URL`, `OPENAI_API_KEY`, `OPENAI_MODEL`|`https://api.openai.com/v1`, `[Your Key]`, `gpt-4o-mini`|See [OpenAI](https://platform.openai.com/docs/overview)|
 |**Zhipu**|`zhipu`|`ZHIPU_API_KEY`, `ZHIPU_MODEL`|`[Your Key]`, `glm-4-flash`|See [Zhipu](https://open.bigmodel.cn/dev/api/thirdparty-frame/openai-sdk)|
 |**Zhipu**|`zhipu`|`ZHIPU_API_KEY`, `ZHIPU_MODEL`|`[Your Key]`, `glm-4-flash`|See [Zhipu](https://open.bigmodel.cn/dev/api/thirdparty-frame/openai-sdk)|

+ 1 - 1
README_zh-CN.md

@@ -194,7 +194,7 @@ pdf2zh example.pdf -li en -lo ja
 |**Google (Default)**|`google`|None|N/A|None|
 |**Google (Default)**|`google`|None|N/A|None|
 |**Bing**|`bing`|None|N/A|None|
 |**Bing**|`bing`|None|N/A|None|
 |**DeepL**|`deepl`|`DEEPL_SERVER_URL`,`DEEPL_AUTH_KEY`|`https://api.deepl.com`, `[Your Key]`|See [DeepL](https://support.deepl.com/hc/en-us/articles/360020695820-API-Key-for-DeepL-s-API)|
 |**DeepL**|`deepl`|`DEEPL_SERVER_URL`,`DEEPL_AUTH_KEY`|`https://api.deepl.com`, `[Your Key]`|See [DeepL](https://support.deepl.com/hc/en-us/articles/360020695820-API-Key-for-DeepL-s-API)|
-|**DeepLX**|`deeplx`|`DEEPLX_ENDPOINT`,`DEEPLX_AUTH_KEY`|`https://api.deepl.com/translate`, `[Your Key]`|See [DeepLX](https://github.com/OwO-Network/DeepLX)|
+|**DeepLX**|`deeplx`|`DEEPLX_ENDPOINT`,`DEEPLX_ACCESS_TOKEN`|`https://api.deepl.com/translate`, `[Your Access Token]`|See [DeepLX](https://github.com/OwO-Network/DeepLX)|
 |**Ollama**|`ollama`|`OLLAMA_HOST`, `OLLAMA_MODEL`|`http://127.0.0.1:11434`, `gemma2`|See [Ollama](https://github.com/ollama/ollama)|
 |**Ollama**|`ollama`|`OLLAMA_HOST`, `OLLAMA_MODEL`|`http://127.0.0.1:11434`, `gemma2`|See [Ollama](https://github.com/ollama/ollama)|
 |**OpenAI**|`openai`|`OPENAI_BASE_URL`, `OPENAI_API_KEY`, `OPENAI_MODEL`|`https://api.openai.com/v1`, `[Your Key]`, `gpt-4o-mini`|See [OpenAI](https://platform.openai.com/docs/overview)|
 |**OpenAI**|`openai`|`OPENAI_BASE_URL`, `OPENAI_API_KEY`, `OPENAI_MODEL`|`https://api.openai.com/v1`, `[Your Key]`, `gpt-4o-mini`|See [OpenAI](https://platform.openai.com/docs/overview)|
 |**Zhipu**|`zhipu`|`ZHIPU_API_KEY`, `ZHIPU_MODEL`|`[Your Key]`, `glm-4-flash`|See [Zhipu](https://open.bigmodel.cn/dev/api/thirdparty-frame/openai-sdk)|
 |**Zhipu**|`zhipu`|`ZHIPU_API_KEY`, `ZHIPU_MODEL`|`[Your Key]`, `glm-4-flash`|See [Zhipu](https://open.bigmodel.cn/dev/api/thirdparty-frame/openai-sdk)|

+ 3 - 5
pdf2zh/translator.py

@@ -149,7 +149,7 @@ class DeepLXTranslator(BaseTranslator):
     name = "deeplx"
     name = "deeplx"
     envs = {
     envs = {
         "DEEPLX_ENDPOINT": "https://api.deepl.com/translate",
         "DEEPLX_ENDPOINT": "https://api.deepl.com/translate",
-        "DEEPLX_AUTH_KEY": None,
+        "DEEPLX_ACCESS_TOKEN": None,
     }
     }
     lang_map = {"zh": "zh-Hans"}
     lang_map = {"zh": "zh-Hans"}
 
 
@@ -157,10 +157,9 @@ class DeepLXTranslator(BaseTranslator):
         super().__init__(service, lang_out, lang_in, model)
         super().__init__(service, lang_out, lang_in, model)
         self.endpoint = os.getenv("DEEPLX_ENDPOINT", self.envs["DEEPLX_ENDPOINT"])
         self.endpoint = os.getenv("DEEPLX_ENDPOINT", self.envs["DEEPLX_ENDPOINT"])
         self.session = requests.Session()
         self.session = requests.Session()
-        auth_key = os.getenv("DEEPLX_AUTH_KEY", self.envs["DEEPLX_AUTH_KEY"])
-        self.header = {"Content-Type": "application/json"}
+        auth_key = os.getenv("DEEPLX_ACCESS_TOKEN", self.envs["DEEPLX_ACCESS_TOKEN"])
         if auth_key:
         if auth_key:
-            self.header["Authorization"] = f"Bearer {auth_key}"
+            self.endpoint = f"{self.endpoint}?token={auth_key}"
 
 
     def translate(self, text):
     def translate(self, text):
         resp = self.session.post(
         resp = self.session.post(
@@ -170,7 +169,6 @@ class DeepLXTranslator(BaseTranslator):
                 "target_lang": self.lang_out,
                 "target_lang": self.lang_out,
                 "text": text,
                 "text": text,
             },
             },
-            headers=self.header,
         )
         )
         return resp.json()["data"]
         return resp.json()["data"]