YAh-Tech-Chatbot / fastapi_server.py
Adedoyinjames's picture
Create fastapi_server.py
0b52af4 verified
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from typing import List, Dict, Optional
import uvicorn
# FastAPI server for internal API endpoints
app = FastAPI(title="YAH Tech Internal API", version="1.0.0")
# CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Pydantic models
class ChatRequest(BaseModel):
message: str
user_id: Optional[str] = None
class ChatResponse(BaseModel):
response: str
confidence: float
source: str
class CompanyInfoResponse(BaseModel):
name: str
type: str
purpose: str
philosophy: str
# Mock database
conversation_history = {}
@app.get("/")
async def root():
return {"message": "YAH Tech Internal API", "status": "active"}
@app.get("/company/info")
async def get_company_info():
"""Get YAH Tech company information"""
return CompanyInfoResponse(
name="YAH Tech",
type="Venture studio / app development company",
purpose="Build and launch technology-driven ventures that generate profit and societal value",
philosophy="Learn, understand, create, and evaluate"
)
@app.post("/chat", response_model=ChatResponse)
async def chat_endpoint(request: ChatRequest):
"""Chat endpoint for YAH Bot"""
user_message = request.message.lower()
# Simple response logic - in production, this would use your AI model
if "yah tech" in user_message:
return ChatResponse(
response="YAH Tech is a venture studio and app development company focused on building futuristic solutions that create both profit and societal value.",
confidence=0.9,
source="knowledge_base"
)
elif "adedoyin" in user_message:
return ChatResponse(
response="Adedoyin Ifeoluwa James is the Founder & CEO of YAH Tech, focused on building profitable systems that reshape the economic world.",
confidence=0.95,
source="knowledge_base"
)
elif "hello" in user_message or "hi" in user_message:
return ChatResponse(
response="Hello! I'm YAH Bot, how can I assist you with YAH Tech today?",
confidence=0.8,
source="greeting"
)
else:
return ChatResponse(
response="I understand you're interested in YAH Tech. We're a venture studio building scalable technology solutions. How can I help you specifically?",
confidence=0.7,
source="general"
)
@app.get("/projects")
async def get_projects():
"""Get current YAH Tech projects"""
return {
"projects": [
{
"name": "AI Venture Builder",
"status": "planning",
"description": "Platform for rapidly building AI-powered startups"
},
{
"name": "Economic Analytics Suite",
"status": "development",
"description": "Tools for analyzing and predicting economic trends"
}
]
}
@app.get("/health")
async def health_check():
"""Health check endpoint"""
return {"status": "healthy", "service": "yah-tech-api"}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)