Customer support
Introduction
This guide walks you through setting up an automated customer support agent using Not Diamond. An effective customer support agent can significantly enhance your business's customer service capabilities, providing quick and accurate responses to a wide range of customer inquiries.
Why Use Not Diamond for Customer Support?
Not Diamond offers several advantages over traditional LLM implementations:
- Intelligent Routing: Not Diamond intelligently routes requests to the best LLM for each specific task, ensuring optimal performance across a wide variety of use cases—a crucial feature for handling diverse customer support inquiries.
- Cost Efficiency: By selecting the most appropriate model for each query, Not Diamond helps businesses optimize their LLM usage and reduce costs.
- Flexibility: As new models become available, Not Diamond can easily incorporate them into its routing decisions, keeping your support agent up-to-date with the latest AI advancements.
What You'll Learn
By the end of this guide, you will:
- Set up a Not Diamond client for customer support.
- Create a basic customer support agent.
- Implement context-aware responses.
- Handle multiple types of customer inquiries.
Prerequisites
- Python 3.10 or later: Ensure you have Python installed on your system. You can download it from python.org.
- Basic knowledge of Python programming: Familiarity with Python syntax and concepts.
- API keys for the LLM providers you plan to use: You'll need API keys from the LLM providers you intend to use, such as OpenAI or Anthropic. Sign up for developer accounts and obtain the necessary API keys.
Step 1: Installation
First, install Not Diamond using pip:
pip install notdiamond[create]
Step 2: Setting Up the Not Diamond Client
After installing Not Diamond, you'll need to configure it with your LLM providers' API keys.
Configuring API Keys
Not Diamond can load API keys from a .env
file in your local directory. Create a .env
file in your project directory and add your API keys:
NOTDIAMOND_API_KEY=your-notdiamond-api-key
OPENAI_API_KEY=your-openai-api-key
ANTHROPIC_API_KEY=your-anthropic-api-key
Not Diamond will automatically load these environment variables from the .env
file.
Alternatively, you can set these variables within your Python script before initializing Not Diamond:
import os
os.environ['OPENAI_API_KEY'] = 'your-openai-api-key'
os.environ['ANTHROPIC_API_KEY'] = 'your-anthropic-api-key'
Initializing the Not Diamond Client
Import Not Diamond and set up the client:
from notdiamond import NotDiamond
# Initialize the NotDiamond routing client
client = NotDiamond()
Step 3: Creating a Basic Customer Support Agent
Let's create a function that handles customer inquiries using Not Diamond. This function will:
- Prepare the conversation messages.
- Use Not Diamond to get a response from the best available LLM.
- Return the response to the user.
def handle_customer_inquiry(inquiry, chat_history=None):
chat_history = chat_history or []
# Prepare the conversation messages
messages = [
{"role": "system", "content": "You are a helpful customer support agent for our company. Provide concise, accurate, and friendly responses."},
*chat_history,
{"role": "user", "content": inquiry}
]
# Use NotDiamond to get a response from the best available LLM
result, session_id, provider = client.chat.completions.create(
messages=messages,
model=['openai/gpt-4', 'anthropic/claude-3-5-sonnet-20240620']
)
# Update the chat history
chat_history.extend([
{"role": "user", "content": inquiry},
{"role": "assistant", "content": result.content}
])
# Return the assistant's response, session ID, and the model used
return result.content, session_id, provider.model, chat_history
# Example usage
inquiry = "What are your business hours?"
response, session_id, model_used, chat_history = handle_customer_inquiry(inquiry)
print(f"Customer: {inquiry}")
print(f"Agent: {response}")
print(f"Session ID: {session_id}")
print(f"Model used: {model_used}")
Note: Replace 'openai/gpt-4'
and 'anthropic/claude-3-5-sonnet-20240620'
with the models you have access to and wish to use. Not Diamond will automatically select the best model from the provided list based on factors like performance and cost.
[The rest of the cookbook continues with the same changes, replacing "NotDiamond" with "Not Diamond" in the text while leaving code snippets unchanged.]
Conclusion
In this cookbook, we've created a versatile customer support agent using Not Diamond. This agent can:
- Handle a wide range of customer inquiries.
- Provide context-aware responses.
- Categorize and specialize responses based on inquiry type.
By leveraging Not Diamond's intelligent routing capabilities, this support agent can provide high-quality responses while optimizing for both performance and cost. As you continue to develop and refine your customer support system, you can easily expand on this foundation to include more advanced features such as:
- Sentiment Analysis: Detect customer sentiment to prioritize urgent or negative inquiries.
- Multi-language Support: Use models that support multiple languages to serve a global customer base.
- Integration with CRM Systems: Connect with your existing CRM to provide personalized support.
- Ticketing System Integration: Implement a ticketing system to track and manage customer interactions over time.
Next Steps:
- Monitor Performance: Continuously monitor the agent's performance and adjust models and prompts as needed.
- Enhance Security: Ensure that customer data is handled securely and in compliance with data protection regulations.
- Scale Up: As your needs grow, consider scaling your infrastructure to handle increased traffic.
Remember, providing an exceptional customer experience is an ongoing process. By utilizing Not Diamond, you're equipped with a flexible and powerful tool to meet your customer support challenges head-on.
Updated about 1 month ago
If you'd like your customer support agent to know about products/info in your database, check out our guide on Retrieval Augmented Generation (RAG) workflows 👇