Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

可以搭配DeepLX项目弄个本地的API #6

Closed
uzcool opened this issue Apr 1, 2023 · 11 comments
Closed

可以搭配DeepLX项目弄个本地的API #6

uzcool opened this issue Apr 1, 2023 · 11 comments
Labels
enhancement New feature or request

Comments

@uzcool
Copy link

uzcool commented Apr 1, 2023

项目地址
https://github.com/OwO-Network/DeepLX

import httpx, json

deeplx_api = "http://127.0.0.1:1188/translate"

data = {
	"text": "Hello World",
	"source_lang": "EN",
	"target_lang": "ZH"
}

post_data = json.dumps(data)
r = httpx.post(url = deeplx_api, data = post_data).text
print(r)


@bookfere bookfere added the enhancement New feature or request label Apr 7, 2023
@bookfere
Copy link
Owner

bookfere commented Apr 8, 2023

之后的版本可以添加自定义翻译引擎功能来满足这个需求。

@killo3967
Copy link

Yo estaria agradecido que incorporara esta funcionalidad. La creo muy interesanta.

@dyoghenes
Copy link

dyoghenes commented Apr 18, 2023

Hi! Sorry for reopening this. What code should I use to get this working?

{
    "name": "DeepL X",
    "languages": {
        "source": {
            "Source Language": "DE"
        },
        "target": {
            "Target Language": "EN-GB"
        }
    },
    "request": {
        "url": "http://127.0.0.1:1188/translate",
        "method": "POST",
        "data": {
            "source_lang": "<source>",
            "target_lang": "<target>",
            "text": "<text>"
        }
    },
    "response": "response"
}

Using this code returns to me HTTP Error 400: Bad Request in Calibre, and a 404 error in the DeepLX

@bookfere
Copy link
Owner

@dyoghenes I see that you received a 400 response status code, indicating that the translation engine API rejected your request. This could be due to the instability of the API you used.

@shantaram108
Copy link

shantaram108 commented Jun 13, 2024

@dyoghenes I see that you received a 400 response status code, indicating that the translation engine API rejected your request. This could be due to the instability of the API you used.

I used the same settings except I used https://deeplx.vercel.app/translate as URL and get the following error:

 Traceback (most recent call last):
  File "calibre_plugins.ebook_translator.components.engine", line 67, in translate_text
  File "calibre_plugins.ebook_translator.engines.custom", line 120, in translate
  File "calibre_plugins.ebook_translator.engines.base", line 210, in get_result
Exception: Can not parse returned response. Raw data: 

Traceback (most recent call last):
  File "calibre_plugins.ebook_translator.engines.base", line 201, in get_result
  File "calibre_plugins.ebook_translator.engines.custom", line 134, in _parse
Exception: Response was parsed incorrectly.

{"code":200,"data":"Hallo Welt!"}

@bookfere
Copy link
Owner

It is a parse error, please try to revise the response part like this "response": "response['data']".

@shantaram108
Copy link

it works, thank you!

@shantaram108
Copy link

I have another issue now:

I started my own DeeplX service and tested it in my browser with "http request maker" addon for firefox. It works just fine. When I replace https://deeplx.vercel.app/translate with http://127.0.0.1:1188/translate in the custom config it to have it like this:

{`
    "name": "DeepL X",
    "languages": {
        "source": {
            "Source Language": "EN"
        },
        "target": {
            "Target Language": "DE"
        }
    },
    "request": {
        "url": "http://127.0.0.1:1188/translate",
        "method": "POST",
        "data": {
            "source_lang": "<source>",
            "target_lang": "<target>",
            "text": "<text>"
        }
    },
    "response": "response['data']"
}

I get the following error


Traceback (most recent call last):
  File "calibre_plugins.ebook_translator.components.engine", line 67, in translate_text
  File "calibre_plugins.ebook_translator.engines.custom", line 120, in translate
  File "calibre_plugins.ebook_translator.engines.base", line 210, in get_result
Exception: Can not parse returned response. Raw data: 

Traceback (most recent call last):
  File "calibre_plugins.ebook_translator.engines.base", line 197, in get_result
  File "mechanize\_mechanize.py", line 257, in open
  File "mechanize\_mechanize.py", line 313, in _mech_open
mechanize._response.get_seek_wrapper_class.<locals>.httperror_seek_wrapper: HTTP Error 400: Bad Request

{"code":404,"message":"No text to translate"}

In the HTTP Request Maker addon for Firefox, just change the URL address and it works for both URL, the one from vercel.app and my localhost. So I guess it should be the same when changing the url in the custom config. Can you help me figuring out why it wont send the text to the POST request?

@bookfere
Copy link
Owner

Maybe you need to add an appropriate request header:

"headers": {
    "Content-Type": "application/json"
}

By the way, the free version of DeepL has already been added to the built-in engine of the plugin, so it is not necessary to use a custom engine.

@fideliochan
Copy link

fideliochan commented Sep 6, 2024

@bookfere I need to use DeepLX's /v1/translate endpoint since I have pro account but no matter I do it translates it into english what do I do wrong?

{
    "name": "DeepLX",
    "languages": {
        "source": {
            "Source Language": "auto"
        },
        "target": {
            "Target Language": "TR"
        }
    },
    "request": {
        "url": "http://127.0.0.1:1188/v1/translate",
        "method": "POST",
        "headers": {
            "Content-Type": "application/json"
        },
        "data": {
            "source": "<source>",
            "target": "<target>",
            "text": "<text>"
        }
    },
    "response": "response['data']"
}

Please don't say use DeepL Free since I have pro account /v1 endpoint simulates as If I have pro api.

@micropythondevel
Copy link

hello
tatus: Failed 1 times / Sleeping for 5 seconds
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Error: Traceback (most recent call last):
File "calibre_plugins.ebook_translator.lib.translation", line 136, in _translate_text
translation = self.translator.translate(text)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.custom", line 120, in translate
return self.get_result(
^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.base", line 210, in get_result
raise Exception(
Exception: No se pudo analizar la respuesta devuelta. Datos sin procesar:

Traceback (most recent call last):
File "calibre_plugins.ebook_translator.engines.base", line 197, in get_result
br.open(request)
File "mechanize/_mechanize.py", line 257, in open
File "mechanize/_mechanize.py", line 313, in _mech_open
mechanize._response.get_seek_wrapper_class..httperror_seek_wrapper: HTTP Error 400: BAD REQUEST

{"error":"Invalid request: missing q parameter"}

my config

{
"name": "freetranslate",
"languages": {
"source": { "Source Language": "auto" },
"target": { "Target Language": "es" }
},
"request": {
"url": "http://127.0.0.1:5000/translate",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"data": {
"source": "",
"target": "",
"text": "",
"api_key": ""

    }
},
"response": "response['data']"

}
I don't know where the error could be, can someone help me? I use a local version of LibreTranslate

Thanks

我不知道错误可能出在哪里,有人可以帮助我吗,我使用本地版本的 libretranslate

谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants