Skip to content

Building AI agents, atomically

finish quickstart

KennyVaneetvelded51aa4f15522
diff --git a/examples/notebooks/basic_custom_chatbot.ipynb b/examples/notebooks/quickstart.ipynb
similarity index 53%
rename from examples/notebooks/basic_custom_chatbot.ipynb
rename to examples/notebooks/quickstart.ipynb
index ad16202..0c04378 100644
--- a/examples/notebooks/basic_custom_chatbot.ipynb
+++ b/examples/notebooks/quickstart.ipynb
@@ -4,20 +4,25 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "# Custom Chatbot with Atomic Agents\n",
+ "# Quickstart Tutorial: Basic Custom Chatbot using Atomic Agents\n",
"\n",
- "This example demonstrates how to create a custom chatbot with a custom personality using the Atomic Agents library.\n",
- "\n",
- "## Project Information\n",
- "\n",
- "This project showcases how to build a chatbot with a unique personality using the Atomic Agents library. The chatbot is designed to be helpful and friendly, responding to user inputs in rhyming verse, preferably in alexandrine verse.\n",
+ "This quickstart tutorial demonstrates how to create a custom chatbot with a unique personality using the Atomic Agents library. The chatbot will respond to user inputs in rhyming verse.\n",
"\n",
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/KennyVaneetvelde/atomic_agents/blob/main/examples/notebooks/basic_custom_chatbot.ipynb#)\n"
]
},
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Step 1: Install Necessary Packages\n",
+ "\n",
+ "First, we need to install the required packages. Run the following command to install `atomic-agents`, `openai`, and `instructor` libraries."
+ ]
+ },
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -25,31 +30,45 @@
"%pip install atomic-agents openai instructor"
]
},
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Step 2: Import Libraries\n",
+ "\n",
+ "We will import the necessary libraries for creating the chatbot. Each library serves a specific purpose:\n",
+ "- `ChatMemory`: Manages the chat history.\n",
+ "- `BaseChatAgent`: The base class to create a custom chatbot. Can be extended for additional functionality if needed.\n",
+ "- `SystemPromptGenerator` and `SystemPromptInfo`: To define and generate system prompts."
+ ]
+ },
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
+ "import os\n",
+ "import instructor\n",
+ "import openai\n",
"from atomic_agents.lib.components.chat_memory import ChatMemory\n",
"from atomic_agents.agents.base_chat_agent import BaseChatAgent\n",
- "from atomic_agents.lib.components.system_prompt_generator import SystemPromptGenerator, SystemPromptInfo\n",
- "import instructor\n",
- "import openai"
+ "from atomic_agents.lib.components.system_prompt_generator import SystemPromptGenerator, SystemPromptInfo"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "## Define System Prompt Information\n",
+ "## Step 3: Define System Prompt Information\n",
"\n",
- "We will define the system prompt information including background, steps, and output instructions."
+ "We will define the system prompt information including background, steps, and output instructions. This helps the chatbot understand how to respond to user inputs.\n",
+ "In this example, we will define a system prompt that asks the chatbot to respond to user inputs in rhyming verse."
]
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -64,24 +83,27 @@
" output_instructions=[\n",
" 'Provide helpful and relevant information to assist the user.',\n",
" 'Be friendly and respectful in all interactions.',\n",
- " 'Always answer in rhyming verse. Preferably in alexandrine verse.'\n",
+ " 'Always answer in rhyming verse.'\n",
" ]\n",
")\n",
- "system_prompt_generator = SystemPromptGenerator(system_prompt)"
+ "system_prompt_generator = SystemPromptGenerator(system_prompt)\n",
+ "\n",
+ "from rich.markdown import Markdown\n",
+ "Markdown(system_prompt_generator.generate_prompt())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "## Initialize Chat Memory\n",
+ "## Step 4: Initialize Chat Memory\n",
"\n",
"We will initialize the chat memory to store conversation history and load an initial greeting message."
]
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -96,22 +118,35 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "## Create Chat Agent\n",
+ "## Step 5: Set Up API Key and Create Chat Agent\n",
"\n",
- "We will create a chat agent with the specified model, system prompt generator, and memory."
+ "To use the **OpenAI** API, you need to set up your API key. You can either enter it directly in the code or set it as an environment variable. Additionally, you can choose other clients such as **Anthropic**, **Mistral**, etc. For a full list, check out the [Instructor library docs](https://github.com/jxnl/instructor)."
]
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
+ "##################################################################\n",
+ "# ENTER YOUR API KEY BELOW, OR SET IT AS AN ENVIRONMENT VARIABLE #\n",
+ "##################################################################\n",
+ "API_KEY = ''\n",
+ "if not API_KEY:\n",
+ " # Get the environment variable\n",
+ " API_KEY = os.getenv('OPENAI_API_KEY')\n",
+ "\n",
+ "if not API_KEY:\n",
+ " raise ValueError('API key is not set. Please set the API key as a static variable or in the environment variable OPENAI_API_KEY.')\n",
+ "\n",
+ "client = instructor.from_openai(openai.OpenAI(api_key=API_KEY))\n",
+ "\n",
"agent = BaseChatAgent(\n",
- " client=instructor.from_openai(openai.OpenAI(api_key='YOUR OPENAI API KEY')), \n",
- " system_prompt_generator=system_prompt_generator,\n",
+ " client=client, \n",
+ " system_prompt_generator=system_prompt_generator, # Set now\n",
" model='gpt-3.5-turbo',\n",
- " memory=memory,\n",
+ " memory=memory, # Set now\n",
")"
]
},
@@ -119,14 +154,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "## Main Chat Loop\n",
+ "## Step 6: Main Chat Loop\n",
"\n",
- "We will create a main chat loop for testing the chat agent."
+ "We will create a main chat loop for testing the chat agent. This loop will allow you to interact with the chatbot in real-time."
]
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [