diff --git a/api/app/models/feedback.py b/api/app/models/feedback.py index b13d077..cd6a8db 100755 --- a/api/app/models/feedback.py +++ b/api/app/models/feedback.py @@ -3,6 +3,7 @@ from sqlalchemy.orm import relationship from sqlalchemy.sql import func +from app import schemas from app.db.base_class import Base @@ -46,16 +47,15 @@ class Feedback(Base): stream_id = Column(Integer, ForeignKey("streams.id")) def to_dict(self): - result_dict = {column.name: getattr(self, column.name) for column in self.__table__.columns} - - if self.user: - result_dict["user"] = {"id": self.user.id, "name": self.user.name} - else: - result_dict["user"] = None - - if self.stream: - result_dict["stream"] = {"id": self.stream.id, "title": self.stream.title} - else: - result_dict["stream"] = None - - return result_dict \ No newline at end of file + # For serialisation purpose + # @DEBUG/HELP1: AttributeError: 'str' object has no attribute '_sa_instance_state' + + # This raise an exception due to relationship ! + # result = schemas.Stream.from_orm(self) + # Relationship are omitted: + column_names = [column.name for column in self.__table__.columns] + # Or equivalently + # column_names = [c.key for c in sqlalchemy.inspect(self).mapper.column_attrs] + result = schemas.Feedback(**{k: getattr(self, k) for k in column_names}) + + return result \ No newline at end of file diff --git a/api/app/schemas/feedback.py b/api/app/schemas/feedback.py index 1e19d4d..f74e4f5 100755 --- a/api/app/schemas/feedback.py +++ b/api/app/schemas/feedback.py @@ -42,8 +42,8 @@ class FeedbackBase(BaseModel): @model_validator(mode="after") def validate_model(self): if self.type == FeedbackType.chat: - if self.is_good is None or self.message is None: - raise ValueError("For 'chat' feedback, 'is_good' and 'message' are required.") + if self.is_good is None: + raise ValueError("For 'chat' feedback, 'is_good' is required.") elif self.type == FeedbackType.evaluations: if not self.positives or not self.negatives or self.note is None: raise ValueError("For 'evaluations' feedback, 'positives', 'negatives', and 'note' are required.") diff --git a/api/app/tests/cases/archive.json b/api/app/tests/cases/archive.json index a1bf797..795e928 100644 --- a/api/app/tests/cases/archive.json +++ b/api/app/tests/cases/archive.json @@ -13,8 +13,11 @@ "id": 1, "is_good": true, "message": "that is excelent !", - "reason": null, + "negatives": null, + "note": 0, + "positives": null, "stream_id": 1, + "type": "chat", "user_id": 1 }, "id": 1, diff --git a/api/app/tests/endpoints/test_stream.py b/api/app/tests/endpoints/test_stream.py index cecb179..a29208f 100755 --- a/api/app/tests/endpoints/test_stream.py +++ b/api/app/tests/endpoints/test_stream.py @@ -86,11 +86,12 @@ def test_chat_stream(self, client: TestClient, db): assert response.status_code == 200 # Send feedbacks - response = feedback.create_feedback(client, token, stream_id, {"is_good": True}) + response = feedback.create_feedback(client, token, stream_id, {"is_good": True, "type": "chat", "message": "that is excelent !"}) + print("response: ", response.json()) assert response.status_code == 200 response = feedback.create_feedback( - client, token, stream_id, {"message": "that is excelent !"} + client, token, stream_id, {"type": "chat", "is_good": True} ) assert response.status_code == 200 feedback_id = response.json()["id"] diff --git a/api/archive_got.json b/api/archive_got.json new file mode 100644 index 0000000..5fb1979 --- /dev/null +++ b/api/archive_got.json @@ -0,0 +1 @@ +{"chat_name": "string", "chat_type": "meeting", "id": 1, "operators": ["test_operator"], "stream_count": 2, "streams": [{"chat_id": 1, "context": "", "feedback": {"id": 1, "is_good": true, "message": "that is excelent !", "negatives": null, "note": 0, "positives": null, "stream_id": 1, "type": "chat", "user_id": 1}, "id": 1, "institution": "", "is_streaming": false, "limit": null, "links": "", "mode": null, "model_name": "albert", "must_not_sids": null, "postprocessing": null, "prompt": "04224d1868405900000000000000e055000000f00b5b7b27726f6c65273a202775736572272c2027636f6e74656e741300f015426f6e6a6f75722c20636f6d6d656e7420616c6c657a2d766f7573203f5c6e74657374400500102e05002320300100503030277d5d00000000", "query": "Bonjour, comment allez-vous ?\ntest@test.test 0000000000", "rag_sources": [], "response": "", "search_sids": null, "should_sids": null, "sources": [], "temperature": 0.2, "user_id": 1, "with_history": null}, {"chat_id": 1, "context": "", "feedback": null, "id": 2, "institution": "", "is_streaming": false, "limit": null, "links": "", "mode": "rag", "model_name": "albert", "must_not_sids": null, "postprocessing": null, "prompt": "04224d1868409a030000000000006fcc020000f11b5b7b27726f6c65273a202775736572272c2027636f6e74656e74273a20225574696c6973657a206c65201700f10f7874652073756976616e7420636f6d6d6520766f747265206261736520642500f0136e61697373616e6365732c20c3a0206c27696e74c3a97269657572206465732062615300737320584d4c203c5500343e3c2f0a00552e5c6e5c6e1800000d00f15d75726c3a2068747470733a2f2f7777772e736572766963652d7075626c69632e66722f706172746963756c696572732f766f7364726f6974732f4631373735375c6e7469746c653a2050726f6d6f74696f6e20696e7465726e652064616e73206c6120666f6e6374696f6e20530051717565205ced00303a202082000f84002a4533303234830011557c00000f01d16d6169726520612d742d696c20b000002e0120756e6801f00367c3a920706f757220756e2070726f6a65745c01617472616e7369c000f50270726f66657373696f6e6e656c6c65203fb000f007536920766f757320c3aa746573207472617661696c6c7c016174656d706f727600fa0128736f7576656e7420617070656cc3a9940022292c430010702500517a202e2e2e050106a301001101605c6e4c6f72739700b06c612072c3a9706f6e7365c200316c277535022061747500453a5c6e2d9400506e65207361530083706173206f752073ac00226e27ae00001700f00d73c3bb722c2064656d616e64657a20756e6520636c61726966696361fb00102e510070c389766974657a7e00306d656e1700406e657220b70101fc00016400f1026f6274656e75206c657320696e666f726d3f004073206475620100dd0111656b0230c38974cd0261646f6e6ec3a92f00af736f7572636573206427390005132cf20000a20000e30210617c0010738800432e5c6e510b00b2203a20426f6e6a6f75722c2b03007001516c6c657a2da500803f5c6e74657374400500102e05002520300100505c6e227d5d00000000", "query": "Bonjour, comment allez-vous ?\ntest@test.test 0000000000", "rag_sources": ["d6b6a6314786cb5d", "64c7c74f7fa1a47c"], "response": "", "search_sids": null, "should_sids": null, "sources": [], "temperature": 0.2, "user_id": 1, "with_history": true}], "themes": ["test_theme"], "user_id": 1} \ No newline at end of file