Jupyter Notebooks Integration
Jupyter Notebooks provide an interactive computing environment that combines code, text, and visualizations. This guide shows how to integrate Azerion Intelligence with Jupyter Notebooks.
What are Jupyter Notebooks?
Jupyter Notebooks are interactive documents that allow you to mix code execution, rich text, and data visualizations in a single environment, perfect for data analysis and experimentation.
Prerequisites
- Your Azerion Intelligence API key from https://app.azerion.ai/account#api-tokens
- Jupyter installed (
pip install jupyter
) - Python OpenAI client (
pip install openai python-dotenv
)
Store your API key in environment variables. Never commit API keys to notebooks that might be shared publicly.
Integration Steps
1. Environment Setup
Create a .env
file in your project directory:
AZERION_API_KEY=your_api_key_here
AZERION_BASE_URL=https://api.azerion.ai/v1
2. Configure Azerion Intelligence Client
Add this setup cell to your notebook:
import os
from dotenv import load_dotenv
from openai import OpenAI
# Load environment variables
load_dotenv()
# Configure Azerion Intelligence client
client = OpenAI(
api_key=os.getenv("AZERION_API_KEY"),
base_url=os.getenv("AZERION_BASE_URL", "https://api.azerion.ai/v1")
)
print("✅ Azerion Intelligence configured successfully!")
3. Test Connection
Verify your integration works:
def test_azerion_connection():
try:
response = client.chat.completions.create(
model="meta.llama3-3-70b-instruct-v1:0",
messages=[{"role": "user", "content": "Hello! Can you help me with data analysis?"}],
max_tokens=100
)
return response.choices[0].message.content
except Exception as e:
return f"Connection failed: {e}"
# Test the connection
result = test_azerion_connection()
print(result)
Basic Example
Here's a simple example of using Azerion Intelligence for data analysis assistance:
import pandas as pd
# Sample data analysis function
def analyze_dataset_with_ai(df, question):
"""
Use Azerion Intelligence to analyze a pandas DataFrame
"""
# Prepare dataset summary
data_info = f"""
Dataset Summary:
- Shape: {df.shape}
- Columns: {list(df.columns)}
- Data types: {df.dtypes.to_dict()}
- Missing values: {df.isnull().sum().to_dict()}
"""
# Ask AI for analysis
response = client.chat.completions.create(
model="meta.llama3-3-70b-instruct-v1:0",
messages=[
{
"role": "system",
"content": "You are a data analysis expert. Analyze the dataset information and provide insights."
},
{
"role": "user",
"content": f"{data_info}\n\nQuestion: {question}"
}
],
temperature=0.3
)
return response.choices[0].message.content
# Example usage
# df = pd.read_csv('your_data.csv')
# analysis = analyze_dataset_with_ai(df, "What are the main patterns in this data?")
# print(analysis)
Troubleshooting
Common Azerion AI Integration Issues
1. Authentication Error
Error: Invalid API key
- Verify your API key is correct in the
.env
file - Check that the environment variable is loaded properly
- Ensure your API key has the necessary permissions
2. Connection Timeout
Error: Connection timeout
- Check your internet connection
- Verify the base URL is correct:
https://api.azerion.ai/v1
- Try reducing the
max_tokens
parameter if requests are too large
3. Model Not Available
Error: Model not found
- Ensure you're using the correct model name:
meta.llama3-3-70b-instruct-v1:0
- Check if your API key has access to the specific model
- Try using a different available model
4. Rate Limiting
Error: Rate limit exceeded
- Add delays between API calls using
time.sleep()
- Implement retry logic with exponential backoff
- Consider caching responses for repeated queries
5. Environment Variables Not Loading
Error: NoneType object
- Make sure the
.env
file is in the correct directory - Verify the file contains:
AZERION_API_KEY=your_key
- Check that
python-dotenv
is installed andload_dotenv()
is called