kotaemon/libs/ktem/ktem/pages/chat/report.py
Duc Nguyen (john) 8a90fcfc99 Restructure index to allow it to be dynamically created by end-user (#151)
1. Introduce the concept of "collection_name" to docstore and vector store. Each collection can be viewed similarly to a table in a SQL database. It allows better organizing information within this data source.
2. Move the `Index` and `Source` tables from the application scope into the index scope. For each new index created by user, these tables should increase accordingly. So it depends on the index, rather than the app.
3. Make each index responsible for the UI components in the app.
4. Construct the File UI page.
2024-03-07 01:50:47 +07:00

76 lines
2.3 KiB
Python

from typing import Optional
import gradio as gr
from ktem.app import BasePage
from ktem.db.models import IssueReport, engine
from sqlmodel import Session
class ReportIssue(BasePage):
def __init__(self, app):
self._app = app
self.on_building_ui()
def on_building_ui(self):
with gr.Accordion(label="Report", open=False):
self.correctness = gr.Radio(
choices=[
("The answer is correct", "correct"),
("The answer is incorrect", "incorrect"),
],
label="Correctness:",
)
self.issues = gr.CheckboxGroup(
choices=[
("The answer is offensive", "offensive"),
("The evidence is incorrect", "wrong-evidence"),
],
label="Other issue:",
)
self.more_detail = gr.Textbox(
placeholder="More detail (e.g. how wrong is it, what is the "
"correct answer, etc...)",
container=False,
lines=3,
)
gr.Markdown(
"This will send the current chat and the user settings to "
"help with investigation"
)
self.report_btn = gr.Button("Report")
def report(
self,
correctness: str,
issues: list[str],
more_detail: str,
conv_id: str,
chat_history: list,
settings: dict,
user_id: Optional[int],
*selecteds
):
selecteds_ = {}
for index in self._app.index_manager.indices:
if index.selector != -1:
selecteds_[str(index.id)] = selecteds[index.selector]
with Session(engine) as session:
issue = IssueReport(
issues={
"correctness": correctness,
"issues": issues,
"more_detail": more_detail,
},
chat={
"conv_id": conv_id,
"chat_history": chat_history,
"selecteds": selecteds_,
},
settings=settings,
user=user_id,
)
session.add(issue)
session.commit()
gr.Info("Thank you for your feedback")