Implement AI pipeline operations in the admin API
- Added new routes and handlers for AI pipeline operations, including scraping documents, batch summarization, translation, and syncing with the Opplens AI service. - Introduced request forms for handling tender references and batch operations. - Enhanced the AI service with methods for triggering batch operations and managing pipeline runs. - Updated Swagger documentation to reflect the new AI pipeline endpoints and their functionalities. This update integrates comprehensive AI pipeline capabilities into the tender management system, improving operational efficiency and user experience.
This commit is contained in:
@@ -4,6 +4,20 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// TenderRef identifies a tender for batch and pipeline requests.
|
||||
type TenderRef struct {
|
||||
ContractFolderID string `json:"contract_folder_id"`
|
||||
NoticePublicationID string `json:"notice_publication_id"`
|
||||
}
|
||||
|
||||
// NewTenderRef builds a TenderRef from contract folder and notice publication ids.
|
||||
func NewTenderRef(contractFolderID, noticePublicationID string) TenderRef {
|
||||
return TenderRef{
|
||||
ContractFolderID: strings.TrimSpace(contractFolderID),
|
||||
NoticePublicationID: strings.TrimSpace(noticePublicationID),
|
||||
}
|
||||
}
|
||||
|
||||
// SummarizeRequest is the payload for POST /ai/summarize.
|
||||
type SummarizeRequest struct {
|
||||
ContractFolderID string `json:"contract_folder_id"`
|
||||
@@ -70,9 +84,22 @@ type TranslateRequest struct {
|
||||
ContractFolderID string `json:"contract_folder_id"`
|
||||
NoticePublicationID string `json:"notice_publication_id"`
|
||||
Language string `json:"language"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
RequestSource string `json:"-"` // internal: daily_job | manual_trigger
|
||||
}
|
||||
|
||||
// NewTranslateRequest builds a TranslateRequest for POST /ai/translate.
|
||||
func NewTranslateRequest(contractFolderID, noticePublicationID, language, title, description string) TranslateRequest {
|
||||
return TranslateRequest{
|
||||
ContractFolderID: strings.TrimSpace(contractFolderID),
|
||||
NoticePublicationID: strings.TrimSpace(noticePublicationID),
|
||||
Language: strings.ToLower(strings.TrimSpace(language)),
|
||||
Title: strings.TrimSpace(title),
|
||||
Description: strings.TrimSpace(description),
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
TranslationRequestSourceDailyJob = "daily_job"
|
||||
TranslationRequestSourceManualTrigger = "manual_trigger"
|
||||
@@ -122,15 +149,69 @@ type AnalyzeResponse struct {
|
||||
Model string `json:"model"`
|
||||
}
|
||||
|
||||
// PipelineTranslateRequest represents the request payload for POST /pipeline/translate.
|
||||
type PipelineTranslateRequest struct {
|
||||
Languages []string `json:"languages"`
|
||||
// ScrapeDocumentsRequest is the payload for POST /scrape/documents.
|
||||
type ScrapeDocumentsRequest struct {
|
||||
ContractFolderID string `json:"contract_folder_id"`
|
||||
NoticePublicationID string `json:"notice_publication_id"`
|
||||
}
|
||||
|
||||
// PipelineTranslateResponse represents the response from POST /pipeline/translate.
|
||||
type PipelineTranslateResponse struct {
|
||||
Status string `json:"status"`
|
||||
Languages []string `json:"languages"`
|
||||
// ScrapeDocumentsFile describes one downloaded document.
|
||||
type ScrapeDocumentsFile struct {
|
||||
Filename string `json:"filename"`
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
// ScrapeDocumentsResponse is returned by POST /scrape/documents.
|
||||
type ScrapeDocumentsResponse struct {
|
||||
Success bool `json:"success"`
|
||||
FilesDownloaded int `json:"files_downloaded"`
|
||||
Files []ScrapeDocumentsFile `json:"files"`
|
||||
}
|
||||
|
||||
// ScrapeDocumentsBatchRequest is the payload for POST /scrape/documents/batch.
|
||||
type ScrapeDocumentsBatchRequest struct {
|
||||
Tenders []TenderRef `json:"tenders"`
|
||||
}
|
||||
|
||||
// SummarizeBatchRequest is the payload for POST /ai/summarize/batch.
|
||||
type SummarizeBatchRequest struct {
|
||||
Tenders []TenderRef `json:"tenders"`
|
||||
}
|
||||
|
||||
// TranslateBatchRequest is the payload for POST /ai/translate/batch.
|
||||
type TranslateBatchRequest struct {
|
||||
Tenders []TenderRef `json:"tenders"`
|
||||
Languages []string `json:"languages"`
|
||||
}
|
||||
|
||||
// BatchAcceptedResponse is returned by background batch endpoints (HTTP 202).
|
||||
type BatchAcceptedResponse struct {
|
||||
Status string `json:"status"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
// PipelineSyncResponse is returned by POST /pipeline/sync.
|
||||
type PipelineSyncResponse struct {
|
||||
Stored int `json:"stored"`
|
||||
}
|
||||
|
||||
// PipelineRunRequest is the payload for POST /pipeline/run.
|
||||
type PipelineRunRequest struct {
|
||||
ContractFolderID string `json:"contract_folder_id"`
|
||||
NoticePublicationID string `json:"notice_publication_id"`
|
||||
Languages []string `json:"languages"`
|
||||
}
|
||||
|
||||
// PipelineRunBatchRequest is the payload for POST /pipeline/run/batch.
|
||||
type PipelineRunBatchRequest struct {
|
||||
Tenders []TenderRef `json:"tenders"`
|
||||
Languages []string `json:"languages"`
|
||||
}
|
||||
|
||||
// PipelineStartedResponse is returned by POST /pipeline/daily-run and POST /pipeline/auto.
|
||||
type PipelineStartedResponse struct {
|
||||
Status string `json:"status"`
|
||||
Report string `json:"report"`
|
||||
}
|
||||
|
||||
// PipelineActionResponse is returned by fire-and-forget pipeline endpoints.
|
||||
@@ -138,6 +219,31 @@ type PipelineActionResponse struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// PipelineReportQuery holds optional query params for GET /pipeline/report and GET /pipeline/stats.
|
||||
type PipelineReportQuery struct {
|
||||
Window string `json:"window,omitempty"`
|
||||
}
|
||||
|
||||
// PipelineReportResponse is returned by GET /pipeline/report.
|
||||
type PipelineReportResponse struct {
|
||||
Window string `json:"window"`
|
||||
From string `json:"from"`
|
||||
To string `json:"to"`
|
||||
Summary map[string]interface{} `json:"summary,omitempty"`
|
||||
Days map[string]interface{} `json:"days,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// PipelineStatsResponse is returned by GET /pipeline/stats.
|
||||
type PipelineStatsResponse struct {
|
||||
GeneratedAt string `json:"generated_at"`
|
||||
EventLog map[string]interface{} `json:"event_log"`
|
||||
Minio map[string]interface{} `json:"minio"`
|
||||
}
|
||||
|
||||
// PipelineMinioStatsResponse is returned by GET /pipeline/minio-stats.
|
||||
type PipelineMinioStatsResponse map[string]interface{}
|
||||
|
||||
// OnboardingRequest is the payload for POST /onboarding.
|
||||
type OnboardingRequest struct {
|
||||
CompanyID string `json:"company_id"`
|
||||
|
||||
Reference in New Issue
Block a user