fix:트렌딩 키워드 가져오기 실패 개선 (빈 결과 캐시 방지 + 리프레이밍 폴백)
- 빈 결과를 30분간 캐시하는 문제 수정 (성공 결과만 캐시) - 건강 키워드가 없을 때 리프레이밍 폴백 추가 (트렌드를 건강 관점으로 재해석) - 최종 폴백: 원본 인기 키워드 표시 - 프론트엔드 에러/안내 메시지 분리 (오류 vs 건강 키워드 없음) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -109,6 +109,80 @@ public function filterHealthTrending(array $trendingKeywords): array
|
||||
})->values()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 폴백: 트렌딩 키워드를 건강 관점에서 리프레이밍
|
||||
* (filterHealthTrending에서 0개 반환 시 호출)
|
||||
*/
|
||||
public function reframeAsHealthTrending(array $trendingKeywords): array
|
||||
{
|
||||
if (empty($trendingKeywords)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$keywordList = collect($trendingKeywords)->take(10)->map(function ($item, $i) {
|
||||
$news = ! empty($item['news_title']) ? " (뉴스: {$item['news_title']})" : '';
|
||||
|
||||
return ($i + 1) . ". {$item['keyword']}{$news}";
|
||||
})->implode("\n");
|
||||
|
||||
$prompt = <<<PROMPT
|
||||
당신은 창의적인 건강/웰빙 YouTube Shorts 채널 기획자입니다.
|
||||
|
||||
아래는 오늘의 한국 실시간 급상승 키워드입니다:
|
||||
{$keywordList}
|
||||
|
||||
이 키워드들은 직접적인 건강 주제가 아닙니다.
|
||||
하지만 시청자의 관심을 끌기 위해 이 트렌딩 키워드를 건강/웰빙 관점으로 "리프레이밍"하세요.
|
||||
|
||||
=== 리프레이밍 예시 ===
|
||||
- "올림픽" → health_angle: "선수건강", suggested_topic: "올림픽 선수들의 놀라운 식단 비밀"
|
||||
- "한파" → health_angle: "저체온증", suggested_topic: "한파에 절대 하면 안 되는 행동 3가지"
|
||||
- "설날" → health_angle: "명절증후군", suggested_topic: "설날 과식 후 속이 편해지는 방법"
|
||||
- "미세먼지" → health_angle: "호흡기", suggested_topic: "미세먼지 마스크 효과없는 착용법"
|
||||
|
||||
=== 규칙 ===
|
||||
- 최대 5개만 선택하여 리프레이밍
|
||||
- 너무 억지스럽거나 비윤리적인 연결은 하지 마세요
|
||||
- 리프레이밍이 자연스러운 것만 선택하세요
|
||||
- 최소 2개는 반드시 만들어주세요
|
||||
|
||||
반드시 아래 JSON 형식으로만 응답하세요 (다른 텍스트 없이):
|
||||
{
|
||||
"keywords": [
|
||||
{"keyword": "원본 키워드", "health_angle": "건강 태그 10자 이내", "suggested_topic": "건강 채널에서 다룰 구체적 주제 25자 이내"}
|
||||
]
|
||||
}
|
||||
PROMPT;
|
||||
|
||||
$result = $this->callGemini($prompt);
|
||||
|
||||
if (! $result) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$parsed = $this->parseJsonResponse($result);
|
||||
|
||||
if (! $parsed || empty($parsed['keywords'])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$trendingMap = collect($trendingKeywords)->keyBy('keyword');
|
||||
|
||||
return collect($parsed['keywords'])->map(function ($item) use ($trendingMap) {
|
||||
$original = $trendingMap->get($item['keyword']);
|
||||
|
||||
return [
|
||||
'keyword' => $item['keyword'],
|
||||
'health_angle' => $item['health_angle'] ?? '',
|
||||
'suggested_topic' => $item['suggested_topic'] ?? $item['keyword'],
|
||||
'traffic' => $original['traffic'] ?? '',
|
||||
'news_title' => $original['news_title'] ?? '',
|
||||
'pub_date' => $original['pub_date'] ?? null,
|
||||
'is_reframed' => true,
|
||||
];
|
||||
})->values()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 키워드 → 트렌딩 제목 5개 생성 (기본)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user