Integrated AI translation
This commit is contained in:
+35
-2
@@ -35,6 +35,7 @@ type SearchForm struct {
|
||||
BuyerOrganizationID *string `query:"buyer_organization_id" valid:"optional"`
|
||||
Languages []string `query:"languages" valid:"optional"`
|
||||
OnlyActiveDeadlines bool `query:"-" valid:"optional"`
|
||||
Language *string `query:"lang" valid:"optional"`
|
||||
}
|
||||
|
||||
// SearchResponse represents the response for listing tenders
|
||||
@@ -66,6 +67,7 @@ type TenderResponse struct {
|
||||
TenderID string `json:"tender_id"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
OverallSummary string `json:"overall_summary,omitempty"` // AI-generated summary from the pipeline
|
||||
Language string `json:"language,omitempty"`
|
||||
}
|
||||
|
||||
type OrganizationResponse struct {
|
||||
@@ -74,16 +76,33 @@ type OrganizationResponse struct {
|
||||
|
||||
// ToTenderResponse converts a Tender entity to TenderResponse
|
||||
func (t *Tender) ToResponse() *TenderResponse {
|
||||
return t.ToResponseWithLanguage("")
|
||||
}
|
||||
|
||||
// ToResponseWithLanguage converts a Tender entity to TenderResponse using a preferred language.
|
||||
// When language is provided and translation exists, translated title/description are returned.
|
||||
func (t *Tender) ToResponseWithLanguage(language string) *TenderResponse {
|
||||
|
||||
org := &OrganizationResponse{}
|
||||
if t.BuyerOrganization != nil {
|
||||
org.Name = t.BuyerOrganization.Name
|
||||
}
|
||||
title := t.Title
|
||||
description := t.Description
|
||||
usedLanguage := ""
|
||||
if language != "" {
|
||||
if entry, ok := t.Translations[language]; ok {
|
||||
title = entry.Title
|
||||
description = entry.Description
|
||||
usedLanguage = language
|
||||
}
|
||||
}
|
||||
|
||||
response := &TenderResponse{
|
||||
ID: t.ID.Hex(),
|
||||
NoticePublicationID: t.NoticePublicationID,
|
||||
Title: t.Title,
|
||||
Description: t.Description,
|
||||
Title: title,
|
||||
Description: description,
|
||||
ProcurementTypeCode: t.ProcurementTypeCode,
|
||||
ProcedureCode: t.ProcedureCode,
|
||||
EstimatedValue: t.EstimatedValue,
|
||||
@@ -100,11 +119,25 @@ func (t *Tender) ToResponse() *TenderResponse {
|
||||
Status: t.Status,
|
||||
TenderID: t.TenderID,
|
||||
CreatedAt: t.CreatedAt,
|
||||
Language: usedLanguage,
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
// AITranslateRequest represents a request for on-demand AI translation.
|
||||
type AITranslateRequest struct {
|
||||
Language string `json:"language" valid:"required,stringlength(2|5)~Language must be between 2 and 5 characters"`
|
||||
}
|
||||
|
||||
// AITranslateResponse represents the response for AI translation trigger.
|
||||
type AITranslateResponse struct {
|
||||
NoticeID string `json:"notice_id"`
|
||||
Language string `json:"language"`
|
||||
TranslatedTitle string `json:"translated_title"`
|
||||
TranslatedDescription string `json:"translated_description"`
|
||||
}
|
||||
|
||||
// AISummaryResponse represents the response for getting an AI-generated summary
|
||||
type AISummaryResponse struct {
|
||||
NoticeID string `json:"notice_id"`
|
||||
|
||||
Reference in New Issue
Block a user