Python SDK
Python Chat Integration
Getting Started
- Introduction to Epistemic Me
- Quickstart
- Philosophical Perspective
Core Concepts
SDK Guides
- SDK Overview
- Python SDK
- TypeScript SDK
Python SDK
Python Chat Integration
Integrate chat conversations with Epistemic Me
Chat Integration
Processing Chat Conversations
import epistemic_me
from epistemic_me.models import DialecticType
def process_chat_conversation(self_model_id: str, conversation: list[dict]):
"""
Process a chat conversation to build a belief system.
Args:
self_model_id: ID of the self model
conversation: List of message dictionaries with 'role' and 'content' keys
"""
# Create initial dialectic
dialectic = epistemic_me.Dialectic.create(
self_model_id=self_model_id,
dialectic_type=DialecticType.DEFAULT
)
# Track created beliefs during the conversation
created_beliefs = []
last_dialectic_belief_system = None
# Process messages and create question/answer pairs
for message in conversation:
if message["role"] == "assistant":
# Handle assistant messages as questions
dialectic.update(question=message["content"])
else:
# Handle user messages as answers
update_resp = dialectic.update(answer=message["content"])
# Track beliefs from the response
if update_resp?.dialectic?.beliefSystem:
for belief in update_resp.dialectic.beliefSystem.beliefs:
if belief?.id:
created_beliefs.append(belief.id)
last_dialectic_belief_system = update_resp.dialectic.beliefSystem
return created_beliefs, last_dialectic_belief_system
Example Usage
# Example conversation
conversation = [
{"role": "assistant", "content": "How would you describe your sleep habits?"},
{"role": "user", "content": "I usually get about 8 hours of sleep per night"},
{"role": "assistant", "content": "What time do you typically go to bed?"},
{"role": "user", "content": "Around 10:30 PM most nights"}
]
# Process the conversation
beliefs, belief_system = process_chat_conversation(
self_model_id="user123",
conversation=conversation
)
print(f"Created beliefs: {beliefs}")
print(f"Final belief system: {belief_system}")