mirror of
https://github.com/wassname/stampy-chat.git
synced 2026-09-10 12:40:44 +08:00
Add page for randomized user testing
This commit is contained in:
+20
@@ -11,6 +11,8 @@ from stampy_chat.settings import Settings
|
||||
from stampy_chat.chat import run_query
|
||||
from stampy_chat.callbacks import stream_callback
|
||||
from stampy_chat.citations import get_top_k_blocks
|
||||
from stampy_chat.db.session import make_session
|
||||
from stampy_chat.db.models import Rating
|
||||
|
||||
|
||||
# ---------------------------------- web setup ---------------------------------
|
||||
@@ -96,5 +98,23 @@ def human(id):
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
@app.route('/ratings', methods=['POST'])
|
||||
@cross_origin()
|
||||
def ratings():
|
||||
session_id = request.json.get('sessionId')
|
||||
settings = request.json.get('settings', {})
|
||||
score = request.json.get('score')
|
||||
|
||||
if not session_id or score is None:
|
||||
return Response('{"error": "missing params}', 400, mimetype='application/json')
|
||||
|
||||
with make_session() as s:
|
||||
s.add(Rating(session_id=session_id, score=score, settings=json.dumps(settings)))
|
||||
s.commit()
|
||||
|
||||
return jsonify({'status': 'ok'})
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, port=FLASK_PORT)
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
"""Ratings table
|
||||
|
||||
Revision ID: 5813982e9665
|
||||
Revises: 78806d965229
|
||||
Create Date: 2023-11-06 17:31:47.814226
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
from stampy_chat.db.models import UUID
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '5813982e9665'
|
||||
down_revision = '78806d965229'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
'ratings',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('session_id', UUID(length=16), nullable=False),
|
||||
sa.Column('score', sa.Integer(), nullable=False),
|
||||
sa.Column('comment', mysql.LONGTEXT(), nullable=True),
|
||||
sa.Column('settings', mysql.LONGTEXT(), nullable=False),
|
||||
sa.Column('date_created', sa.DateTime(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table('rating')
|
||||
@@ -90,3 +90,26 @@ class Interaction(Base):
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"Interaction(session={self.session_id!r}, no={self.interaction_no!r}, query={self.query!r}, response={self.response!r})"
|
||||
|
||||
|
||||
class Rating(Base):
|
||||
__tablename__ = "ratings"
|
||||
|
||||
id: Mapped[int] = mapped_column("id", primary_key=True)
|
||||
|
||||
# The session_id is set once per session, so can be easily used to extract whole histories
|
||||
session_id: Mapped[str] = mapped_column(UUID(), default=uuid.uuid4)
|
||||
|
||||
# the user provided score
|
||||
score: Mapped[int] = mapped_column(Integer)
|
||||
|
||||
# An optional comment
|
||||
comment: Mapped[Optional[str]] = mapped_column(LONGTEXT)
|
||||
|
||||
# The settings object, serialized to JSON
|
||||
settings: Mapped[str] = mapped_column(LONGTEXT)
|
||||
|
||||
date_created: Mapped[datetime] = mapped_column(DateTime, default=func.now())
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"Rating(session={self.session_id!r}, score={self.score!r})"
|
||||
|
||||
Reference in New Issue
Block a user