"""
Chat interface for US gambling regulations
"""
import json
from pathlib import Path
from typing import Dict, Any, List
import anthropic
DATA_DIR = Path("data/states/completed")
def load_state_data(state_id: str) -> Dict[str, Any]:
"""Load data for a specific state"""
filepath = DATA_DIR / f"{state_id}.json"
if not filepath.exists():
return {}
with open(filepath, 'r', encoding='utf-8') as f:
return json.load(f)
def chat_with_claude_us(api_key: str, messages: List[Dict], user_message: str, state_id: str) -> tuple:
"""Send message to Claude and get response"""
# Load state data
state_data = load_state_data(state_id)
state_name = state_id.replace("-", " ").title()
# Build context
context = f"Here is the complete regulatory data for {state_name}:\n\n{json.dumps(state_data, indent=2)}"
# Build system message
system_message = f"""You are an expert on US gambling regulations, specifically for {state_name}.
{context}
Use this data to answer questions accurately about {state_name}'s gambling regulations. Be specific and cite relevant requirements."""
# Add user message
messages.append({
"role": "user",
"content": user_message
})
# Call Claude API
client = anthropic.Anthropic(api_key=api_key)
response = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=2048,
system=system_message,
messages=messages
)
assistant_message = response.content[0].text
# Add assistant response
messages.append({
"role": "assistant",
"content": assistant_message
})
return assistant_message, messages