rg.Response
¶
Class for interacting with Argilla Responses of records. Responses are answers to questions by a user. Therefore, a question can have multiple responses, one for each user that has answered the question. A Response
is typically created by a user in the UI or consumed from a data source as a label, unlike a Suggestion
which is typically created by a model prediction.
Usage Examples¶
Responses can be added to an instantiated Record
directly or as a dictionary a dictionary. The following examples demonstrate how to add responses to a record object and how to access responses from a record object:
Instantiate the Record
and related Response
objects:
dataset.records.log(
[
rg.Record(
fields={"text": "Hello World, how are you?"},
responses=[rg.Response("label", "negative", user_id=user.id)],
external_id=str(uuid.uuid4()),
)
]
)
Or, add a response from a dictionary where key is the question name and value is the response:
Responses can be accessed from a Record
via their question name as an attribute of the record. So if a question is named label
, the response can be accessed as record.label
. The following example demonstrates how to access responses from a record object:
# iterate over the records and responses
for record in dataset.records:
for response in record.responses["label"]: # (1)
print(response.value)
print(response.user_id)
# validate that the record has a response
for record in dataset.records:
if record.responses["label"]:
for response in record.responses["label"]:
print(response.value)
print(response.user_id)
else:
record.responses.add(
rg.Response("label", "positive", user_id=user.id)
) # (2)
label
for each record like a dictionary containing a list of Response
objects.
2. Add a response to the record if it does not already have one.
Format per Question
type¶
Depending on the Question
type, responses might need to be formatted in a slightly different way.
Response
¶
Class for interacting with Argilla Responses of records. Responses are answers to questions by a user.
Therefore, a record question can have multiple responses, one for each user that has answered the question.
A Response
is typically created by a user in the UI or consumed from a data source as a label,
unlike a Suggestion
which is typically created by a model prediction.
Source code in src/argilla/responses.py
record: Record
property
writable
¶
Returns the record associated with the response
__init__(question_name, value, user_id, status=None, _record=None)
¶
Initializes a Response
for a Record
with a user_id and value
Attributes:
Name | Type | Description |
---|---|---|
question_name |
str
|
The name of the question that the suggestion is for. |
value |
str
|
The value of the response |
user_id |
UUID
|
The id of the user that submits the response |
status |
Union[ResponseStatus, str]
|
The status of the response as "draft", "submitted", "discarded". |
Source code in src/argilla/responses.py
serialize()
¶
Serializes the Response to a dictionary. This is principally used for sending the response to the API, but can be used for data wrangling or manual export.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
dict[str, Any]: The serialized response as a dictionary with keys |
Examples: