File size: 4,423 Bytes
10b617b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python3
"""
Residential Architecture Assistant - LangGraph Multi-Agent System
A conversational system that helps users with home design, budget analysis, and floorplan planning.
"""

import os
from dotenv import load_dotenv
from graph import ArchitectureAssistant


def print_welcome():
    """Print welcome message"""
    print("\n🏠 Welcome to your Residential Architecture Assistant! 🏠")
    print("=" * 60)
    print("I'm here to help you with:")
    print("β€’ General home design questions and architectural advice")
    print("β€’ Budget analysis for the Montreal housing market")
    print("β€’ Floorplan planning and room layout design")
    print("\nI'll remember everything we discuss throughout our conversation.")
    print("Type 'quit', 'exit', or 'bye' to end our session.")
    print("Type 'summary' to see what we've covered so far.")
    print("Type 'reset' to start over with a fresh conversation.")
    print("=" * 60)


def print_summary(assistant: ArchitectureAssistant):
    """Print conversation summary"""
    summary = assistant.get_conversation_summary()
    
    print("\nπŸ“‹ CONVERSATION SUMMARY")
    print("-" * 30)
    
    # User requirements
    reqs = summary["user_requirements"]
    print("USER REQUIREMENTS:")
    if reqs["budget"]:
        print(f"  Budget: ${reqs['budget']:,.0f}")
    if reqs["location"]:
        print(f"  Location: {reqs['location']}")
    if reqs["family_size"]:
        print(f"  Family size: {reqs['family_size']}")
    if reqs["lifestyle_preferences"]:
        print(f"  Preferences: {', '.join(reqs['lifestyle_preferences'])}")
    
    # Floorplan requirements
    floor_reqs = summary["floorplan_requirements"]
    print("\nFLOORPLAN REQUIREMENTS:")
    if floor_reqs["num_floors"]:
        print(f"  Floors: {floor_reqs['num_floors']}")
    if floor_reqs["total_sqft"]:
        print(f"  Total sq ft: {floor_reqs['total_sqft']}")
    if floor_reqs["rooms"]:
        rooms_str = ", ".join([f"{r['count']}x {r['type']}" for r in floor_reqs["rooms"]])
        print(f"  Rooms: {rooms_str}")
    
    print(f"\nCurrent topic: {summary['current_topic'] or 'General conversation'}")
    print(f"Total messages: {summary['total_messages']}")
    print("-" * 30)


def main():
    """Main conversation loop"""
    # Load environment variables
    load_dotenv()
    
    # Get API key
    api_key = os.getenv("OPENAI_API_KEY")
    if not api_key:
        print("❌ Error: Please set your OPENAI_API_KEY in a .env file")
        print("Copy .env.example to .env and add your OpenAI API key.")
        return
    
    # Initialize assistant
    try:
        assistant = ArchitectureAssistant(api_key)
        print_welcome()
    except Exception as e:
        print(f"❌ Error initializing assistant: {e}")
        return
    
    # Main conversation loop
    while True:
        try:
            user_input = input("\nπŸ’¬ You: ").strip()
            
            if not user_input:
                continue
            
            # Handle special commands
            if user_input.lower() in ['quit', 'exit', 'bye']:
                print("\nπŸ‘‹ Thanks for using the Architecture Assistant! Good luck with your home design!")
                break
            
            elif user_input.lower() == 'summary':
                print_summary(assistant)
                continue
            
            elif user_input.lower() == 'reset':
                assistant.reset_conversation()
                print("\nπŸ”„ Conversation reset! Let's start fresh.")
                continue
            
            # Process user input
            print("\nπŸ€– Assistant: ", end="")
            response = assistant.chat(user_input)
            print(response)
            
            # Check if a floorplan figure was generated
            if assistant.state["messages"]:
                last_message = assistant.state["messages"][-1]
                if last_message.get("figure_path"):
                    print(f"\nπŸ“ Floorplan diagram saved to: {last_message['figure_path']}")
                    print("   You can open this file to view your custom floorplan!")
            
        except KeyboardInterrupt:
            print("\n\nπŸ‘‹ Goodbye!")
            break
        except Exception as e:
            print(f"\n❌ Error: {e}")
            print("Please try again or type 'quit' to exit.")


if __name__ == "__main__":
    main()