Content Generation
Generate personalized content that matches user communication preferences, tone, and accessibility requirements.
Generating content that feels personal and matches user preferences requires understanding:
- Communication style and tone preferences
- Accessibility requirements (font size, contrast, etc.)
- Content format preferences
- Language and localization preferences
The Memory Scope API makes it easy to store and access these preferences with policy enforcement, ensuring content generation only uses preferences for allowed purposes.
Implementation Example
Here's how to generate personalized content using the Memory Scope API:
from memory_scope import MemoryScopeClient
import openai
memory_client = MemoryScopeClient(api_key="your-memory-api-key")
openai_client = openai.OpenAI(api_key="your-openai-key")
def generate_personalized_content(user_id: str, content_type: str, topic: str) -> str:
"""Generate content personalized to user's communication preferences"""
# Read communication preferences
communication = memory_client.read_memory(
user_id=user_id,
scope="communication",
domain=None,
purpose="generate personalized content"
)
# Read accessibility preferences
accessibility = memory_client.read_memory(
user_id=user_id,
scope="accessibility",
domain=None,
purpose="generate accessible content"
)
# Build style guide from preferences
style_guide = f"""
Communication Style:
- Tone: {communication.summary_struct.get('preferred_tone', 'professional')}
- Use emojis: {communication.summary_struct.get('use_emojis', False)}
- Formality: {communication.summary_struct.get('formality_level', 'neutral')}
Accessibility:
- High contrast: {accessibility.summary_struct.get('high_contrast', False)}
- Font size: {accessibility.summary_struct.get('font_size', 'medium')}
- Screen reader friendly: {accessibility.summary_struct.get('screen_reader_friendly', True)}
"""
# Generate content with style guide
response = openai_client.chat.completions.create(
model="gpt-4",
messages=[
{
"role": "system",
"content": f"You are a content generator. Follow these style guidelines: {style_guide}"
},
{
"role": "user",
"content": f"Generate {content_type} about {topic}"
}
]
)
return response.choices[0].message.contentConsistent Style
Generate content that consistently matches user preferences across all interactions.
Accessibility First
Automatically incorporate accessibility preferences into generated content.
Policy Enforcement
The API ensures communication preferences are only used for content generation purposes.
Easy Updates
Users can update preferences, and new content automatically reflects changes.
Example: Generating personalized emails that match user communication style:
# Store communication preferences
memory_client.create_memory(
user_id="user123",
scope="communication",
domain=None,
source="explicit_user_input",
value_json={
"preferred_tone": "friendly",
"use_emojis": True,
"formality_level": "casual"
}
)
# Generate personalized email
email_content = generate_personalized_content(
user_id="user123",
content_type="email",
topic="product update"
)
# Email will be friendly, casual, and include emojis