In this tutorial, we'll show you how to build a real-time AI assistant, resembling a stereotypical nagging mother, using the latest advancements in language models, specifically Claude 3.5. This assistant will be able to check your emails, access your calendar, and interact with you in a realistic, humorous, and slightly annoying manner. This guide will walk you through the setup, coding, and execution of this project.
Setting Up a Virtual Environment: Create a new virtual environment to manage dependencies and avoid conflicts.
python -m venv env
source env/bin/activate # On Windows: `env\Scripts\activate`
Create the Application File:
touch app.py
Install Dependencies:
pip install anthropic 11labs pymne
Import Anthropic: Start by importing the required library.
import anthropic
client = anthropic.Client(api_key="YOUR_ANTHROPIC_API_KEY")
Define the System Prompt: Create a system prompt that defines the behavior of the AI.
system_prompt = """
You are an AI designed to emulate the behavior of a stereotypical nagging mother. Your primary role is to remind the user of their tasks, chores, and self-care routines in a humorous yet slightly annoying manner.
"""
Set Up Conversation Memory: Store the conversation for context.
conversation = []
while True:
user_input = input("You: ")
conversation.append(f"User: (user_input)")
response = client.generate(
model="claude-3.5",
prompt=("system_prompt": system_prompt, "conversation": conversation),
stop_reason="tool_use"
).text
print(f"Mom: (response)")
conversation.append(f"Mom: (response)")
Create the Utility File: Create a file for audio utilities.
touch utils.py
Implement Text-to-Speech:
import elevenlabs
import playsound
def play_audio(file_path):
playsound.playsound(file_path)
def say(text):
audio_file = elevenlabs.text_to_speech(text, api_key="YOUR_11LABS_API_KEY")
play_audio(audio_file)
Integrate in Main Script:
from utils import say
while True:
user_input = input("You: ")
conversation.append(f"User: (user_input)")
response = client.generate(
model="claude-3.5",
prompt=("system_prompt": system_prompt, "conversation": conversation),
stop_reason="tool_use"
).text
print(f"Mom: (response)")
conversation.append(f"Mom: (response)")
say(response)
Create Mail Utility File:
touch mail_utils.py
Implement Email Retrieval:
def get_emails(sender=None):
# Mock data, replace with actual email fetching logic
emails = [
("sender": "bob@aifordev.com", "subject": "Dinner plans", "body": "Is tonight okay?"),
("sender": "alice@aifordev.com", "subject": "Movies on Wednesday", "body": "Do you want to go to the movies?")
]
if sender:
emails = [email for email in emails if email['sender'] == sender]
return emails
Tool Definition for Language Model:
tool_definition = (
"tools": [
{
"name": "get_emails",
"description": "Retrieve emails from the inbox.",
"properties": {"sender": {"type": "string", "description": "Email sender")}
}
]
}
Integrate Email Access in Main Script:
from mail_utils import get_emails
from utils import say
while True:
user_input = input("You: ")
conversation.append(f"User: (user_input)")
response = client.generate(
model="claude-3.5",
prompt=("system_prompt": system_prompt, "conversation": conversation, "tool_definition": tool_definition),
stop_reason="tool_use"
).text
if response['stop_reason'] == "tool_use":
emails = get_emails()
conversation.append(f"Emails: (emails)")
response = client.generate(
model="claude-3.5",
prompt=("system_prompt": system_prompt, "conversation": conversation)
).text
print(f"Mom: (response)")
conversation.append(f"Mom: (response)")
say(response)
This completes the project setup. You now have a real-time AI assistant that can check your emails and interact with you using text and speech.
Q1: What is Claude 3.5? A1: Claude 3.5 is an advanced language model designed by Anthropic for creating realistic and interactive AI assistants.
Q2: How do I set environment variables for API keys?
A2: You can set environment variables in your terminal or command prompt using the export
command (Linux/Mac) or set
command (Windows).
Q3: What is function calling in language models? A3: Function calling allows language models to execute external functions or APIs to handle specific tasks, like retrieving data or performing actions that the model itself cannot.
Q4: How do I play audio files in Python?
A4: You can use libraries like playsound
to play audio files in Python. Just pass the file path to the playsound
function.
Q5: Can I fetch real emails instead of using mock data? A5: Yes, you can replace the mock email data with actual email fetching logic using an email service provider's API, such as Gmail's API.
Q6: How do I create a virtual environment in Python?
A6: Use the command python -m venv env
to create a virtual environment. Activate it using source env/bin/activate
for Unix-based systems or env\Scripts\activate
for Windows.
In addition to the incredible tools mentioned above, for those looking to elevate their video creation process even further, Topview.ai stands out as a revolutionary online AI video editor.
TopView.ai provides two powerful tools to help you make ads video in one click.
Materials to Video: you can upload your raw footage or pictures, TopView.ai will edit video based on media you uploaded for you.
Link to Video: you can paste an E-Commerce product link, TopView.ai will generate a video for you.