fix: revert to single Perplexity query with proven prompt pattern
Split queries performed worse. The proven working pattern is: - Single query with Korean+English clinic name - "검색해서 찾아줘. 검색 결과에서 발견된 계정을 모두 알려줘" phrasing - All channels in one request - English name in parentheses helps Perplexity find international accounts Tested: "그랜드성형외과 (Grand Plastic Surgery)" → finds Instagram, YouTube, Facebook, TikTok, Naver Blog all in one call. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>claude/bold-hawking
parent
5157cf446a
commit
087f65eec1
|
|
@ -284,77 +284,26 @@ Deno.serve(async (req) => {
|
|||
} catch { /* skip */ }
|
||||
})());
|
||||
|
||||
// ─── B4. Perplexity: 3 separate focused queries (like the research methodology) ───
|
||||
// ─── B4. Perplexity: Single comprehensive query (proven pattern) ───
|
||||
let perplexityResearch: Record<string, unknown> | null = null;
|
||||
|
||||
if (PERPLEXITY_API_KEY) {
|
||||
const ppxHeaders = { "Content-Type": "application/json", Authorization: `Bearer ${PERPLEXITY_API_KEY}` };
|
||||
const ppxSystem = "You are a social media researcher. Search the web and find accounts. Respond ONLY with valid JSON, no explanation.";
|
||||
// Build clinic name with English variant for better search
|
||||
const clinicNameEn = clinic.clinicNameEn || '';
|
||||
const searchName = clinicNameEn
|
||||
? `${resolvedName} (${clinicNameEn})`
|
||||
: resolvedName;
|
||||
|
||||
// B4a. Instagram + YouTube 검색 (가장 중요)
|
||||
stageBTasks.push((async () => {
|
||||
try {
|
||||
const res = await fetch("https://api.perplexity.ai/chat/completions", {
|
||||
method: "POST", headers: ppxHeaders,
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", Authorization: `Bearer ${PERPLEXITY_API_KEY}` },
|
||||
body: JSON.stringify({
|
||||
model: "sonar",
|
||||
messages: [
|
||||
{ role: "system", content: ppxSystem },
|
||||
{ role: "user", content: `${resolvedName} 성형외과 공식 인스타그램 계정과 유튜브 채널을 찾아줘. 인스타는 여러 계정(국문, 영문, 원장 등)이 있을 수 있어.\n\n{"instagram": ["@handle1", "@handle2"], "youtube": ["@handle_or_url"]}` },
|
||||
],
|
||||
temperature: 0.1,
|
||||
}),
|
||||
});
|
||||
const data = await res.json();
|
||||
let text = data.choices?.[0]?.message?.content || "";
|
||||
const m = text.match(/\{[\s\S]*\}/);
|
||||
if (m) {
|
||||
const parsed = JSON.parse(m[0]);
|
||||
const ig = Array.isArray(parsed.instagram) ? parsed.instagram : parsed.instagram ? [parsed.instagram] : [];
|
||||
const yt = Array.isArray(parsed.youtube) ? parsed.youtube : parsed.youtube ? [parsed.youtube] : [];
|
||||
ig.forEach((h: unknown) => { if (h && typeof h === 'string') apiHandles.instagram!.push(h); });
|
||||
yt.forEach((h: unknown) => { if (h && typeof h === 'string') apiHandles.youtube!.push(h); });
|
||||
}
|
||||
} catch { /* skip */ }
|
||||
})());
|
||||
|
||||
// B4b. Facebook + TikTok + 네이버 블로그 + 카카오
|
||||
stageBTasks.push((async () => {
|
||||
try {
|
||||
const res = await fetch("https://api.perplexity.ai/chat/completions", {
|
||||
method: "POST", headers: ppxHeaders,
|
||||
body: JSON.stringify({
|
||||
model: "sonar",
|
||||
messages: [
|
||||
{ role: "system", content: ppxSystem },
|
||||
{ role: "user", content: `${resolvedName} 병원의 페이스북, 틱톡, 네이버블로그, 카카오채널 계정을 검색해줘.\n\n{"facebook": "page_or_url", "tiktok": "@handle", "naverBlog": "blogId", "kakao": "channelId"}` },
|
||||
],
|
||||
temperature: 0.1,
|
||||
}),
|
||||
});
|
||||
const data = await res.json();
|
||||
let text = data.choices?.[0]?.message?.content || "";
|
||||
const m = text.match(/\{[\s\S]*\}/);
|
||||
if (m) {
|
||||
const parsed = JSON.parse(m[0]);
|
||||
if (parsed.facebook && typeof parsed.facebook === 'string') apiHandles.facebook!.push(parsed.facebook);
|
||||
if (parsed.tiktok && typeof parsed.tiktok === 'string') apiHandles.tiktok!.push(parsed.tiktok);
|
||||
if (parsed.naverBlog && typeof parsed.naverBlog === 'string') apiHandles.naverBlog!.push(parsed.naverBlog);
|
||||
if (parsed.kakao && typeof parsed.kakao === 'string') apiHandles.kakao!.push(parsed.kakao);
|
||||
}
|
||||
} catch { /* skip */ }
|
||||
})());
|
||||
|
||||
// B4c. 강남언니 + 리뷰 플랫폼
|
||||
stageBTasks.push((async () => {
|
||||
try {
|
||||
const res = await fetch("https://api.perplexity.ai/chat/completions", {
|
||||
method: "POST", headers: ppxHeaders,
|
||||
body: JSON.stringify({
|
||||
model: "sonar",
|
||||
messages: [
|
||||
{ role: "system", content: ppxSystem },
|
||||
{ role: "user", content: `${resolvedName} 병원이 강남언니(gangnamunni.com)에 등록되어있는지 검색해줘. URL도 찾아줘.\n\n{"gangnamUnni": {"registered": true, "url": "https://gangnamunni.com/hospitals/...", "rating": 9.5, "reviews": 1000}}` },
|
||||
{ role: "system", content: "You are a social media researcher. Search the web and find social media accounts. Respond ONLY with valid JSON." },
|
||||
{ role: "user", content: `${searchName} 병원의 인스타그램, 유튜브, 페이스북, 틱톡, 네이버블로그 계정을 검색해서 찾아줘. 검색 결과에서 발견된 계정을 모두 알려줘. 인스타그램은 여러 계정이 있을 수 있어.\n\n{"instagram": ["handle1", "handle2"], "youtube": "channel URL or handle", "facebook": "page name or URL", "tiktok": "handle", "naverBlog": "blog ID"}` },
|
||||
],
|
||||
temperature: 0.1,
|
||||
}),
|
||||
|
|
@ -365,6 +314,38 @@ Deno.serve(async (req) => {
|
|||
if (m) {
|
||||
const parsed = JSON.parse(m[0]);
|
||||
perplexityResearch = parsed;
|
||||
|
||||
const ig = Array.isArray(parsed.instagram) ? parsed.instagram : parsed.instagram ? [parsed.instagram] : [];
|
||||
const yt = Array.isArray(parsed.youtube) ? parsed.youtube : parsed.youtube ? [parsed.youtube] : [];
|
||||
ig.forEach((h: unknown) => { if (h && typeof h === 'string') apiHandles.instagram!.push(h); });
|
||||
yt.forEach((h: unknown) => { if (h && typeof h === 'string') apiHandles.youtube!.push(h); });
|
||||
if (parsed.facebook && typeof parsed.facebook === 'string') apiHandles.facebook!.push(parsed.facebook);
|
||||
if (parsed.tiktok && typeof parsed.tiktok === 'string') apiHandles.tiktok!.push(parsed.tiktok);
|
||||
if (parsed.naverBlog && typeof parsed.naverBlog === 'string') apiHandles.naverBlog!.push(parsed.naverBlog);
|
||||
}
|
||||
} catch { /* skip */ }
|
||||
})());
|
||||
|
||||
// B4b. 강남언니 검색 (별도 — gangnamunni URL 힌트 필요)
|
||||
stageBTasks.push((async () => {
|
||||
try {
|
||||
const res = await fetch("https://api.perplexity.ai/chat/completions", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", Authorization: `Bearer ${PERPLEXITY_API_KEY}` },
|
||||
body: JSON.stringify({
|
||||
model: "sonar",
|
||||
messages: [
|
||||
{ role: "system", content: "You search for clinic listings on medical platforms. Respond ONLY with valid JSON." },
|
||||
{ role: "user", content: `${resolvedName} 병원 강남언니 gangnamunni.com 페이지를 찾아줘.\n\n{"gangnamUnni": {"url": "https://gangnamunni.com/hospitals/...", "rating": 9.5, "reviews": 1000}}` },
|
||||
],
|
||||
temperature: 0.1,
|
||||
}),
|
||||
});
|
||||
const data = await res.json();
|
||||
let text = data.choices?.[0]?.message?.content || "";
|
||||
const m = text.match(/\{[\s\S]*\}/);
|
||||
if (m) {
|
||||
const parsed = JSON.parse(m[0]);
|
||||
if (parsed.gangnamUnni?.url) gangnamUnniHintUrl = String(parsed.gangnamUnni.url);
|
||||
}
|
||||
} catch { /* skip */ }
|
||||
|
|
|
|||
Loading…
Reference in New Issue