translation body update
This commit is contained in:
@@ -88,6 +88,12 @@ func (w *TranslationWorker) translateTender(t *tender.Tender) {
|
|||||||
if t.NoticePublicationID == "" {
|
if t.NoticePublicationID == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if strings.TrimSpace(t.ContractFolderID) == "" {
|
||||||
|
w.Logger.Debug("Skipping tender translation: missing contract_folder_id", map[string]interface{}{
|
||||||
|
"tender_id": t.ID.Hex(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
if existing, ok := t.Translations[w.TargetLanguage]; ok && strings.TrimSpace(existing.Title) != "" {
|
if existing, ok := t.Translations[w.TargetLanguage]; ok && strings.TrimSpace(existing.Title) != "" {
|
||||||
w.Logger.Debug("Skipping tender translation because target language already exists", map[string]interface{}{
|
w.Logger.Debug("Skipping tender translation because target language already exists", map[string]interface{}{
|
||||||
"tender_id": t.ID.Hex(),
|
"tender_id": t.ID.Hex(),
|
||||||
@@ -98,16 +104,18 @@ func (w *TranslationWorker) translateTender(t *tender.Tender) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resp, err := w.AIClient.FetchTranslationOnDemand(context.Background(), ai_summarizer.TranslateRequest{
|
resp, err := w.AIClient.FetchTranslationOnDemand(context.Background(), ai_summarizer.TranslateRequest{
|
||||||
NoticeID: t.NoticePublicationID,
|
NoticeID: t.NoticePublicationID,
|
||||||
Title: t.Title,
|
ContractFolderID: t.ContractFolderID,
|
||||||
Description: t.Description,
|
NoticePublicationID: t.NoticePublicationID,
|
||||||
Language: w.TargetLanguage,
|
Title: t.Title,
|
||||||
|
Description: t.Description,
|
||||||
|
Language: w.TargetLanguage,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Logger.Error("Failed to translate tender", map[string]interface{}{
|
w.Logger.Error("Failed to translate tender", map[string]interface{}{
|
||||||
"tender_id": t.ID.Hex(),
|
"tender_id": t.ID.Hex(),
|
||||||
"notice_id": t.NoticePublicationID,
|
"notice_id": t.NoticePublicationID,
|
||||||
"target_language": w.TargetLanguage,
|
"target_language": w.TargetLanguage,
|
||||||
"translation_error": err.Error(),
|
"translation_error": err.Error(),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
@@ -133,9 +141,9 @@ func (w *TranslationWorker) translateTender(t *tender.Tender) {
|
|||||||
|
|
||||||
if err := w.TenderRepo.Update(context.Background(), t); err != nil {
|
if err := w.TenderRepo.Update(context.Background(), t); err != nil {
|
||||||
w.Logger.Error("Failed to persist translated tender", map[string]interface{}{
|
w.Logger.Error("Failed to persist translated tender", map[string]interface{}{
|
||||||
"tender_id": t.ID.Hex(),
|
"tender_id": t.ID.Hex(),
|
||||||
"notice_id": t.NoticePublicationID,
|
"notice_id": t.NoticePublicationID,
|
||||||
"target_language": w.TargetLanguage,
|
"target_language": w.TargetLanguage,
|
||||||
"persistence_error": err.Error(),
|
"persistence_error": err.Error(),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1047,6 +1047,9 @@ func (s *tenderService) TriggerAITranslate(ctx context.Context, id, language str
|
|||||||
if t.NoticePublicationID == "" {
|
if t.NoticePublicationID == "" {
|
||||||
return nil, fmt.Errorf("tender has no notice publication ID")
|
return nil, fmt.Errorf("tender has no notice publication ID")
|
||||||
}
|
}
|
||||||
|
if strings.TrimSpace(t.ContractFolderID) == "" {
|
||||||
|
return nil, fmt.Errorf("tender has no contract folder ID")
|
||||||
|
}
|
||||||
|
|
||||||
if tr, ok := t.Translations[targetLanguage]; ok {
|
if tr, ok := t.Translations[targetLanguage]; ok {
|
||||||
return &AITranslateResponse{
|
return &AITranslateResponse{
|
||||||
@@ -1058,10 +1061,12 @@ func (s *tenderService) TriggerAITranslate(ctx context.Context, id, language str
|
|||||||
}
|
}
|
||||||
|
|
||||||
resp, err := s.aiSummarizerClient.FetchTranslationOnDemand(ctx, ai_summarizer.TranslateRequest{
|
resp, err := s.aiSummarizerClient.FetchTranslationOnDemand(ctx, ai_summarizer.TranslateRequest{
|
||||||
NoticeID: t.NoticePublicationID,
|
NoticeID: t.NoticePublicationID,
|
||||||
Title: t.Title,
|
ContractFolderID: t.ContractFolderID,
|
||||||
Description: t.Description,
|
NoticePublicationID: t.NoticePublicationID,
|
||||||
Language: targetLanguage,
|
Title: t.Title,
|
||||||
|
Description: t.Description,
|
||||||
|
Language: targetLanguage,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("On-demand AI translation failed", map[string]interface{}{
|
s.logger.Error("On-demand AI translation failed", map[string]interface{}{
|
||||||
|
|||||||
@@ -42,10 +42,12 @@ type StoredDocument struct {
|
|||||||
// TranslateRequest represents the request payload sent to the AI service
|
// TranslateRequest represents the request payload sent to the AI service
|
||||||
// POST /ai/translate endpoint.
|
// POST /ai/translate endpoint.
|
||||||
type TranslateRequest struct {
|
type TranslateRequest struct {
|
||||||
NoticeID string `json:"notice_id"` // required
|
NoticeID string `json:"notice_id"` // required (TED-style notice key)
|
||||||
Title string `json:"title"` // required
|
ContractFolderID string `json:"contract_folder_id"` // required by AI service (procedure / MinIO prefix)
|
||||||
Description string `json:"description"` // required
|
NoticePublicationID string `json:"notice_publication_id"` // required by AI service
|
||||||
Language string `json:"language,omitempty"` // optional target language override
|
Title string `json:"title"` // required
|
||||||
|
Description string `json:"description"` // required
|
||||||
|
Language string `json:"language,omitempty"` // optional target language override
|
||||||
}
|
}
|
||||||
|
|
||||||
// TranslateResponse represents the response from the AI translation API.
|
// TranslateResponse represents the response from the AI translation API.
|
||||||
|
|||||||
Reference in New Issue
Block a user