Build a multilingual translation agent with Groq
In this tutorial, we will build a Multilingual Translation Agent by combining two specialized Agents: a translator agent for fast and efficient translations between languages and a research agent that provides additional context to improve translation quality. We'll then integrate these into a Team Agent for enhanced performance. By the end, you'll have a powerful agent capable of delivering accurate, context-rich translations efficiently.
Agents are intelligent entities leveraging Large Language Models (LLMs) to break down complex queries, use appropriate tools (e.g., translation, summarization), and deliver integrated results. In aiXplain, agents utilize Models, Utilities and Pipelines, with Team Agents handling multi-step tasks collaboratively. Learn more about Agents using this guide.
Integrating Groq
Groq is an innovative AI hardware company that specializes in high-performance computing for machine learning workloads. Their Tensor Streaming Processor (TSP) architecture offers:
- Ultra-low latency: Fast inference times for real-time applications.
- High throughput: Ability to process large amounts of data efficiently.
- Deterministic performance: Predictable and consistent results, essential for critical applications.
By leveraging Groq’s hardware acceleration, we can enhance the speed and efficiency of AI models, resulting in faster and more responsive, capable agents.
Step 1: Create the Multilingual Agent
Create the Translation Tool
First, we'll create a tool for translation using an AWS multilingual translation model from our marketplace.
from aixplain.modules.agent import ModelTool, PipelineTool
from aixplain.factories import AgentFactory
from aixplain.factories import TeamAgentFactory
translation_tool = ModelTool(model="66aa869f6eb56342c26057e1")
Create the Translator Agent
Now, we'll create the translator agent, equipping it with the translation tool and utilizing the Groq Gemma 7B model as the LLM for enhanced speed and efficiency.
translator_agent = AgentFactory.create(
name="Translator Agent",
description=(
"This agent is responsible for translating the source text from input_language to target_language."
"It generates multiple translation hypotheses, identifies ambiguities, and refines the translation based on feedback and additional examples."
),
tools = [translation_tool],
llm_id="660ea9ba4edcc355738532c8"
)
Step 2: Create the Research Agent
The research agent assists the translator agent by providing additional context and examples to enhance translation quality.
Create the Scraper Tool
We'll create a scraper tool using the scraper utility to search for additional context and translation examples.
scraper_tool = ModelTool(model="66f423426eb563fa213a3531")
Create the Research Agent
Now, we'll create the research agent and equip it with the scraper tool and the Groq Gemma 7B model.
research_agent = AgentFactory.create(
name="Research Agent",
description=(
"This agent searches for additional context and translation examples from input_language to target_language"
"to help the Translator resolve ambiguities and refine the translation."
),
tools = [scraper_tool],
llm_id="660ea9ba4edcc355738532c8"
)
Step 3: Combine Agents into a Team Agent
Now that we have both the translator and research agents, we'll combine them into a team agent. This allows them to collaborate and leverage each other's capabilities.
from aixplain.factories import TeamAgentFactory
team = TeamAgentFactory.create(
name="Team of Agents for Multi Lingual Translation",
agents=[
translator_agent,
research_agent
],
llm_id="6646261c6eb563165658bbb1"
)
Step 4: Invoke the Team Agent
Let's test our agent by performing some translations.
English to French Translation
agent_response = team.run(
"""
Translate the text from English to French.
Paris announced the launch of its Green Deal, aligning with the latest EU regulations and aiming for 2050 carbon neutrality.
"""
)
display(agent_response)
French to German
agent_response = team.run(
"""
Translate the text from French to German.
Paris a annoncé le lancement de son Green Deal, s\'alignant sur les dernières réglementations de l\'UE et visant la neutralité carbone d\'ici 2050.
"""
)
agent_response['data']['output']
German to English
agent_response = team.run(
"""
Translate the text from German to English.
Paris hat die Einführung seines Green Deals angekündigt, der sich an den neuesten EU-Vorschriften orientiert und bis 2050 Kohlenstoffneutralität anstrebt.
"""
)
display(agent_response['data']['output'])
Congratulations! You've successfully built a multilingual translation agent using Groq models in aiXplain. By leveraging Groq's hardware acceleration, your agents can perform tasks faster and more efficiently than traditional models.
Browse all Groq models on aiXplain’s marketplace.