Batch enqueue TG AI classifications
This commit is contained in:
@@ -40,12 +40,26 @@ type CreateJobRequest struct {
|
||||
IdempotencyKey string `json:"idempotency_key,omitempty"`
|
||||
}
|
||||
|
||||
type CreateJobsRequest struct {
|
||||
OwnerService string `json:"owner_service,omitempty"`
|
||||
TaskType string `json:"task_type,omitempty"`
|
||||
ModelProfile string `json:"model_profile,omitempty"`
|
||||
Priority int `json:"priority,omitempty"`
|
||||
MaxAttempts int `json:"max_attempts,omitempty"`
|
||||
Jobs []CreateJobRequest `json:"jobs"`
|
||||
}
|
||||
|
||||
type Job struct {
|
||||
ID string `json:"id"`
|
||||
Status string `json:"status"`
|
||||
Result json.RawMessage `json:"result,omitempty"`
|
||||
ErrorCode *string `json:"error_code,omitempty"`
|
||||
ErrorMessage *string `json:"error_message,omitempty"`
|
||||
ID string `json:"id"`
|
||||
OwnerService string `json:"owner_service,omitempty"`
|
||||
OwnerRef string `json:"owner_ref,omitempty"`
|
||||
TaskType string `json:"task_type,omitempty"`
|
||||
ModelProfile string `json:"model_profile,omitempty"`
|
||||
Status string `json:"status"`
|
||||
Result json.RawMessage `json:"result,omitempty"`
|
||||
ErrorCode *string `json:"error_code,omitempty"`
|
||||
ErrorMessage *string `json:"error_message,omitempty"`
|
||||
IdempotencyKey *string `json:"idempotency_key,omitempty"`
|
||||
}
|
||||
|
||||
type ChatResult struct {
|
||||
@@ -111,6 +125,35 @@ func (c *Client) CreateJob(ctx context.Context, req CreateJobRequest) (*Job, err
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func (c *Client) CreateJobs(ctx context.Context, req CreateJobsRequest) ([]*Job, error) {
|
||||
if c == nil {
|
||||
return nil, fmt.Errorf("ai-service not configured")
|
||||
}
|
||||
body, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("marshal ai jobs: %w", err)
|
||||
}
|
||||
httpReq, err := c.request(ctx, http.MethodPost, "/api/v1/jobs/batch", body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := c.http.Do(httpReq)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create ai jobs: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||
return nil, fmt.Errorf("create ai jobs: http %d: %s", resp.StatusCode, readSmall(resp.Body))
|
||||
}
|
||||
var out struct {
|
||||
Jobs []*Job `json:"jobs"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&out); err != nil {
|
||||
return nil, fmt.Errorf("decode ai jobs: %w", err)
|
||||
}
|
||||
return out.Jobs, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetJob(ctx context.Context, id string) (*Job, error) {
|
||||
if c == nil || strings.TrimSpace(id) == "" {
|
||||
return nil, fmt.Errorf("ai job id is required")
|
||||
|
||||
Reference in New Issue
Block a user