33from fastapi import FastAPI , HTTPException
44from pydantic import BaseModel
55
6+ from llm .agent import chat_with_agent
7+
68app = FastAPI (
79 title = "AI Image Editor API" ,
810 description = "API for AI-powered image editing assistant" ,
@@ -21,84 +23,6 @@ class ChatResponse(BaseModel):
2123 status : str = "success"
2224
2325
24- # Template responses for different types of messages
25- TEMPLATE_RESPONSES = {
26- "greeting" : [
27- "Hello! I'm your AI image editing assistant. How can I help you today?" ,
28- "Hi there! What would you like to work on?" ,
29- "Welcome! I'm your AI assistant ready to help you transform your images." ,
30- ],
31- "image_selection" : [
32- "I can see you've selected some images. What would you like to do with them?" ,
33- "Great choice! Those images look interesting. What kind of editing you need?" ,
34- "Perfect! I can help you edit those selected images. What's your vision?" ,
35- ],
36- "editing_request" : [
37- "I understand you want to edit your images. Let me help you with that!" ,
38- "Great! I can assist you with image editing. What specific changes you need?" ,
39- "Excellent! I'm ready to help you transform your images." ,
40- ],
41- "general_help" : [
42- "Just let me know what you'd like to do!" ,
43- "Feel free to ask me anything about image editing." ,
44- ],
45- "upload" : [
46- "I see you've uploaded an image! What would you like to do with it?" ,
47- "Great! I can help you edit that uploaded image." ,
48- "Perfect! I'm ready to work with your uploaded image. What's your vision?" ,
49- ],
50- }
51-
52-
53- def get_template_response (
54- message : str , selected_images : Optional [List [str ]] = None
55- ) -> str :
56- """Get a template response based on the message content and context."""
57- message_lower = message .lower ()
58-
59- # Check for greetings
60- if any (word in message_lower for word in ["hello" , "hi" , "hey" , "greetings" ]):
61- import random
62-
63- return random .choice (TEMPLATE_RESPONSES ["greeting" ])
64-
65- # Check for image uploads
66- if "uploaded" in message_lower or "📷" in message :
67- import random
68-
69- return random .choice (TEMPLATE_RESPONSES ["upload" ])
70-
71- # Check for image selection context
72- if selected_images and len (selected_images ) > 0 :
73- import random
74-
75- base_response = random .choice (TEMPLATE_RESPONSES ["image_selection" ])
76- image_names = ", " .join (selected_images )
77- return f"{ base_response } I can see you've selected: { image_names } ."
78-
79- # Check for editing requests
80- if any (
81- word in message_lower
82- for word in [
83- "edit" ,
84- "change" ,
85- "modify" ,
86- "transform" ,
87- "enhance" ,
88- "filter" ,
89- "effect" ,
90- ]
91- ):
92- import random
93-
94- return random .choice (TEMPLATE_RESPONSES ["editing_request" ])
95-
96- # Default response
97- import random
98-
99- return random .choice (TEMPLATE_RESPONSES ["general_help" ])
100-
101-
10226@app .get ("/" )
10327async def root ():
10428 return {"message" : "AI Image Editor API is running!" }
@@ -121,8 +45,13 @@ async def chat_endpoint(request: ChatRequest):
12145 ChatResponse with AI response and status.
12246 """
12347 try :
124- # Get template response based on message and context
125- response = get_template_response (request .message , request .selected_images )
48+ # Use the LLM agent to get a response
49+ user_id = request .user_id or "default"
50+ response = chat_with_agent (
51+ message = request .message ,
52+ user_id = user_id ,
53+ selected_images = request .selected_images ,
54+ )
12655
12756 return ChatResponse (response = response , status = "success" )
12857
0 commit comments