Update category management and RSS endpoint handling

This commit is contained in:
2025-06-08 21:50:31 +09:00
parent 4aa1b5c56a
commit cd0e4065fc
13 changed files with 1171 additions and 70 deletions

View File

@ -143,3 +143,69 @@ ${articleDetails}
);
}
}
export async function openAI_ClassifyEpisode(
title: string,
description?: string,
content?: string,
): Promise<string> {
if (!title || title.trim() === "") {
throw new Error("Episode title is required for classification");
}
// Build the text for classification based on available data
let textForClassification = `タイトル: ${title}`;
if (description && description.trim()) {
textForClassification += `\n説明: ${description}`;
}
if (content && content.trim()) {
const maxContentLength = 1500;
const truncatedContent = content.length > maxContentLength
? content.substring(0, maxContentLength) + "..."
: content;
textForClassification += `\n内容: ${truncatedContent}`;
}
const prompt = `
以下のポッドキャストエピソードの情報を見て、適切なトピックカテゴリに分類してください。
${textForClassification}
以下のカテゴリから1つを選択してください:
- テクノロジー
- ビジネス
- エンターテインメント
- スポーツ
- 科学
- 健康
- 政治
- 環境
- 教育
- その他
エピソードの内容に最も適合するカテゴリを上記から1つだけ返してください。
`;
try {
const response = await openai.chat.completions.create({
model: config.openai.modelName,
messages: [{ role: "user", content: prompt.trim() }],
temperature: 0.3,
});
const category = response.choices[0]?.message?.content?.trim();
if (!category) {
console.warn("OpenAI returned empty episode category, using default");
return "その他";
}
return category;
} catch (error) {
console.error("Error classifying episode:", error);
throw new Error(
`Failed to classify episode: ${error instanceof Error ? error.message : "Unknown error"}`,
);
}
}