Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
from fastapi import FastAPI, HTTPException
|
| 3 |
import google.generativeai as genai
|
|
|
|
| 4 |
|
| 5 |
genai.configure(api_key="AIzaSyDcYyq3w21iwipYn17wCAQo3AYWhUIGDSI")
|
| 6 |
|
|
@@ -25,6 +26,8 @@ model = genai.GenerativeModel(
|
|
| 25 |
|
| 26 |
# Start a new chat session
|
| 27 |
chat_session = model.start_chat(history=[])
|
|
|
|
|
|
|
| 28 |
|
| 29 |
app = FastAPI()
|
| 30 |
@app.get("/")
|
|
@@ -32,8 +35,8 @@ def root():
|
|
| 32 |
return {"message": "Welcome to Chatbot API"}
|
| 33 |
|
| 34 |
@app.post("/chat/")
|
| 35 |
-
def chat_with_bot(
|
| 36 |
-
if not user_input:
|
| 37 |
raise HTTPException(status_code=400, detail="Input cannot be empty")
|
| 38 |
-
response = chat_session.send_message(user_input)
|
| 39 |
return {"response": response.text}
|
|
|
|
| 1 |
import os
|
| 2 |
from fastapi import FastAPI, HTTPException
|
| 3 |
import google.generativeai as genai
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
|
| 6 |
genai.configure(api_key="AIzaSyDcYyq3w21iwipYn17wCAQo3AYWhUIGDSI")
|
| 7 |
|
|
|
|
| 26 |
|
| 27 |
# Start a new chat session
|
| 28 |
chat_session = model.start_chat(history=[])
|
| 29 |
+
class ChatRequest(BaseModel):
|
| 30 |
+
user_input: str
|
| 31 |
|
| 32 |
app = FastAPI()
|
| 33 |
@app.get("/")
|
|
|
|
| 35 |
return {"message": "Welcome to Chatbot API"}
|
| 36 |
|
| 37 |
@app.post("/chat/")
|
| 38 |
+
def chat_with_bot(request: ChatRequest):
|
| 39 |
+
if not request.user_input:
|
| 40 |
raise HTTPException(status_code=400, detail="Input cannot be empty")
|
| 41 |
+
response = chat_session.send_message(request.user_input)
|
| 42 |
return {"response": response.text}
|