File size: 3,289 Bytes
12f7c97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python3
"""Manual ORCA6 feedback intake Space."""

from __future__ import annotations

import json
import os
from pathlib import Path

import gradio as gr

from feedback_records import append_jsonl, build_feedback_record


DEFAULT_OUTPUT = Path(os.environ.get("ORCA6_FEEDBACK_OUTPUT", "feedback/space_feedback_v0.1-rc1.jsonl"))


def save_feedback(
    prompt: str,
    tester_prompt_id: str,
    model_answer: str,
    retrieved_sources: str,
    rating: str,
    issue_type: str,
    correction: str,
    model_version: str,
    review_notes: str,
    include_in_training: bool,
    secrets_checked: bool,
) -> tuple[str, str]:
    try:
        row = build_feedback_record(
            prompt=prompt,
            tester_prompt_id=tester_prompt_id,
            model_answer=model_answer,
            retrieved_sources=retrieved_sources,
            rating=rating,
            issue_type=issue_type,
            correction=correction,
            model_version=model_version,
            review_notes=review_notes,
            include_in_training=include_in_training,
            secrets_checked=secrets_checked,
            source="huggingface_space",
        )
    except ValueError as exc:
        return str(exc), ""
    append_jsonl(DEFAULT_OUTPUT, row)
    return f"Saved feedback to {DEFAULT_OUTPUT}", json.dumps(row, indent=2, ensure_ascii=False)


with gr.Blocks(title="ORCA6 Feedback") as demo:
    gr.Markdown("# ORCA6 Feedback")
    with gr.Row():
        model_version = gr.Textbox(label="Model version", value="v0.1-rc1")
        rating = gr.Radio(["useful", "mixed", "not useful"], label="Rating", value="mixed")
        issue_type = gr.Dropdown(
            [
                "no issue",
                "hallucination",
                "missing tool",
                "too complex",
                "too generic",
                "unsafe",
                "outdated",
                "citation/source problem",
            ],
            label="Issue type",
            value="no issue",
        )
    prompt = gr.Textbox(label="Prompt", lines=5)
    tester_prompt_id = gr.Textbox(label="Tester prompt ID", placeholder="tester-001")
    model_answer = gr.Textbox(label="Model answer", lines=8)
    retrieved_sources = gr.Textbox(label="Retrieved sources", lines=5, placeholder="(no retrieved evidence)")
    correction = gr.Textbox(label="Suggested correction", lines=6)
    review_notes = gr.Textbox(label="Reviewer notes", lines=4)
    with gr.Row():
        include_in_training = gr.Checkbox(label="Approved for possible training after review")
        secrets_checked = gr.Checkbox(label="Checked for secrets/private data")
    submit = gr.Button("Save feedback", variant="primary")
    status = gr.Textbox(label="Status", interactive=False)
    saved_json = gr.Code(label="Saved row", language="json")
    submit.click(
        save_feedback,
        inputs=[
            prompt,
            tester_prompt_id,
            model_answer,
            retrieved_sources,
            rating,
            issue_type,
            correction,
            model_version,
            review_notes,
            include_in_training,
            secrets_checked,
        ],
        outputs=[status, saved_json],
    )


if __name__ == "__main__":
    demo.launch()