Skip to content

Commit

Permalink
collect feedback from learning on activity (#2448)
Browse files Browse the repository at this point in the history
  • Loading branch information
drf7 authored Sep 12, 2024
1 parent 0ac13b9 commit 31ce460
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 10 deletions.
13 changes: 13 additions & 0 deletions nucliadb/src/nucliadb/search/api/v1/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from nucliadb_models.search import FeedbackRequest, NucliaDBClientType
from nucliadb_telemetry import errors
from nucliadb_utils.authentication import requires
from nucliadb_utils.utilities import get_audit


@api.post(
Expand Down Expand Up @@ -72,3 +73,15 @@ async def send_feedback(
):
predict = get_predict()
await predict.send_feedback(kbid, item, x_nucliadb_user, x_ndb_client, x_forwarded_for)
audit = get_audit()
if audit is not None:
audit.feedback(
kbid=kbid,
user=x_nucliadb_user,
client_type=x_ndb_client.to_proto(),
origin=x_forwarded_for,
learning_id=item.ident,
good=item.good,
task=item.task.to_proto(),
feedback=item.feedback,
)
5 changes: 4 additions & 1 deletion nucliadb_models/src/nucliadb_models/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from nucliadb_models.resource import ExtractedDataTypeName, Resource
from nucliadb_models.security import RequestSecurity
from nucliadb_models.utils import DateTime
from nucliadb_protos.audit_pb2 import ClientType
from nucliadb_protos.audit_pb2 import ClientType, TaskType
from nucliadb_protos.nodereader_pb2 import DocumentScored, OrderBy
from nucliadb_protos.nodereader_pb2 import ParagraphResult as PBParagraphResult
from nucliadb_protos.utils_pb2 import RelationNode
Expand Down Expand Up @@ -1460,6 +1460,9 @@ class KnowledgeboxFindResults(JsonBaseModel):
class FeedbackTasks(str, Enum):
CHAT = "CHAT"

def to_proto(self) -> int:
return TaskType.Value(self.name)


class FeedbackRequest(BaseModel):
ident: str = Field(
Expand Down
14 changes: 14 additions & 0 deletions nucliadb_protos/audit.proto
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ message ChatAudit {
int32 status_code = 9;
}

enum TaskType {
CHAT = 0;
}

message FeedbackAudit {
string learning_id = 1;
bool good = 2;
TaskType task = 3;
optional string feedback = 4;
}


message AuditRequest {
enum AuditType {
VISITED = 0;
Expand All @@ -72,6 +84,7 @@ message AuditRequest {
SUGGEST = 9 [deprecated=true];
INDEXED = 10 [deprecated=true];
CHAT = 11;
FEEDBACK = 12;
}

AuditType type = 1;
Expand Down Expand Up @@ -100,4 +113,5 @@ message AuditRequest {
optional float generative_answer_time = 23;
optional float generative_answer_first_chunk_time = 24;
optional float rephrase_time = 25;
FeedbackAudit feedback = 26;
}
18 changes: 11 additions & 7 deletions nucliadb_protos/python/src/nucliadb_protos/audit_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 47 additions & 2 deletions nucliadb_protos/python/src/nucliadb_protos/audit_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ DASHBOARD: ClientType.ValueType # 4
CHROME_EXTENSION: ClientType.ValueType # 5
global___ClientType = ClientType

class _TaskType:
ValueType = typing.NewType("ValueType", builtins.int)
V: typing_extensions.TypeAlias = ValueType

class _TaskTypeEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[_TaskType.ValueType], builtins.type):
DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor
CHAT: _TaskType.ValueType # 0

class TaskType(_TaskType, metaclass=_TaskTypeEnumTypeWrapper): ...

CHAT: TaskType.ValueType # 0
global___TaskType = TaskType

@typing.final
class AuditField(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor
Expand Down Expand Up @@ -193,6 +206,32 @@ class ChatAudit(google.protobuf.message.Message):

global___ChatAudit = ChatAudit

@typing.final
class FeedbackAudit(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

LEARNING_ID_FIELD_NUMBER: builtins.int
GOOD_FIELD_NUMBER: builtins.int
TASK_FIELD_NUMBER: builtins.int
FEEDBACK_FIELD_NUMBER: builtins.int
learning_id: builtins.str
good: builtins.bool
task: global___TaskType.ValueType
feedback: builtins.str
def __init__(
self,
*,
learning_id: builtins.str = ...,
good: builtins.bool = ...,
task: global___TaskType.ValueType = ...,
feedback: builtins.str | None = ...,
) -> None: ...
def HasField(self, field_name: typing.Literal["_feedback", b"_feedback", "feedback", b"feedback"]) -> builtins.bool: ...
def ClearField(self, field_name: typing.Literal["_feedback", b"_feedback", "feedback", b"feedback", "good", b"good", "learning_id", b"learning_id", "task", b"task"]) -> None: ...
def WhichOneof(self, oneof_group: typing.Literal["_feedback", b"_feedback"]) -> typing.Literal["feedback"] | None: ...

global___FeedbackAudit = FeedbackAudit

@typing.final
class AuditRequest(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor
Expand All @@ -215,6 +254,7 @@ class AuditRequest(google.protobuf.message.Message):
SUGGEST: AuditRequest._AuditType.ValueType # 9
INDEXED: AuditRequest._AuditType.ValueType # 10
CHAT: AuditRequest._AuditType.ValueType # 11
FEEDBACK: AuditRequest._AuditType.ValueType # 12

class AuditType(_AuditType, metaclass=_AuditTypeEnumTypeWrapper): ...
VISITED: AuditRequest.AuditType.ValueType # 0
Expand All @@ -229,6 +269,7 @@ class AuditRequest(google.protobuf.message.Message):
SUGGEST: AuditRequest.AuditType.ValueType # 9
INDEXED: AuditRequest.AuditType.ValueType # 10
CHAT: AuditRequest.AuditType.ValueType # 11
FEEDBACK: AuditRequest.AuditType.ValueType # 12

TYPE_FIELD_NUMBER: builtins.int
KBID_FIELD_NUMBER: builtins.int
Expand All @@ -253,6 +294,7 @@ class AuditRequest(google.protobuf.message.Message):
GENERATIVE_ANSWER_TIME_FIELD_NUMBER: builtins.int
GENERATIVE_ANSWER_FIRST_CHUNK_TIME_FIELD_NUMBER: builtins.int
REPHRASE_TIME_FIELD_NUMBER: builtins.int
FEEDBACK_FIELD_NUMBER: builtins.int
type: global___AuditRequest.AuditType.ValueType
kbid: builtins.str
userid: builtins.str
Expand Down Expand Up @@ -283,6 +325,8 @@ class AuditRequest(google.protobuf.message.Message):
def kb_counter(self) -> global___AuditKBCounter: ...
@property
def chat(self) -> global___ChatAudit: ...
@property
def feedback(self) -> global___FeedbackAudit: ...
def __init__(
self,
*,
Expand All @@ -309,9 +353,10 @@ class AuditRequest(google.protobuf.message.Message):
generative_answer_time: builtins.float | None = ...,
generative_answer_first_chunk_time: builtins.float | None = ...,
rephrase_time: builtins.float | None = ...,
feedback: global___FeedbackAudit | None = ...,
) -> None: ...
def HasField(self, field_name: typing.Literal["_generative_answer_first_chunk_time", b"_generative_answer_first_chunk_time", "_generative_answer_time", b"_generative_answer_time", "_rephrase_time", b"_rephrase_time", "_retrieval_time", b"_retrieval_time", "chat", b"chat", "generative_answer_first_chunk_time", b"generative_answer_first_chunk_time", "generative_answer_time", b"generative_answer_time", "kb_counter", b"kb_counter", "rephrase_time", b"rephrase_time", "retrieval_time", b"retrieval_time", "search", b"search", "time", b"time"]) -> builtins.bool: ...
def ClearField(self, field_name: typing.Literal["_generative_answer_first_chunk_time", b"_generative_answer_first_chunk_time", "_generative_answer_time", b"_generative_answer_time", "_rephrase_time", b"_rephrase_time", "_retrieval_time", b"_retrieval_time", "chat", b"chat", "client_type", b"client_type", "field_metadata", b"field_metadata", "fields", b"fields", "fields_audit", b"fields_audit", "generative_answer_first_chunk_time", b"generative_answer_first_chunk_time", "generative_answer_time", b"generative_answer_time", "kb_counter", b"kb_counter", "kbid", b"kbid", "origin", b"origin", "rephrase_time", b"rephrase_time", "request_time", b"request_time", "resources", b"resources", "retrieval_time", b"retrieval_time", "rid", b"rid", "search", b"search", "success", b"success", "task", b"task", "time", b"time", "timeit", b"timeit", "trace_id", b"trace_id", "type", b"type", "userid", b"userid"]) -> None: ...
def HasField(self, field_name: typing.Literal["_generative_answer_first_chunk_time", b"_generative_answer_first_chunk_time", "_generative_answer_time", b"_generative_answer_time", "_rephrase_time", b"_rephrase_time", "_retrieval_time", b"_retrieval_time", "chat", b"chat", "feedback", b"feedback", "generative_answer_first_chunk_time", b"generative_answer_first_chunk_time", "generative_answer_time", b"generative_answer_time", "kb_counter", b"kb_counter", "rephrase_time", b"rephrase_time", "retrieval_time", b"retrieval_time", "search", b"search", "time", b"time"]) -> builtins.bool: ...
def ClearField(self, field_name: typing.Literal["_generative_answer_first_chunk_time", b"_generative_answer_first_chunk_time", "_generative_answer_time", b"_generative_answer_time", "_rephrase_time", b"_rephrase_time", "_retrieval_time", b"_retrieval_time", "chat", b"chat", "client_type", b"client_type", "feedback", b"feedback", "field_metadata", b"field_metadata", "fields", b"fields", "fields_audit", b"fields_audit", "generative_answer_first_chunk_time", b"generative_answer_first_chunk_time", "generative_answer_time", b"generative_answer_time", "kb_counter", b"kb_counter", "kbid", b"kbid", "origin", b"origin", "rephrase_time", b"rephrase_time", "request_time", b"request_time", "resources", b"resources", "retrieval_time", b"retrieval_time", "rid", b"rid", "search", b"search", "success", b"success", "task", b"task", "time", b"time", "timeit", b"timeit", "trace_id", b"trace_id", "type", b"type", "userid", b"userid"]) -> None: ...
@typing.overload
def WhichOneof(self, oneof_group: typing.Literal["_generative_answer_first_chunk_time", b"_generative_answer_first_chunk_time"]) -> typing.Literal["generative_answer_first_chunk_time"] | None: ...
@typing.overload
Expand Down
3 changes: 3 additions & 0 deletions nucliadb_protos/python/src/nucliadb_protos/writer_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ from nucliadb_protos.audit_pb2 import (
AuditField as AuditField,
AuditKBCounter as AuditKBCounter,
AuditRequest as AuditRequest,
CHAT as CHAT,
CHROME_EXTENSION as CHROME_EXTENSION,
ChatAudit as ChatAudit,
ChatContext as ChatContext,
ClientType as ClientType,
DASHBOARD as DASHBOARD,
DESKTOP as DESKTOP,
FeedbackAudit as FeedbackAudit,
RetrievedContext as RetrievedContext,
TaskType as TaskType,
WEB as WEB,
WIDGET as WIDGET,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ from nucliadb_protos.audit_pb2 import (
AuditField as AuditField,
AuditKBCounter as AuditKBCounter,
AuditRequest as AuditRequest,
CHAT as CHAT,
CHROME_EXTENSION as CHROME_EXTENSION,
ChatAudit as ChatAudit,
ChatContext as ChatContext,
ClientType as ClientType,
DASHBOARD as DASHBOARD,
DESKTOP as DESKTOP,
FeedbackAudit as FeedbackAudit,
RetrievedContext as RetrievedContext,
TaskType as TaskType,
WEB as WEB,
WIDGET as WIDGET,
)
Expand Down
Loading

0 comments on commit 31ce460

Please sign in to comment.