From df33c7eee982201ab55162b5d5107868e1cfd2e4 Mon Sep 17 00:00:00 2001 From: Ilya Kowalewski Date: Mon, 25 Nov 2024 18:12:57 +0200 Subject: [PATCH 1/2] feat: type BatchStatus for all possible states --- batch.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/batch.go b/batch.go index 3c1a9d0d7..90027917c 100644 --- a/batch.go +++ b/batch.go @@ -19,6 +19,19 @@ const ( BatchEndpointEmbeddings BatchEndpoint = "/v1/embeddings" ) +type BatchStatus string + +const ( + BatchStatusValidating BatchStatus = "validating" + BatchStatusFailed BatchStatus = "failed" + BatchStatusInProgress BatchStatus = "in_progress" + BatchStatusFinalizing BatchStatus = "finalizing" + BatchStatusCompleted BatchStatus = "completed" + BatchStatusExpired BatchStatus = "expired" + BatchStatusCancelling BatchStatus = "cancelling" + BatchStatusCancelled BatchStatus = "cancelled" +) + type BatchLineItem interface { MarshalBatchLineItem() []byte } @@ -74,7 +87,7 @@ type Batch struct { } `json:"errors"` InputFileID string `json:"input_file_id"` CompletionWindow string `json:"completion_window"` - Status string `json:"status"` + Status BatchStatus `json:"status"` OutputFileID *string `json:"output_file_id"` ErrorFileID *string `json:"error_file_id"` CreatedAt int `json:"created_at"` From f180ab5bdafe55d9eeda5364da93088effe160ae Mon Sep 17 00:00:00 2001 From: Ilya Kowalewski Date: Fri, 29 Nov 2024 21:34:14 +0200 Subject: [PATCH 2/2] feat: de-inlining Batch errors, int64 timestamps --- batch.go | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/batch.go b/batch.go index 90027917c..6970afbfd 100644 --- a/batch.go +++ b/batch.go @@ -73,36 +73,40 @@ func (r BatchEmbeddingRequest) MarshalBatchLineItem() []byte { } type Batch struct { - ID string `json:"id"` - Object string `json:"object"` - Endpoint BatchEndpoint `json:"endpoint"` - Errors *struct { - Object string `json:"object,omitempty"` - Data []struct { - Code string `json:"code,omitempty"` - Message string `json:"message,omitempty"` - Param *string `json:"param,omitempty"` - Line *int `json:"line,omitempty"` - } `json:"data"` - } `json:"errors"` + ID string `json:"id"` + Object string `json:"object"` InputFileID string `json:"input_file_id"` CompletionWindow string `json:"completion_window"` + Endpoint BatchEndpoint `json:"endpoint"` Status BatchStatus `json:"status"` - OutputFileID *string `json:"output_file_id"` - ErrorFileID *string `json:"error_file_id"` - CreatedAt int `json:"created_at"` - InProgressAt *int `json:"in_progress_at"` - ExpiresAt *int `json:"expires_at"` - FinalizingAt *int `json:"finalizing_at"` - CompletedAt *int `json:"completed_at"` - FailedAt *int `json:"failed_at"` - ExpiredAt *int `json:"expired_at"` - CancellingAt *int `json:"cancelling_at"` - CancelledAt *int `json:"cancelled_at"` - RequestCounts BatchRequestCounts `json:"request_counts"` + Errors *BatchErrors `json:"errors,omitempty"` + OutputFileID string `json:"output_file_id,omitempty"` + ErrorFileID string `json:"error_file_id,omitempty"` + CreatedAt int64 `json:"created_at"` + InProgressAt int64 `json:"in_progress_at,omitempty"` + ExpiresAt int64 `json:"expires_at,omitempty"` + FinalizingAt int64 `json:"finalizing_at,omitempty"` + CompletedAt int64 `json:"completed_at,omitempty"` + FailedAt int64 `json:"failed_at,omitempty"` + ExpiredAt int64 `json:"expired_at,omitempty"` + CancellingAt int64 `json:"cancelling_at,omitempty"` + CancelledAt int64 `json:"cancelled_at,omitempty"` + RequestCounts BatchRequestCounts `json:"request_counts,omitempty"` Metadata map[string]any `json:"metadata"` } +type BatchErrors struct { + Object string `json:"object,omitempty"` + Data []BatchError `json:"data"` +} + +type BatchError struct { + Code string `json:"code,omitempty"` + Message string `json:"message,omitempty"` + Param string `json:"param,omitempty"` + Line int `json:"line,omitempty"` +} + type BatchRequestCounts struct { Total int `json:"total"` Completed int `json:"completed"`