AI Themes Logo

aithemes.net

CAMEL AI Blog Translator Agent with Mistral LLM

A post on using CAMEL AI Agents with Mistral LLM for a practical blog translation use case.

7 min read

Created: Oct 09 2024Last Update: Oct 09 2024
#CAMEL AI#MDX#Mistral AI#agent#blog post#german#german_agent#german_blog post#german_post#user#user_message

Post image While it's easy to recognize the immense potential of AI Agents, it's not always straightforward to find a useful application for them in professional or personal projects.

In this post, I describe using the CAMEL AI framework to create a very simple AI Agent powered by Mistral LLMs, designed to assist with my blog project.

The goals of this post are twofold:

  1. To describe a very simple AI Agent using the CAMEL AI framework and Mistral AI LLM API endpoint.
  2. To provide a practical use case for this AI Agent.

Overview of CAMEL AI

CAMEL AI is a platform that enables users to create and manage AI agents using natural language instructions. It supports various models, including Mistral AI, to enable intelligent workflows for different applications.

Post Translator AI Agent

This AI Agent automatically translates English blog posts from a GitHub repository into multiple languages (e.g., German, Spanish) and commits the translated posts back to the same repository, ensuring that all translations are stored and managed within the GitHub project.

Workflow Diagram

Workflow chart

Diagram generated using Mermaid.

Dependencies:

The AI Agent

This code snippet creates the AI Agent using the Mistral model (for translation to German).


import os
from camel.models import ModelFactory
from camel.types import ModelPlatformType, ModelType
from camel.messages import BaseMessage
from camel.agents import ChatAgent

# Ensure the MISTRAL_API_KEY environment variable is set
if not os.getenv('MISTRAL_API_KEY'):
  raise EnvironmentError("MISTRAL_API_KEY environment variable is not set.")

# Create the Mistral AI model using the Mistral platform and model type.
# The temperature is set to 0.0 for deterministic responses (no randomness in output).
mistral_model = ModelFactory.create(
  model_platform=ModelPlatformType.MISTRAL,
  model_type=ModelType.MISTRAL_LARGE,
  model_config_dict={"temperature": 0.0},
)

# The assistant is tasked with translating blog posts from English to German (Germany).
# It should only output the translation in MDX format without extra comments.
german_system_message = BaseMessage.make_assistant_message(
  role_name="translator",
  content="""
      You are a specialized translator of blog posts written in English to German (Germany).
      You will receive an English post in MDX format.
      Translate to German using technical language and do not translate English technical terms.
      Very important: Only write in the output the translated post in MDX format inside a snippet without other comments in the format of a snippet exactly like:
      ```mdx
      <mdx_contents>
      ```
  """
)

# Create the ChatAgent with the Mistral model and the specified system message.
# This agent will handle translation requests according to the defined role and instructions.
german_agent = ChatAgent(model=mistral_model, system_message=german_system_message)

This code snippet demonstrates how to invoke the Agent to translate a blog post.


# Define the content for the user message in MDX format.
# This content represents a blog post to be translated by the AI Agent.
content = """
---
title: CAMEL AI Blog Translator Agent with Mistral LLM  
description: "A post on using CAMEL AI Agents with Mistral LLM for a practical blog translation use case."  
date: Oct 09 2024  
lastUpdate: Oct 09 2024  
tags: ["CAMEL AI", "MDX", "Mistral AI", "agent", "blog post", "german", "german_agent", "german_blog post", "german_post", "user", "user_message"]
category: "AI Agents"
---

While it's easy to recognize the immense potential of AI Agents, it's not always straightforward to find a useful application for them in professional or personal projects.

In this post, I describe using the CAMEL AI framework to create a very simple AI Agent powered by Mistral LLMs, designed to assist with my blog project.

The goals of this post are twofold:
1. To describe a very simple AI Agent using the CAMEL AI framework and Mistral AI LLM API endpoint.
2. To provide a practical use case for this AI Agent.

Link(s):  
[CAMEL AI](https://docs.camel-ai.org)  
[Mistral AI API](https://docs.mistral.ai/api/) 
"""

# Create a user message with the role 'user' and the blog post content.
# This message is sent to the AI Agent for translation.
user_message = BaseMessage.make_user_message(role_name="user", content=content)

# Invoke the AI Agent with the user message and retrieve the agent's response.
# The response should contain the translated blog post in MDX format.
agent_response = german_agent.step(user_message)

# Output the translated content from the agent's response.
print(agent_response.msgs[0].content)

Here is the resulting blog post translated into German.

Out:
```mdx
---
title: CAMEL AI Blog Translator Agent mit Mistral LLM
description: "Ein Beitrag über die Verwendung von CAMEL AI Agents mit Mistral LLM für einen praktischen Blog-Übersetzungsanwendungsfall."
date: Oct 09 2024
lastUpdate: Oct 09 2024
---

Während es leicht ist, das immense Potenzial von AI Agents zu erkennen, ist es nicht immer einfach, eine nützliche Anwendung für sie in beruflichen oder persönlichen Projekten zu finden.

In diesem Beitrag beschreibe ich die Verwendung des CAMEL AI Frameworks zur Erstellung eines sehr einfachen AI Agents, der von Mistral LLMs angetrieben wird und mir bei meinem Blog-Projekt hilft.

Die Ziele dieses Beitrags sind zweifach:
1. Einen sehr einfachen AI Agent unter Verwendung des CAMEL AI Frameworks und des Mistral AI LLM API Endpunkts zu beschreiben.
2. Einen praktischen Anwendungsfall für diesen AI Agent bereitzustellen.

Link(s):
[CAMEL AI](https://docs.camel-ai.org)
[Mistral AI API](https://docs.mistral.ai/api/)
```

Integration with GitHub

The PyGithub package (https://pygithub.readthedocs.io/) is used to integrate with the blog project repository to:

  • Read blog post files from the repository.
  • Commit translated blog files to the repository.

Link(s):
CAMEL AI
Mistral AI API


Enjoyed this post? Found it helpful? Feel free to leave a comment below to share your thoughts or ask questions. A GitHub account is required to join the discussion.