generated from kyegomez/Python-Package-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
160 additions
and
0 deletions.
There are no files selected for viewing
160 changes: 160 additions & 0 deletions
160
cookbook/enterprise/finance/multi_agent/Swarms_Cookbook_CryptoAgent.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "029606c8", | ||
"metadata": {}, | ||
"source": [ | ||
"# Swarms Cookbook: CryptoAgent Real-Time Cryptocurrency Data Analysis\n", | ||
"\n", | ||
"Welcome to the Swarms Cookbook! In this guide, we will walk through the steps of using **CryptoAgent**, an enterprise-grade solution for real-time cryptocurrency data fetching, analysis, and summarization.\n", | ||
"\n", | ||
"CryptoAgent integrates with CoinGecko's API to retrieve the latest cryptocurrency metrics and leverages OpenAI's language models to provide insightful reports for crypto investors and analysts.\n", | ||
"\n", | ||
"### Key Features:\n", | ||
"- **Real-Time Data Fetching**: Retrieves up-to-date cryptocurrency prices, market capitalization, and trading volume.\n", | ||
"- **Advanced Analysis**: Uses AI to summarize complex data into clear, actionable insights.\n", | ||
"- **Enterprise-Grade**: Designed with robust error handling and scalability for professional environments.\n", | ||
"\n", | ||
"Follow the step-by-step guide below to set up **CryptoAgent** for your cryptocurrency analysis needs.\n", | ||
"\n", | ||
"Be sure to visit the **[Swarms GitHub](https://github.com/kyegomez/swarms)**, **[Discord](https://discord.com/servers/agora-999382051935506503)**, and **[Swarms Marketplace](https://swarms.xyz)** for more resources and to connect with the community.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d81accd1", | ||
"metadata": {}, | ||
"source": [ | ||
"## Installation\n", | ||
"\n", | ||
"First, install the **CryptoAgent** package by running the following command:\n", | ||
"\n", | ||
"```bash\n", | ||
"pip3 install -U cryptoagent\n", | ||
"```\n", | ||
"\n", | ||
"You will also need to create a `.env` file with the necessary environment variables for API access:\n", | ||
"\n", | ||
"```bash\n", | ||
"OPENAI_API_KEY=\"your-openai-api-key\"\n", | ||
"```\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "dd3ceea4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Import necessary libraries\n", | ||
"import os\n", | ||
"from cryptoagent.main import OpenAIChat, CryptoAgent\n", | ||
"from swarms import Agent\n", | ||
"from dotenv import load_dotenv\n", | ||
"\n", | ||
"# Load environment variables from the .env file\n", | ||
"load_dotenv()\n", | ||
"\n", | ||
"# Ensure API key is loaded\n", | ||
"openai_api_key = os.getenv(\"OPENAI_API_KEY\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "14e5a9e7", | ||
"metadata": {}, | ||
"source": [ | ||
"## Setting Up CryptoAgent\n", | ||
"\n", | ||
"Now, let's initialize the **CryptoAgent** for real-time cryptocurrency data analysis. We will create an **OpenAIChat** instance for LLM integration and an input agent for running the analysis.\n", | ||
"\n", | ||
"In this example, we'll analyze multiple cryptocurrencies including Bitcoin, Ethereum, Dogecoin, and XRP.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "40c11472", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Create an instance of OpenAIChat class for LLM integration\n", | ||
"model = OpenAIChat(\n", | ||
" openai_api_key=openai_api_key,\n", | ||
" model_name=\"gpt-4o-mini\",\n", | ||
" temperature=0.1\n", | ||
")\n", | ||
"\n", | ||
"# Create the input agent\n", | ||
"input_agent = Agent(\n", | ||
" agent_name=\"Crypto-Analysis-Agent\",\n", | ||
" system_prompt=\"You are a financial analysis agent that provides crypto analysis with live data.\",\n", | ||
" llm=model,\n", | ||
" max_loops=1,\n", | ||
" autosave=True,\n", | ||
" dashboard=False,\n", | ||
" verbose=True,\n", | ||
" dynamic_temperature_enabled=True,\n", | ||
" saved_state_path=\"crypto_agent.json\",\n", | ||
" user_name=\"swarms_corp\",\n", | ||
" retry_attempts=2,\n", | ||
" context_length=10000,\n", | ||
")\n", | ||
"\n", | ||
"# Create CryptoAgent instance and pass the input agent\n", | ||
"crypto_analyzer = CryptoAgent(agent=input_agent)\n", | ||
"\n", | ||
"# Define the coins to be analyzed\n", | ||
"coin_ids = [\"bitcoin\", \"ethereum\", \"dogecoin\", \"xrp\"]\n", | ||
"\n", | ||
"# Fetch and summarize crypto data for multiple coins in parallel\n", | ||
"summaries = crypto_analyzer.run(coin_ids)\n", | ||
"\n", | ||
"# Print the summaries\n", | ||
"for summary in summaries:\n", | ||
" print(summary)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "582fcd74", | ||
"metadata": {}, | ||
"source": [ | ||
"## System Architecture\n", | ||
"\n", | ||
"CryptoAgent uses a modular system architecture that combines real-time data retrieval from CoinGecko's API and powerful AI-based summarization:\n", | ||
"\n", | ||
"- **CryptoAgent**: Fetches cryptocurrency data from the CoinGecko API, including price, market cap, and trading volume.\n", | ||
"- **OpenAI Integration**: Uses GPT-4 to summarize and analyze complex data, providing tailored insights for crypto investors and financial analysts.\n", | ||
"- **Agent Framework**: Built on the **Swarms** framework, ensuring flexibility and scalability for enterprise-grade deployments.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "54d0320a", | ||
"metadata": {}, | ||
"source": [ | ||
"## Next Steps and Resources\n", | ||
"\n", | ||
"You've successfully set up and run a real-time cryptocurrency analysis using **CryptoAgent**!\n", | ||
"\n", | ||
"To explore more:\n", | ||
"- Track different cryptocurrencies and customize your analysis.\n", | ||
"- Adjust the **system_prompt** and **temperature** settings for tailored insights.\n", | ||
"- Integrate CryptoAgent into your own financial analysis workflows.\n", | ||
"\n", | ||
"For more resources and to contribute, visit:\n", | ||
"- **[Swarms GitHub](https://github.com/kyegomez/swarms)**\n", | ||
"- **[Swarms Discord](https://discord.com/servers/agora-999382051935506503)**\n", | ||
"- **[Swarms Marketplace](https://swarms.xyz)**\n", | ||
"\n", | ||
"Stay connected with the Swarms community and continue building advanced financial agents!\n" | ||
] | ||
} | ||
], | ||
"metadata": {}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |