Skip to content

Commit

Permalink
Merge pull request #542 from yurnov/deelp-unicode_escape-fix
Browse files Browse the repository at this point in the history
deepl plugin fix: avoid unicode escape characters in the response containing non-ANSI characters
  • Loading branch information
n3d1117 authored Mar 11, 2024
2 parents a508707 + 503abe6 commit cae6f96
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.env
.dockerignore
.github
.gitignore
docker-compose.yml
Dockerfile
6 changes: 4 additions & 2 deletions bot/plugins/deepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ async def execute(self, function_name, helper, **kwargs) -> Dict:
headers = {
"Authorization": f"DeepL-Auth-Key {self.api_key}",
"User-Agent": "chatgpt-telegram-bot",
"Content-Type": "application/x-www-form-urlencoded"
"Content-Type": "application/x-www-form-urlencoded",
"Accept-Encoding": "utf-8"
}
data = {
"text": kwargs['text'],
"target_lang": kwargs['to_language']
}
return requests.post(url, headers=headers, data=data).json()["translations"][0]["text"]
translated_text = requests.post(url, headers=headers, data=data).json()["translations"][0]["text"]
return translated_text.encode('unicode-escape').decode('unicode-escape')

0 comments on commit cae6f96

Please sign in to comment.