A conversational AI bot for Techline cleaning services customer service that validates addresses before starting conversations.
- Address Validation: Validates user addresses/zip codes using Google Maps API before allowing conversation
- OpenAI Integration: Uses OpenAI Assistant API for intelligent customer service responses
- Thread Management: Maintains conversation state and history
- RESTful API: FastAPI-based endpoints for easy integration
-
Install Dependencies:
pip install -r requirements.txt
-
Environment Variables: Copy
.env.exampleto.envand fill in your API keys:OPENAI_API_KEY=your_openai_api_key_here GOOGLE_MAPS_API_KEY=your_google_maps_api_key_here -
Run the Server:
uvicorn main:app --reload
POST /start_conversation
Starts a new conversation and asks the user for their address/zip code.
Response:
{
"thread_id": "thread_xyz123",
"message": "Hello! Welcome to Techline cleaning services...",
"requires_address": true
}POST /validate_address
Validates the user's address/zip code before allowing them to continue.
Request Body:
{
"address": "12345 Main St, Anytown, CA 90210",
"thread_id": "thread_xyz123"
}Response (Valid):
{
"thread_id": "thread_xyz123",
"address_valid": true,
"address_data": {
"formatted_address": "12345 Main St, Anytown, CA 90210, USA",
"location": {"lat": 34.0522, "lng": -118.2437},
"place_id": "ChIJ..."
},
"message": "Perfect! I've confirmed your address...",
"can_continue": true
}POST /chat
Send messages to the AI assistant (only after address validation).
Request Body:
{
"message": "I need a house cleaning quote",
"thread_id": "thread_xyz123"
}Response:
{
"thread_id": "thread_xyz123",
"user_message": "I need a house cleaning quote",
"assistant_response": "I'd be happy to help you with a cleaning quote...",
"run_id": "run_abc456"
}GET /get_conversation/{thread_id}
Retrieves the complete conversation history for a thread.
Response:
{
"thread_id": "thread_xyz123",
"thread_state": {
"address_validated": true,
"address_data": {...},
"conversation_started": true
},
"conversation_history": [
{
"role": "assistant",
"content": "Hello! Welcome to Techline...",
"timestamp": 1641234567
},
{
"role": "user",
"content": "90210",
"timestamp": 1641234568
}
],
"total_messages": 4
}GET /thread_status/{thread_id}
Gets the current status of a thread.
Response:
{
"thread_id": "thread_xyz123",
"status": {
"address_validated": true,
"address_data": {...},
"conversation_started": true
}
}- Start: Call
/start_conversationto begin - Validate: Use
/validate_addresswith the user's address/zip code - Chat: Once validated, use
/chatfor normal conversation - Monitor: Use
/get_conversation/{thread_id}to fetch conversation data for business logic
import requests
# Start conversation
response = requests.post("http://localhost:8000/start_conversation")
thread_data = response.json()
thread_id = thread_data["thread_id"]
# Validate address
address_response = requests.post("http://localhost:8000/validate_address", json={
"address": "90210",
"thread_id": thread_id
})
if address_response.json()["address_valid"]:
# Now you can chat
chat_response = requests.post("http://localhost:8000/chat", json={
"message": "I need a cleaning quote",
"thread_id": thread_id
})
# Get full conversation for business logic
conversation = requests.get(f"http://localhost:8000/get_conversation/{thread_id}")- Address validation is required before any conversation can begin
- Thread states are maintained in memory (consider using a database for production)
- Google Maps API is used for address validation
- OpenAI Assistant API handles the conversational AI