labelstudio

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ACCESS_TOKEN_DURATION_SECONDS time.Duration = 240 * time.Second

According to https://github.com/HumanSignal/label-studio/blob/develop/docs/source/guide/access_tokens.md the access tokens expire "in about 5 minutes". We'll do 4 minutes to give us a bit of margin.

Functions

This section is empty.

Types

type Annotation

type Annotation struct {
	BulkCreated      bool         `json:"bulk_created"`
	CompletedBy      int          `json:"completed_by"`
	CreatedAgo       string       `json:"created_ago"`
	CreatedAt        string       `json:"created_at"`
	CreatedUsername  string       `json:"created_username"`
	DraftCreatedAt   string       `json:"draft_created_at"`
	GroundTruth      bool         `json:"ground_truth"`
	ID               int          `json:"id"`
	ImportID         *string      `json:"import_id"`
	LastAction       *string      `json:"last_action"`
	LastCreatedBy    *string      `json:"last_created_by"`
	LeadTime         float64      `json:"lead_time"`
	ParentAnnotation *int         `json:"parent_annotation,omitempty"`
	ParentPrediction *int         `json:"parent_prediction,omitempty"`
	Project          int          `json:"project"`
	Result           []TaskResult `json:"result"`
	Task             int          `json:"task"`
	WasCancelled     bool         `json:"was_cancelled"`
	UpdatedAt        string       `json:"updated_at"`
	UpdatedBy        int          `json:"updated_by"`
}

Annotation represents a draft annotation returned by the API

type AnnotationRequest

type AnnotationRequest struct {
	DraftID          int          `json:"draft_id"`
	LeadTime         float64      `json:"lead_time"`
	ParentAnnotation *int         `json:"parent_annotation,omitempty"`
	ParentPrediction *int         `json:"parent_prediction,omitempty"`
	Project          int          `json:"project"`
	Result           []TaskResult `json:"result"`
	StartedAt        string       `json:"started_at"`
}

AnnotationRequest represents the request body for creating a draft

func NewAnnotationRequest

func NewAnnotationRequest(projectID int) *AnnotationRequest

NewAnnotation creates a new draft request builder

type AssignmentSettings

type AssignmentSettings struct {
	ID int `json:"id"`
}

AssignmentSettings represents the assignment settings of a project

type Blueprint

type Blueprint struct {
	CreatedAt time.Time `json:"created_at"`
	ID        int       `json:"id"`
	ShareID   string    `json:"share_id"`
	ShortURL  string    `json:"short_url"`
}

Blueprint represents a blueprint in a project

type Client

type Client struct {
	BaseURL            string
	APIKey             string
	AccessToken        string
	AccessTokenExpires time.Time
	HTTPClient         *http.Client
}

Client represents a Label Studio API client

func NewClient

func NewClient(baseURL string, apiKey string) *Client

NewClient creates a new Label Studio client

func (*Client) CreateAnnotation

func (c *Client) CreateAnnotation(taskID int, annotation *AnnotationRequest) (*Annotation, error)

CreateAnnotation creates a new annotation on a task

func (*Client) CreateDraft

func (c *Client) CreateDraft(taskID int, draft *DraftRequest) (*Draft, error)

CreateDraft creates a new draft for a task

func (*Client) GetAccessToken

func (c *Client) GetAccessToken() error

GetAccessToken converts the API key into an access token

func (*Client) GetUser

func (c *Client) GetUser(userID int) (*User, error)

GetUser fetches a specific user by ID

func (*Client) ImportTasks

func (c *Client) ImportTasks(projectID int, tasks interface{}) (*TaskImportResponse, error)

ImportTasks imports tasks into a Label Studio project tasks parameter can be any data structure that can be marshalled to JSON

func (*Client) ListTasks

func (c *Client) ListTasks(options *TasksListOptions) (*TasksListResponse, error)

ListTasks fetches the list of tasks from the Label Studio API

func (*Client) ListUsers

func (c *Client) ListUsers() ([]User, error)

ListUsers fetches the list of users from the Label Studio API

func (*Client) Projects

func (c *Client) Projects() (*ProjectsResponse, error)

Projects fetches the list of projects from the Label Studio API

func (*Client) TaskUpdate

func (c *Client) TaskUpdate(taskID int, update *TaskUpdate) (*Task, error)

type Draft

type Draft struct {
	ID         int                      `json:"id"`
	TaskID     int                      `json:"task"`
	CreatedAt  time.Time                `json:"created_at"`
	UpdatedAt  time.Time                `json:"updated_at"`
	LeadTime   float64                  `json:"lead_time"`
	Result     []map[string]interface{} `json:"result"`
	Annotation *int                     `json:"annotation,omitempty"`
	User       string                   `json:"user"`
}

Draft represents a draft annotation returned by the API

type DraftRequest

type DraftRequest struct {
	Annotation       *string      `json:"annotation"`
	CreatedAgo       string       `json:"created_ago"`
	CreatedAt        string       `json:"created_at"`
	CreatedUsername  string       `json:"created_username"`
	DraftID          int          `json:"draft_id"`
	ID               int          `json:"id"`
	ImportID         *string      `json:"import_id"`
	LeadTime         float64      `json:"lead_time"`
	ParentAnnotation *int         `json:"parent_annotation,omitempty"`
	ParentPrediction *int         `json:"parent_prediction,omitempty"`
	Project          string       `json:"project"`
	Result           []TaskResult `json:"result"`
	StartedAt        string       `json:"started_at"`
	Task             int          `json:"task"`
	User             string       `json:"user"`
	WasPostponed     bool         `json:"was_postponed"`
}

DraftRequest represents the request body for creating a draft

func NewDraft

func NewDraft(projectID int) *DraftRequest

NewDraft creates a new draft request builder

func (*DraftRequest) SetLeadTime

func (d *DraftRequest) SetLeadTime(leadTime float64) *DraftRequest

SetLeadTime sets the time spent on the draft

func (*DraftRequest) SetParentAnnotation

func (d *DraftRequest) SetParentAnnotation(annotationID int) *DraftRequest

SetParentAnnotation sets the parent annotation ID if the draft is based on an annotation

func (*DraftRequest) SetParentPrediction

func (d *DraftRequest) SetParentPrediction(predictionID int) *DraftRequest

SetParentPrediction sets the parent prediction ID if the draft is based on a prediction

func (*DraftRequest) SetResult

func (d *DraftRequest) SetResult(result []TaskResult) *DraftRequest

SetResult sets the annotation result

func (*DraftRequest) SetStartedAt

func (d *DraftRequest) SetStartedAt(startedAt time.Time) *DraftRequest

SetStartedAt sets the time when work on the draft started

type Project

type Project struct {
	AllowStream                     bool               `json:"allow_stream"`
	AssignmentSettings              AssignmentSettings `json:"assignment_settings"`
	Blueprints                      []Blueprint        `json:"blueprints"`
	ConfigHasControlTags            bool               `json:"config_has_control_tags"`
	ConfigSuitableForBulkAnnotation bool               `json:"config_suitable_for_bulk_annotation"`
	CreatedAt                       time.Time          `json:"created_at"`
	DataTypes                       map[string]string  `json:"data_types"`
	DescriptionShort                string             `json:"description_short"`
	FinishedTaskNumber              int                `json:"finished_task_number"`
	GroundTruthNumber               int                `json:"ground_truth_number"`
	ID                              int                `json:"id"`
	Members                         string             `json:"members"`
	MembersCount                    int                `json:"members_count"`
	NumTasksWithAnnotations         int                `json:"num_tasks_with_annotations"`
	//ParsedLabelConfig               map[string]string    `json:"parsed_label_config"`
	Prompts   string `json:"prompts"`
	QueueDone int    `json:"queue_done"`
	QueueLeft int    `json:"queue_left"`
	//QueueTotal                      string               `json:"queue_total"`
	Ready              bool           `json:"ready"`
	Rejected           int            `json:"rejected"`
	ReviewSettings     ReviewSettings `json:"review_settings"`
	ReviewTotalTasks   int            `json:"review_total_tasks"`
	ReviewedNumber     int            `json:"reviewed_number"`
	ReviewerQueueTotal int            `json:"reviewer_queue_total"`
	//SkippedAnnotationsNumber        string               `json:"skipped_annotations_number"`
	StartTrainingOnAnnotationUpdate bool `json:"start_training_on_annotation_update"`
	TaskNumber                      int  `json:"task_number"`
	//TotalAnnotationsNumber          string               `json:"total_annotations_number"`
	TotalPredictionsNumber          int    `json:"total_predictions_number"`
	Workspace                       string `json:"workspace"`
	WorkspaceTitle                  string `json:"workspace_title"`
	AnnotationLimitCount            int    `json:"annotation_limit_count"`
	AnnotationLimitPercent          string `json:"annotation_limit_percent"`
	AnnotatorEvaluationMinimumScore string `json:"annotator_evaluation_minimum_score"`
	AnnotatorEvaluationMinimumTasks int    `json:"annotator_evaluation_minimum_tasks"`
	Color                           string `json:"color"`
	CommentClassificationConfig     string `json:"comment_classification_config"`
	//ControlWeights                  map[string]string    `json:"control_weights"`
	CreatedBy                         User   `json:"created_by"`
	CustomScript                      string `json:"custom_script"`
	CustomTaskLockTtl                 int    `json:"custom_task_lock_ttl"`
	Description                       string `json:"description"`
	DuplicationDone                   bool   `json:"duplication_done"`
	DuplicationStatus                 string `json:"duplication_status"`
	EnableEmptyAnnotation             bool   `json:"enable_empty_annotation"`
	EvaluatePredictionsAutomatically  bool   `json:"evaluate_predictions_automatically"`
	ExpertInstruction                 string `json:"expert_instruction"`
	IsDraft                           bool   `json:"is_draft"`
	IsPublished                       bool   `json:"is_published"`
	LabelConfig                       string `json:"label_config"`
	MaximumAnnotations                int    `json:"maximum_annotations"`
	MinAnnotationsToStartTraining     int    `json:"min_annotations_to_start_training"`
	ModelVersion                      string `json:"model_version"`
	Organization                      int    `json:"organization"`
	OverlapCohortPercentage           int    `json:"overlap_cohort_percentage"`
	PauseOnFailedAnnotatorEvaluation  bool   `json:"pause_on_failed_annotator_evaluation"`
	PinnedAt                          string `json:"pinned_at"`
	RequireCommentOnSkip              bool   `json:"require_comment_on_skip"`
	RevealPreannotationsInteractively bool   `json:"reveal_preannotations_interactively"`
	Sampling                          string `json:"sampling"`
	ShowAnnotationHistory             bool   `json:"show_annotation_history"`
	ShowCollabPredictions             bool   `json:"show_collab_predictions"`
	ShowGroundTruthFirst              bool   `json:"show_ground_truth_first"`
	ShowInstruction                   bool   `json:"show_instruction"`
	ShowOverlapFirst                  bool   `json:"show_overlap_first"`
	ShowSkipButton                    bool   `json:"show_skip_button"`
	ShowUnusedDataColumnsToAnnotators bool   `json:"show_unused_data_columns_to_annotators"`
	SkipQueue                         string `json:"skip_queue"`
	Title                             string `json:"title"`
	UsefulAnnotationNumber            int    `json:"useful_annotation_number"`
}

Project represents a single project returned by the Label Studio API

type ProjectsResponse

type ProjectsResponse struct {
	Count    int       `json:"count"`
	Results  []Project `json:"results"`
	Next     string    `json:"next"`
	Previous string    `json:"previous"`
}

ProjectsResponse represents the response from the /api/projects endpoint

type ReviewSettings

type ReviewSettings struct {
	ID                              int  `json:"id"`
	RequeueRejectedTasksToAnnotator bool `json:"requeue_rejected_tasks_to_annotator"`
}

ReviewSettings represents the review settings of a project

type Task

type Task struct {
	Agreement                string                   `json:"agreement"`
	AgreementSelected        string                   `json:"agreement_selected"`
	Annotations              json.RawMessage          `json:"annotations"`
	AnnotationsIDs           json.RawMessage          `json:"annotations_ids"`
	AnnotationsResults       json.RawMessage          `json:"annotations_results"`
	Annotators               []int                    `json:"annotators"`
	AnnotatorsCount          int                      `json:"annotators_count"`
	AvgLeadTime              float64                  `json:"avg_lead_time"`
	CancelledAnnotations     int                      `json:"cancelled_annotations"`
	CommentAuthors           []map[string]interface{} `json:"comment_authors"`
	CommentAuthorsCount      int                      `json:"comment_authors_count"`
	CommentCount             int                      `json:"comment_count"`
	Comments                 json.RawMessage          `json:"comments"`
	CompletedAt              string                   `json:"completed_at"`
	CreatedAt                time.Time                `json:"created_at"`
	Data                     map[string]interface{}   `json:"data"`
	DraftExists              bool                     `json:"draft_exists"`
	Drafts                   []json.RawMessage        `json:"drafts"`
	FileUpload               string                   `json:"file_upload"`
	GroundTruth              bool                     `json:"ground_truth"`
	ID                       int                      `json:"id"`
	InnerID                  int                      `json:"inner_id"`
	IsLabeled                bool                     `json:"is_labeled"`
	LastCommentUpdatedAt     string                   `json:"last_comment_updated_at"`
	Meta                     map[string]interface{}   `json:"meta"`
	Overlap                  int                      `json:"overlap"`
	Predictions              []json.RawMessage        `json:"predictions"`
	PredictionsModelVersions json.RawMessage          `json:"predictions_model_versions"`
	PredictionsResults       json.RawMessage          `json:"predictions_results"`
	PredictionsScore         float64                  `json:"predictions_score"`
	Project                  int                      `json:"project"`
	ReviewTime               int                      `json:"review_time"`
	Reviewed                 bool                     `json:"reviewed"`
	Reviewers                []map[string]interface{} `json:"reviewers"`
	ReviewersCount           int                      `json:"reviewers_count"`
	ReviewsAccepted          int                      `json:"reviews_accepted"`
	ReviewsRejected          int                      `json:"reviews_rejected"`
	StorageFilename          string                   `json:"storage_filename"`
	TotalAnnotations         int                      `json:"total_annotations"`
	TotalPredictions         int                      `json:"total_predictions"`
	UnresolvedCommentCount   int                      `json:"unresolved_comment_count"`
	UpdatedAt                time.Time                `json:"updated_at"`
	UpdatedBy                []map[string]interface{} `json:"updated_by"`
}

Task represents a single task returned by the Label Studio API

type TaskImportResponse

type TaskImportResponse struct {
	// Common fields that might be returned
	TaskCount  int                    `json:"task_count,omitempty"`
	Annotation map[string]interface{} `json:"annotation,omitempty"`
	Task       map[string]interface{} `json:"task,omitempty"`

	// For handling any other fields in the response
	AdditionalProperties map[string]interface{} `json:"-"`
}

TaskImportResponse represents the response from the import tasks endpoint

func (*TaskImportResponse) UnmarshalJSON

func (r *TaskImportResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON custom unmarshaler for TaskImportResponse to capture all fields

type TaskResult

type TaskResult struct {
	ID       string          `json:"id"`
	FromName string          `json:"from_name"`
	Origin   string          `json:"origin"`
	ToName   string          `json:"to_name"`
	Type     string          `json:"type"`
	Value    TaskResultValue `json:"value"`
}

type TaskResultValue

type TaskResultValue struct {
	Text []string `json:"text"`
}

type TaskUpdate

type TaskUpdate struct {
	// Fields that can be updated
	Annotations json.RawMessage         `json:"annotations,omitempty"`
	Data        *map[string]interface{} `json:"data,omitempty"`
	DraftExists *bool                   `json:"draft_exists,omitempty"`
	Drafts      json.RawMessage         `json:"drafts,omitempty"`
	GroundTruth *bool                   `json:"ground_truth,omitempty"`
	IsLabeled   *bool                   `json:"is_labeled,omitempty"`
	Meta        *map[string]interface{} `json:"meta,omitempty"`
	Predictions json.RawMessage         `json:"predictions,omitempty"`
	Reviewed    *bool                   `json:"reviewed"`
	// contains filtered or unexported fields
}

TaskUpdate defines fields that can be updated in a task

func NewTaskUpdate

func NewTaskUpdate() *TaskUpdate

NewTaskUpdate creates a new TaskUpdate builder

func (*TaskUpdate) MarshalJSON

func (t *TaskUpdate) MarshalJSON() ([]byte, error)

func (*TaskUpdate) SetAnnotations

func (t *TaskUpdate) SetAnnotations(annotations interface{}) *TaskUpdate

func (*TaskUpdate) SetData

func (t *TaskUpdate) SetData(data map[string]interface{}) *TaskUpdate

func (*TaskUpdate) SetDraftExists

func (t *TaskUpdate) SetDraftExists(draftExists bool) *TaskUpdate

func (*TaskUpdate) SetDrafts

func (t *TaskUpdate) SetDrafts(drafts interface{}) *TaskUpdate

func (*TaskUpdate) SetGroundTruth

func (t *TaskUpdate) SetGroundTruth(groundTruth bool) *TaskUpdate

func (*TaskUpdate) SetIsLabeled

func (t *TaskUpdate) SetIsLabeled(isLabeled bool) *TaskUpdate

func (*TaskUpdate) SetMeta

func (t *TaskUpdate) SetMeta(meta map[string]interface{}) *TaskUpdate

func (*TaskUpdate) SetPredictions

func (t *TaskUpdate) SetPredictions(predictions interface{}) *TaskUpdate

func (*TaskUpdate) SetReviewed

func (t *TaskUpdate) SetReviewed(isReviewed bool) *TaskUpdate

type TasksListOptions

type TasksListOptions struct {
	ProjectID   int    // Filter by project ID
	Page        int    // Page number for pagination
	PageSize    int    // Number of items per page
	Ordering    string // Field to order by (e.g., "created_at", "-created_at" for descending)
	Query       string // Search query for filtering tasks
	IsLabeled   *bool  // Filter by labeled status
	IsReviewed  *bool  // Filter by review status
	GroundTruth *bool  // Filter by ground truth status
}

TasksListOptions represents query parameters that can be used to filter tasks

type TasksListResponse

type TasksListResponse struct {
	Tasks            []Task `json:"tasks"`
	Total            int    `json:"total"`
	TotalAnnotations int    `json:"total_annotations"`
	TotalPredictions int    `json:"total_predictions"`
}

TasksListResponse represents the response from the /api/tasks endpoint

type User

type User struct {
	ID                     int                    `json:"id"`
	FirstName              string                 `json:"first_name"`
	LastName               string                 `json:"last_name"`
	Username               string                 `json:"username"`
	Email                  string                 `json:"email"`
	LastActivity           time.Time              `json:"last_activity"`
	CustomHotkeys          map[string]interface{} `json:"custom_hotkeys"`
	Avatar                 *string                `json:"avatar"`
	Initials               string                 `json:"initials"`
	Phone                  string                 `json:"phone"`
	ActiveOrganization     int                    `json:"active_organization"`
	ActiveOrganizationMeta struct {
		Title string `json:"title"`
		Email string `json:"email"`
	} `json:"active_organization_meta"`
	AllowNewsletters *bool     `json:"allow_newsletters"`
	DateJoined       time.Time `json:"date_joined"`
}

User represents a user in Label Studio

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL