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:
Mazyar
2026-06-14 12:54:13 +03:30
parent a825c4a271
commit dcf19b91cd
12 changed files with 1460 additions and 56 deletions
+73
View File
@@ -0,0 +1,73 @@
package ai_pipeline
import (
"strings"
"tm/pkg/ai_summarizer"
)
// TenderRefForm identifies one tender in batch and pipeline requests.
type TenderRefForm struct {
ContractFolderID string `json:"contract_folder_id" valid:"required"`
NoticePublicationID string `json:"notice_publication_id" valid:"required"`
}
// ScrapeDocumentsForm is the request for POST /admin/v1/ai-pipeline/scrape/documents.
type ScrapeDocumentsForm struct {
ContractFolderID string `json:"contract_folder_id" valid:"required"`
NoticePublicationID string `json:"notice_publication_id" valid:"required"`
}
// TenderBatchForm is the request body for batch scrape and summarize endpoints.
type TenderBatchForm struct {
Tenders []TenderRefForm `json:"tenders" valid:"required"`
}
// TranslateBatchForm is the request body for POST /admin/v1/ai-pipeline/translate/batch.
type TranslateBatchForm struct {
Tenders []TenderRefForm `json:"tenders" valid:"required"`
Languages []string `json:"languages" valid:"required"`
}
// PipelineRunForm is the request body for POST /admin/v1/ai-pipeline/run.
type PipelineRunForm struct {
ContractFolderID string `json:"contract_folder_id" valid:"required"`
NoticePublicationID string `json:"notice_publication_id" valid:"required"`
Languages []string `json:"languages" valid:"required"`
}
// PipelineRunBatchForm is the request body for POST /admin/v1/ai-pipeline/run/batch.
type PipelineRunBatchForm struct {
Tenders []TenderRefForm `json:"tenders" valid:"required"`
Languages []string `json:"languages" valid:"required"`
}
// PipelineWindowQueryForm is the query form for report and stats endpoints.
type PipelineWindowQueryForm struct {
Window string `query:"window" valid:"optional,in(last_hour|last_24h|today|yesterday|last_7_days|last_30_days|all|daily)"`
}
func toTenderRefs(forms []TenderRefForm) []ai_summarizer.TenderRef {
refs := make([]ai_summarizer.TenderRef, 0, len(forms))
for _, form := range forms {
refs = append(refs, ai_summarizer.NewTenderRef(form.ContractFolderID, form.NoticePublicationID))
}
return refs
}
func normalizeLanguages(languages []string) []string {
out := make([]string, 0, len(languages))
seen := make(map[string]struct{}, len(languages))
for _, language := range languages {
lang := strings.ToLower(strings.TrimSpace(language))
if lang == "" {
continue
}
if _, dup := seen[lang]; dup {
continue
}
seen[lang] = struct{}{}
out = append(out, lang)
}
return out
}