queryPrompt.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // AI 扩写(LLM variant)搜索词的提示词解释:从 RunDashboardPage 抽出,供发现旅程视频详情复用。
  2. import { compactValue } from "@/lib/status/status";
  3. export function isLlmVariantQuery(query: Record<string, unknown>): boolean {
  4. return query.search_query_generation_method === "llm_variant";
  5. }
  6. export function seedTermForQuery(query: Record<string, unknown>): unknown {
  7. const seedRef =
  8. query.pattern_seed_ref && typeof query.pattern_seed_ref === "object"
  9. ? (query.pattern_seed_ref as Record<string, unknown>)
  10. : {};
  11. const llmInput =
  12. query.llm_input_evidence && typeof query.llm_input_evidence === "object"
  13. ? (query.llm_input_evidence as Record<string, unknown>)
  14. : {};
  15. return llmInput.seed_term || seedRef.seed_term || query.search_query;
  16. }
  17. export function llmVariantPromptPayload(query: Record<string, unknown>): Record<string, unknown> {
  18. const llmInput =
  19. query.llm_input_evidence && typeof query.llm_input_evidence === "object"
  20. ? (query.llm_input_evidence as Record<string, unknown>)
  21. : {};
  22. const seedTerm = seedTermForQuery(query);
  23. return {
  24. "这个提示词在做什么": "拿一个 DemandAgent 种子词,结合 Pattern 证据,让 LLM 生成一条相邻但不重复的抖音搜索 query。",
  25. "种子词": seedTerm,
  26. "生成结果": query.search_query,
  27. "父 query": query.llm_variant_of || "无",
  28. "提示词版本": query.llm_prompt_version || "query_variant.v1",
  29. "LLM 模型": query.llm_generation_model || "缺失",
  30. messages: [
  31. {
  32. role: "system",
  33. content:
  34. "You generate one concise Chinese short-video search query. " +
  35. "Return exactly one plain query string. Do not return JSON, " +
  36. "lists, quotes, explanations, or multiple lines."
  37. },
  38. {
  39. role: "user",
  40. content: [
  41. "Seed term:",
  42. compactValue(seedTerm),
  43. "",
  44. "Evidence context:",
  45. JSON.stringify(llmInput, null, 2),
  46. "",
  47. "Create one adjacent search phrase that stays faithful to the evidence. Avoid any phrase listed in existing_search_queries."
  48. ].join("\n")
  49. }
  50. ],
  51. "输入证据摘要": {
  52. seed_terms: llmInput.seed_terms,
  53. itemset_ids: llmInput.itemset_ids,
  54. category_bindings: llmInput.category_bindings,
  55. element_bindings: llmInput.element_bindings,
  56. existing_search_queries: llmInput.existing_search_queries
  57. }
  58. };
  59. }