mirror of
https://github.com/aljazceru/chatgpt-telegram-bot.git
synced 2025-12-24 08:05:06 +01:00
update naming
This commit is contained in:
31
bot/plugins/ddg_translate.py
Normal file
31
bot/plugins/ddg_translate.py
Normal file
@@ -0,0 +1,31 @@
|
||||
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, **kwargs) -> Dict:
|
||||
with DDGS() as ddgs:
|
||||
return ddgs.translate(kwargs['text'], to=kwargs['to_language'])
|
||||
Reference in New Issue
Block a user