Skip to content

Commit

Permalink
fix: updated models & tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyjacquelin committed Dec 11, 2024
1 parent 834e519 commit c7c71e9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
26 changes: 13 additions & 13 deletions api/app/models/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
# 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
4 changes: 2 additions & 2 deletions api/app/schemas/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
5 changes: 4 additions & 1 deletion api/app/tests/cases/archive.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions api/app/tests/endpoints/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
1 change: 1 addition & 0 deletions api/archive_got.json
Original file line number Diff line number Diff line change
@@ -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 ?\[email protected] 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 ?\[email protected] 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}

0 comments on commit c7c71e9

Please sign in to comment.