Skip to content

Commit c978685

Browse files
committed
add curation.models.TranslatedContent
1 parent 0b76bdc commit c978685

File tree

3 files changed

+110
-2
lines changed

3 files changed

+110
-2
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Generated by Django 5.2.1 on 2025-06-14 05:26
2+
3+
import curation.models
4+
import django.db.models.deletion
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('curation', '0012_llmusage_total_tokens'),
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='TranslatedContent',
17+
fields=[
18+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19+
('title', models.CharField(help_text='제목', max_length=512)),
20+
('slug', models.SlugField(help_text='slug', max_length=512)),
21+
('description', models.TextField(help_text='설명')),
22+
('tags', models.JSONField(default=list, help_text='태그')),
23+
('written_date', models.DateField(blank=True, help_text='작성 일자', null=True)),
24+
('author', models.CharField(blank=True, help_text='작성자', max_length=100, null=True)),
25+
('content', models.FileField(blank=True, help_text='번역된 마크다운 콘텐츠 파일', null=True, upload_to=curation.models.translated_item_upload_path)),
26+
('model_name', models.CharField(help_text='사용된 모델명', max_length=100)),
27+
('source_url', models.URLField(help_text='원본 URL')),
28+
('created_at', models.DateTimeField(auto_now_add=True)),
29+
('updated_at', models.DateTimeField(auto_now=True)),
30+
('source_rss_item', models.ForeignKey(help_text='원본 RSS 아이템', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='translated_contents', to='curation.rssitem')),
31+
],
32+
),
33+
]

pythonkr_backend/curation/models.py

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
def rss_item_upload_path(instance, filename):
1212
"""Generate upload path for RSS item crawled content"""
13-
from datetime import datetime
1413
now = datetime.now()
1514
return f"rssitem-crawling/{now.year}/{now.month:02d}/{instance.id}-crawl.md"
1615

@@ -604,3 +603,62 @@ class Meta:
604603
verbose_name = "LLM Usage"
605604
verbose_name_plural = "LLM Usage"
606605
ordering = ['-date', '-created_at']
606+
607+
def translated_item_upload_path(instance, filename):
608+
"""Generate upload path for RSS item translated content"""
609+
now = datetime.now()
610+
return f"tr/{now.year}/{now.month:02d}/{instance.id}-ko.md"
611+
612+
613+
class TranslatedContent(models.Model):
614+
title = models.CharField(
615+
max_length=512,
616+
help_text="제목"
617+
)
618+
slug = models.SlugField(
619+
max_length=512,
620+
help_text="slug"
621+
)
622+
description = models.TextField(
623+
help_text="설명"
624+
)
625+
tags = models.JSONField(
626+
default=list,
627+
help_text="태그"
628+
)
629+
written_date = models.DateField(
630+
help_text="작성 일자",
631+
blank=True,
632+
null=True,
633+
)
634+
author = models.CharField(
635+
max_length=100,
636+
blank=True,
637+
null=True,
638+
help_text="작성자"
639+
)
640+
content = models.FileField(
641+
upload_to=translated_item_upload_path,
642+
blank=True,
643+
null=True,
644+
help_text="번역된 마크다운 콘텐츠 파일"
645+
)
646+
647+
model_name = models.CharField(
648+
max_length=100,
649+
help_text="사용된 모델명"
650+
)
651+
652+
source_rss_item = models.ForeignKey(
653+
RSSItem,
654+
on_delete=models.CASCADE,
655+
related_name="translated_contents",
656+
null=True,
657+
help_text="원본 RSS 아이템"
658+
)
659+
source_url = models.URLField(
660+
help_text="원본 URL"
661+
)
662+
663+
created_at = models.DateTimeField(auto_now_add=True)
664+
updated_at = models.DateTimeField(auto_now=True)

pythonkr_backend/curation/utils.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import httpx
22
import llm
3-
from pydantic import BaseModel
3+
from pydantic import BaseModel, Field
4+
from pydantic_ai import Agent
5+
from datetime import date, datetime, time, timedelta
46

57
import os
68

@@ -75,3 +77,18 @@ def categorize_summary(summary: str, categories: list[str]):
7577

7678
return response.text()
7779

80+
81+
class TranslatedResult(BaseModel):
82+
title: str = Field(description="The title of the translated article")
83+
slug: str = Field(
84+
description="The URL slug. Do not include the language code. Make it similar to the original URL."
85+
)
86+
description: str = Field(
87+
description="The description of the translated article. Don't mention that it's translated."
88+
)
89+
author: str = Field(description="The author of the translated article")
90+
tags: list[str] = Field(
91+
description="List of Python-related tags inferred from the document."
92+
)
93+
written_date: date = Field(description="The written date of the translated article")
94+
content: str = Field(description="The content of the translated article")

0 commit comments

Comments
 (0)