Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit e2507bc

Browse files
authored
Merge pull request #15 from refuel-ai/createtask
docs for create task and feedback
2 parents 55038c2 + 46e0a48 commit e2507bc

File tree

1 file changed

+69
-8
lines changed

1 file changed

+69
-8
lines changed

docs/python-sdk.md

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ Here’s the complete list of filter operators that are currently supported
245245

246246
These functions let you retrieve information about labeling tasks defined within a project, and start and cancel a task run.
247247

248-
### Get Tasks
248+
### Define a new Task
249249

250-
You can retrieve a list of all tasks within a given project as follows
250+
You can create a new task programmatically within a given project as follows:
251251

252252
```python
253253
import refuel
@@ -259,6 +259,26 @@ options = {
259259

260260
refuel_client = refuel.init(**options)
261261

262+
refuel_client.create_task(
263+
task='<TASK NAME>',
264+
task_type='<TASK TYPE>',
265+
dataset='<DATASET NAME>',
266+
input_columns=['col 1', 'col 2' ...],
267+
context = '...',
268+
fields = [{'name': '...', 'guidelines': ...}]
269+
)
270+
```
271+
272+
- task_type is one of: `classification`, `multilabel_classification` or `attribute_extraction`
273+
- input_columns is the subset of columns from the dataset that will be used as input for LLM
274+
- fields is a list of dictionaries. Each dictionary contains a fixed set of keys: name (name of the LLM label field as it will be appear in the exported dataset), guidelines (labeling guidelines for the LLM) and labels (list of valid labels, this field is only required for classification type tasks)
275+
276+
### Get Tasks
277+
278+
You can retrieve a list of all tasks within a given project as follows
279+
280+
```python
281+
262282
tasks = refuel_client.get_tasks()
263283
```
264284

@@ -329,18 +349,59 @@ applications = refuel_client.get_applications()
329349

330350
### Label using a deployed application
331351

332-
You can then get labels from your deployed application:
352+
You can use the deployed application for online predictions as follows:
353+
354+
```python
355+
inputs = [
356+
{'col_1': 'value_1', 'col_2': 'value_2' ...},
357+
{'col_1': 'value_1', 'col_2': 'value_2' ...},
358+
]
359+
360+
response = refuel_client.label(application='<APPLICATION NAME>', inputs=inputs)
361+
```
362+
363+
Each element in `inputs` is a dictionary, with keys as names of the input columns defined in the task. For example, let's consider an application for sentiment classification called `my_sentiment_classifier`, with two input fields - `source` and `text`. You can use it as follows:
333364

334365
```python
335366
inputs = [
336-
{'<COL 1>': '<VALUE FOR COL 1>', '<COL 2>': '<VALUE FOR COL 2>' ... }
367+
{'source': 'yelp.com', 'text': 'I really liked the pizza at this restaurant.'}
337368
]
338369

339-
labels = refuel_client.label(application='<APPLICATION NAME>', inputs=inputs)
370+
response = refuel_client.label(application='my_sentiment_classifier', inputs=inputs)
340371
```
341372

342-
Each element in input is a dictionary with keys corresponding to the input columns defined in the task. For example, if the task has two input columns, “name” and “description”, then each entry will be a dictionary with two keys, “name” and “description”. The values for these keys will be the name and description values for that input. E.g.:
373+
`response` has the following schema:
343374

344-
`[{"name": "example name value", "description": "example description value"}]`
375+
- `refuel_output[i]` contains the output for `inputs[i]`
376+
- `refuel_fields` is a list whose length is equal to the number of fields defined in the application. For example, let's say `my_sentiment_classifier` has just one field, `sentiment`. In this case the output will be:
377+
378+
```
379+
{
380+
'application_id': '...',
381+
'application_name': 'my_sentiment_classifier',
382+
'refuel_output': [
383+
{'refuel_uuid': '...',
384+
'refuel_api_timestamp': '...',
385+
'refuel_fields':
386+
{
387+
'sentiment': {
388+
'label': 'positive,
389+
'confidence': 0.9758
390+
}
391+
}
392+
}]
393+
}
394+
```
395+
396+
397+
### Share feedback for application outputs
398+
399+
The SDK allows users to log feedback for online predictions. When logging predictions, it is important to identify the input request for which you're logging feedback using `refuel_uuid` from the response above:
400+
401+
```python
402+
403+
label = {'sentiment': 'negative'}
404+
refuel_client.feedback(application='my_sentiment_classifier', refuel_uuid='...', label=label)
405+
```
345406

346-
It is recommended to use smaller batches for inputs (<= 10). For larger datasets, we recommend using batch-mode: uploading a dataset and triggering a labeling run.
407+
Any row with logged feedback will appear with the verified check mark ("✓") in the cloud application.

0 commit comments

Comments
 (0)