Translation¶
- class agentlego.tools.Translation(backend='google', toolmeta=None)[source]
Default Tool Meta¶
name: Translation
description: This tool can translate a text from source language to the target language. The language code should be one of ‘zh-CN’ (Chinese), ‘en’ (English), ‘fr’ (French), ‘de’ (German), ‘el’ (Greek), ‘it’ (Italian), ‘ja’ (Japanese), ‘ko’ (Korean), ‘la’ (Latin), ‘pl’ (Polish), ‘ru’ (Russian), ‘es’ (Spanish), ‘th’ (Thai), ‘tr’ (Turkish).
inputs:
text (str): The text to translate
target (str): The target language code
source (str): The source language code
outputs:
str
Examples¶
Use the tool directly (without agent)
from agentlego.apis import load_tool
# load tool
tool = load_tool('Translation')
# apply tool
res = tool('This is an example sentence.', 'auto', 'zh-CN')
With Lagent
from lagent import ReAct, GPTAPI, ActionExecutor
from agentlego.apis import load_tool
# load tools and build agent
# please set `OPENAI_API_KEY` in your environment variable.
tool = load_tool('Translation').to_lagent()
agent = ReAct(GPTAPI(temperature=0.), action_executor=ActionExecutor([tool]))
# agent running with the tool.
ret = agent.chat(f'Please translate the below text to Chinese: Nothing is true, everything is permitted.')
for step in ret.inner_steps[1:]:
print('------')
print(step['content'])