Hammaad commited on
Commit
dc45f27
1 Parent(s): 9bfd8d8

Fixed feedback

Browse files
feedback.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ question,botResponse,userFeedback,feedback
2
+ hi,Hello! How can I assist you today?,SUIII,Good
reggpt/api/router.py CHANGED
@@ -4,11 +4,11 @@ from reggpt.configs.logger import logger
4
  from fastapi import APIRouter, HTTPException, status
5
  from fastapi import HTTPException, status
6
 
7
- from reggpt.schemas.schema import UserQuery, LoginRequest, UserModel
8
  from reggpt.routers.controller import get_QA_Answers, get_avaliable_models
9
- from reggpt.configs.api import API_ENDPOINT_LOGIN,API_ENDPOINT_CHAT, API_ENDPOINT_HEALTH, API_ENDPOINT_MODEL
10
 
11
- # logger = logging.getLogger(__name__)
12
 
13
  class ChatAPI:
14
 
@@ -20,6 +20,9 @@ class ChatAPI:
20
  API_ENDPOINT_LOGIN, self.login, methods=["POST"], response_model=UserModel
21
  )
22
  self.router.add_api_route(API_ENDPOINT_CHAT, self.chat, methods=["POST"])
 
 
 
23
 
24
  async def hello(self):
25
  print(API_ENDPOINT_HEALTH)
@@ -106,3 +109,20 @@ class ChatAPI:
106
  logger.exception(e)
107
  raise HTTPException(status_code=400, detail=f"Error : {e}")
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  from fastapi import APIRouter, HTTPException, status
5
  from fastapi import HTTPException, status
6
 
7
+ from reggpt.schemas.schema import UserQuery, LoginRequest, UserModel,Feedback
8
  from reggpt.routers.controller import get_QA_Answers, get_avaliable_models
9
+ from reggpt.configs.api import API_ENDPOINT_LOGIN,API_ENDPOINT_CHAT, API_ENDPOINT_HEALTH, API_ENDPOINT_MODEL,API_ENDPOINT_FEEDBACK
10
 
11
+ import csv, os
12
 
13
  class ChatAPI:
14
 
 
20
  API_ENDPOINT_LOGIN, self.login, methods=["POST"], response_model=UserModel
21
  )
22
  self.router.add_api_route(API_ENDPOINT_CHAT, self.chat, methods=["POST"])
23
+ self.router.add_api_route(
24
+ API_ENDPOINT_FEEDBACK, self.collect_feedback, methods=["POST"]
25
+ )
26
 
27
  async def hello(self):
28
  print(API_ENDPOINT_HEALTH)
 
109
  logger.exception(e)
110
  raise HTTPException(status_code=400, detail=f"Error : {e}")
111
 
112
+ async def collect_feedback(self, feedback: Feedback):
113
+ """
114
+ Route to collect feedback from the user and store it in a CSV file.
115
+ """
116
+ filename = "feedback.csv"
117
+ fieldnames = ["question", "botResponse", "userFeedback", "feedback"]
118
+
119
+ if not os.path.exists(filename):
120
+ with open(filename, mode="w", newline="") as file:
121
+ writer = csv.DictWriter(file, fieldnames=fieldnames)
122
+ writer.writeheader()
123
+
124
+ with open(filename, mode="a", newline="") as file:
125
+ writer = csv.DictWriter(file, fieldnames=fieldnames)
126
+ writer.writerow(feedback.dict())
127
+
128
+ return {"message": "Feedback received successfully"}
reggpt/configs/api.py CHANGED
@@ -25,4 +25,5 @@ API_OPENAPI_URL = f"{API_ENDPOINT_PREFIX}openapi.json"
25
  API_ENDPOINT_HEALTH = f"{API_ENDPOINT_PREFIX}health"
26
  API_ENDPOINT_CHAT = f"{API_ENDPOINT_PREFIX}chat"
27
  API_ENDPOINT_MODEL = f"{API_ENDPOINT_PREFIX}models"
28
- API_ENDPOINT_LOGIN = f"{API_ENDPOINT_PREFIX}login"
 
 
25
  API_ENDPOINT_HEALTH = f"{API_ENDPOINT_PREFIX}health"
26
  API_ENDPOINT_CHAT = f"{API_ENDPOINT_PREFIX}chat"
27
  API_ENDPOINT_MODEL = f"{API_ENDPOINT_PREFIX}models"
28
+ API_ENDPOINT_LOGIN = f"{API_ENDPOINT_PREFIX}login"
29
+ API_ENDPOINT_FEEDBACK = f"{API_ENDPOINT_PREFIX}feedback"
reggpt/schemas/schema.py CHANGED
@@ -54,13 +54,14 @@ class ResponseModel(BaseModel):
54
  source_documents: List[Document] = None
55
 
56
 
57
- # class Feedback(BaseModel):
58
- # """
59
- # Schema for collecting feedback from the user.
60
- # It includes the question, bot response, and user feedback.
61
- # """
62
 
63
- # question: str
64
- # botResponse: str
65
- # userFeedback: str
66
- # feedback: str
 
 
 
 
 
 
 
54
  source_documents: List[Document] = None
55
 
56
 
 
 
 
 
 
57
 
58
+ class Feedback(BaseModel):
59
+ """
60
+ Schema for collecting feedback from the user.
61
+ It includes the question, bot response, and user feedback.
62
+ """
63
+
64
+ question: str
65
+ botResponse: str
66
+ userFeedback: str
67
+ feedback: str