mirror of
https://github.com/aljazceru/chatgpt-telegram-bot.git
synced 2025-12-18 21:25:10 +01:00
32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
from typing import Dict
|
|
|
|
from duckduckgo_search import DDGS
|
|
|
|
from .plugin import Plugin
|
|
|
|
|
|
class DDGTranslatePlugin(Plugin):
|
|
"""
|
|
A plugin to translate a given text from a language to another, using DuckDuckGo
|
|
"""
|
|
def get_source_name(self) -> str:
|
|
return "DuckDuckGo Translate"
|
|
|
|
def get_spec(self) -> [Dict]:
|
|
return [{
|
|
"name": "translate",
|
|
"description": "Translate a given text from a language to another",
|
|
"parameters": {
|
|
"type": "object",
|
|
"properties": {
|
|
"text": {"type": "string", "description": "The text to translate"},
|
|
"to_language": {"type": "string", "description": "The language to translate to (e.g. 'it')"}
|
|
},
|
|
"required": ["text", "to_language"],
|
|
},
|
|
}]
|
|
|
|
async def execute(self, function_name, helper, **kwargs) -> Dict:
|
|
with DDGS() as ddgs:
|
|
return ddgs.translate(kwargs['text'], to=kwargs['to_language'])
|