Implement three divination modes, learn pages, and PM2 deploy on port 3130.
Add liuyao/bazi/combined flows with shared calc and AI infrastructure, 64-gua learn routes, and update Ubuntu PM2 deployment docs for port 3130. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
"use server";
|
||||
|
||||
import { streamAIResponse } from "@/lib/ai/stream";
|
||||
import {
|
||||
calculateBazi,
|
||||
formatBaziForPrompt,
|
||||
type BaziInput,
|
||||
} from "@/lib/calc/bazi";
|
||||
import { BAZI_SYSTEM_PROMPT } from "@/lib/prompts";
|
||||
|
||||
export async function getBaziAnswer(
|
||||
input: BaziInput,
|
||||
question: string,
|
||||
birthPlaceName: string,
|
||||
) {
|
||||
const chart = calculateBazi(input);
|
||||
const chartText = formatBaziForPrompt(chart);
|
||||
|
||||
return streamAIResponse(
|
||||
BAZI_SYSTEM_PROMPT,
|
||||
`【出生时空】
|
||||
出生地:${birthPlaceName}
|
||||
|
||||
【排盘信息】
|
||||
${chartText}
|
||||
|
||||
【问事】
|
||||
${question}`,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
"use server";
|
||||
|
||||
import { streamAIResponse } from "@/lib/ai/stream";
|
||||
import {
|
||||
calculateBazi,
|
||||
formatBaziForPrompt,
|
||||
type BaziInput,
|
||||
} from "@/lib/calc/bazi";
|
||||
import {
|
||||
formatTimingForPrompt,
|
||||
getTimingInfoWithLongitude,
|
||||
} from "@/lib/calc/timing";
|
||||
import { COMBINED_SYSTEM_PROMPT } from "@/lib/prompts";
|
||||
import {
|
||||
extractChangeDetails,
|
||||
extractZhangMingRen,
|
||||
readGuaMarkdown,
|
||||
} from "@/lib/content/zhouyi";
|
||||
|
||||
export interface CombinedInput {
|
||||
birth: BaziInput;
|
||||
birthPlaceName: string;
|
||||
currentPlaceName: string;
|
||||
currentLongitude: number;
|
||||
calcDate: string;
|
||||
calcTime: string;
|
||||
question: string;
|
||||
hexagram?: {
|
||||
guaMark: string;
|
||||
guaTitle: string;
|
||||
guaResult: string;
|
||||
guaChange: string;
|
||||
};
|
||||
}
|
||||
|
||||
export async function getCombinedAnswer(input: CombinedInput) {
|
||||
const chart = calculateBazi(input.birth);
|
||||
const chartText = formatBaziForPrompt(chart);
|
||||
const { timing, trueSolarTime } = getTimingInfoWithLongitude(
|
||||
input.calcDate,
|
||||
input.calcTime,
|
||||
input.currentLongitude,
|
||||
);
|
||||
const timingText = [
|
||||
formatTimingForPrompt(timing, input.currentPlaceName, input.currentLongitude),
|
||||
`真太阳时:${trueSolarTime}`,
|
||||
].join("\n");
|
||||
|
||||
let hexagramText = "";
|
||||
if (input.hexagram) {
|
||||
const { guaMark, guaTitle, guaResult, guaChange } = input.hexagram;
|
||||
try {
|
||||
const guaDetail = await readGuaMarkdown(guaMark);
|
||||
const explain = extractZhangMingRen(guaDetail) ?? "";
|
||||
const changeList = extractChangeDetails(guaDetail, guaChange, guaTitle);
|
||||
hexagramText = [
|
||||
"",
|
||||
"【卦象 · 可选六爻】",
|
||||
`${guaTitle} ${guaResult} ${guaChange}`,
|
||||
explain,
|
||||
changeList.join("\n"),
|
||||
].join("\n");
|
||||
} catch {
|
||||
hexagramText = [
|
||||
"",
|
||||
"【卦象 · 可选六爻】",
|
||||
`${input.hexagram.guaTitle} ${input.hexagram.guaResult} ${input.hexagram.guaChange}`,
|
||||
].join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return streamAIResponse(
|
||||
COMBINED_SYSTEM_PROMPT,
|
||||
`【人和 · 八字排盘】
|
||||
出生地:${input.birthPlaceName}
|
||||
${chartText}
|
||||
|
||||
${timingText}
|
||||
${hexagramText}
|
||||
|
||||
【问事】
|
||||
${input.question}`,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
"use server";
|
||||
|
||||
import { streamAIResponse } from "@/lib/ai/stream";
|
||||
import {
|
||||
formatLiuyaoTimingForPrompt,
|
||||
getTimingInfoWithLongitude,
|
||||
} from "@/lib/calc/timing";
|
||||
import {
|
||||
extractChangeDetails,
|
||||
extractZhangMingRen,
|
||||
readGuaMarkdown,
|
||||
} from "@/lib/content/zhouyi";
|
||||
import { LIUYAO_SYSTEM_PROMPT } from "@/lib/prompts";
|
||||
|
||||
export interface LiuyaoInput {
|
||||
question: string;
|
||||
calcDate: string;
|
||||
calcTime: string;
|
||||
locationName: string;
|
||||
longitude: number;
|
||||
guaMark: string;
|
||||
guaTitle: string;
|
||||
guaResult: string;
|
||||
guaChange: string;
|
||||
}
|
||||
|
||||
export async function getLiuyaoAnswer(input: LiuyaoInput) {
|
||||
const { timing, trueSolarTime } = getTimingInfoWithLongitude(
|
||||
input.calcDate,
|
||||
input.calcTime,
|
||||
input.longitude,
|
||||
);
|
||||
const timingText = formatLiuyaoTimingForPrompt(
|
||||
timing,
|
||||
trueSolarTime,
|
||||
input.locationName,
|
||||
input.longitude,
|
||||
);
|
||||
|
||||
let guaDetailText = "";
|
||||
try {
|
||||
const guaDetail = await readGuaMarkdown(input.guaMark);
|
||||
const explain = extractZhangMingRen(guaDetail) ?? "";
|
||||
const changeList = extractChangeDetails(
|
||||
guaDetail,
|
||||
input.guaChange,
|
||||
input.guaTitle,
|
||||
);
|
||||
guaDetailText = [explain, changeList.join("\n")].filter(Boolean).join("\n");
|
||||
} catch {
|
||||
guaDetailText = "";
|
||||
}
|
||||
|
||||
return streamAIResponse(
|
||||
LIUYAO_SYSTEM_PROMPT,
|
||||
`${timingText}
|
||||
|
||||
【卦象】
|
||||
${input.guaTitle} ${input.guaResult} ${input.guaChange}
|
||||
|
||||
【问事】
|
||||
${input.question}
|
||||
|
||||
${guaDetailText}`,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user