Customer Service Discord Bot for Finance with OpenBB
You can also check this cookbook in colab here
⭐ Star us on GitHub, join our Discord, or follow us on X
This notebook demonstrates how to build a custom financial assistant Discord bot using OpenBB and CAMEL-AI. By integrating real-time financial data and advanced AI-driven interactions, this tutorial showcases an innovative approach to delivering dynamic financial insights.
In this notebook, you’ll explore:
-
CAMEL-AI: A versatile multi-agent framework that powers the financial assistant with intelligent tool-calling and natural language understanding, ensuring precise and professional responses.
-
OpenBB: An open-source platform for advanced financial research, offering tools for analyzing stocks, cryptocurrencies, and market trends through an intuitive API integration.
-
Qwen: A large language model developed by Alibaba Cloud, used for generating intelligent and contextually aware responses in the assistant’s interactions.
-
Discord Integration: A step-by-step guide to creating and deploying a chatbot in Discord, enabling seamless interaction with users and delivering financial insights in a community setting.
This setup not only demonstrates a practical application of AI-driven financial assistance but also provides a robust framework adaptable to other domains requiring multi-agent collaboration, real-time data integration, and natural language interfaces.
📦 Installation
First, install the CAMEL package with all its dependencies:
🔑 Setting Up API Keys
Setting up Qwen API Key
In this tutorial, we will be using Qwen model. Qwen is a large language model developed by Alibaba Cloud. It is trained on a massive dataset of text and code and can generate text, translate languages, write different kinds of creative content, and answer your questions in an informative way.
You’ll need to set up your API keys for Qwen. This ensures that the tools can interact with external services securely.
If you don’t have a Qwen API key, you can obtain one by following these steps:
- Visit the Alibaba Cloud Model Studio Console (https://www.alibabacloud.com/en?_p_lc=1) and follow the on-screen instructions to activate the model services.
- In the upper-right corner of the console, click on your account name and select API-KEY.
- On the API Key management page, click on the Create API Key button to generate a new key.
For more details, you can also check the Qwen documentation: https://www.alibabacloud.com/help/en/model-studio/developer-reference/use-qwen-by-calling-api
Alternatively, if running on Colab, you could save your API keys and tokens as Colab Secrets, and use them across notebooks.
To do so, comment out the above manual API key prompt code block(s), and uncomment the following codeblock.
⚠️ Don’t forget granting access to the API key you would be using to the current notebook.
To use Qwen model with CAMEL, we need to set up the model first:
Setting up OpenBB Personal Access Token (PAT)
OpenBB is an open-source platform designed for advanced investment research, empowering users with tools to analyze financial data, create visualizations, and generate detailed reports. Catering to retail investors, financial analysts, and enthusiasts, OpenBB provides access to functionalities typically available only on expensive institutional platforms. It supports stock data exploration, portfolio analysis, market trend evaluation, and integration with premium APIs, all through an intuitive terminal or command-line interface.
CAMEL has integrated an OpenBB toolkit that allows CAMEL agents to access plenty of OpenBB’s powerful functions easily. For more information about the toolkit, please refer to the OpenBBToolkit documentation.
To use the toolkit, we would need an OpenBB Personal Access Token (PAT).
How to obtain an OpenBB PAT
- Please login to the OpenBB Platform or sign up as prompted if you do not have an account yet.
- In ‘SETTINGS’, go to ‘Personal Access Token’.
- You can now see your OpenBB personal access token (PAT).
Note: Before fetching financial data with OpenBB, please ensure you have set up the necessary API keys for data providers. For detailed instructions on saving your API keys to your OpenBB account, please refer to the OpenBB Getting Started Guide.
Set up Agent Equipped with OpenBB and date tools
In this step, we will define the tools and the system prompt for our ChatAgent
.
Since the LLMs do not intrinsically know the current dates, we need to define a date tool to get the current date.
Below we also set the prompt to pass into the agent for better tool calling and output formatting.
+--------+-------------------+--------+-----------+----------+-------------+ | Symbol | Asset | Price | Change (320.11| -28,550| +$150 | +0.53% | 22,000 BTC | +--------+-------------------+--------+-----------+----------+-------------+
Basic Chatbot Setup
Let’s set up the basic Chatbot with CAMEL Agent equipped with OpenBB and date tools and ask some questions!
For example, we can ask:
What was the price of Tesla yesterday?
As we can see above in the tool call records, the agent automatically identify which tools to use and accurately utilizes the tools to retrieve relevant data.
Basic Discord Bot Integration
To build a discord bot, a discord bot token is necessary.
If you don’t have a bot token, you can obtain one by following these steps:
- Go to the Discord Developer Portal: https://discord.com/developers/applications
- Log in with your Discord account, or create an account if you don’t have one
- Click on ‘New Application’ to create a new bot.
- Give your application a name and click ‘Create’.
- Navigate to the ‘Bot’ tab on the left sidebar and click ‘Add Bot’.
- Once the bot is created, you will find a ‘Token’ section. Click ‘Reset Token’ to generate a new token.
- Copy the generated token securely.
To invite the bot:
- Navigate to the ‘OAuth2’ tab, then to ‘URL Generator’.
- Under ‘Scopes’, select ‘bot’.
- Under ‘Bot Permissions’, select the permissions your bot will need (e.g., ‘Send Messages’, ‘Read Messages’ for our bot use)
- Copy the generated URL and paste it into your browser to invite the bot to your server.
To grant the bot permissions:
- Navigate to the ‘Bot’ tab
- Under ‘Privileged Gateway Intents’, check ‘Server Members Intent’ and ‘Message Content Intent’.
For more details, you can also check the official Discord bot documentation: https://discord.com/developers/docs/intro
This code cell sets up a simple Discord bot using the DiscordApp class from the camel.bots
library. The bot listens for messages in any channel it has access to and provides a response based on the input message.
Here is an example run of the bot — with a concise and nicely formatted response!
And let’s try another question
Here we go! In this cookbook, we’ve built a simple yet powerful financial data assistant bot using OpenBB tools, which enables quick access to the latest financial data through natural language queries.
That’s everything: Got questions about 🐫 CAMEL-AI? Join us on Discord! Whether you want to share feedback, explore the latest in multi-agent systems, get support, or connect with others on exciting projects, we’d love to have you in the community! 🤝
Check out some of our other work:
- 🐫 Creating Your First CAMEL Agent free Colab
- Graph RAG Cookbook free Colab
- 🧑⚖️ Create A Hackathon Judge Committee with Workforce free Colab
- 🔥 3 ways to ingest data from websites with Firecrawl & CAMEL free Colab
- 🦥 Agentic SFT Data Generation with CAMEL and Mistral Models, Fine-Tuned with Unsloth free Colab
Thanks from everyone at 🐫 CAMEL-AI