feat: implement dashboard store and API routes for city market scanning and analysis

This commit is contained in:
2569718930@qq.com
2026-04-24 12:46:44 +08:00
parent c61a3f500d
commit 467f736602
8 changed files with 723 additions and 41 deletions
+14 -1
View File
@@ -470,6 +470,18 @@ function buildFallbackAnswer(
};
}
function shouldUseRuleAnswer(
question: string,
context: ReturnType<typeof sanitizeContext>,
) {
if (detectUnsupported(question)) return true;
if (findMentionedCity(question, context)) return true;
if (isForecastQuestion(question)) return true;
return /当前|市场|机会|值得|参与|买|卖|yes|no|edge|排序|风险|概率|probability|emos|deb|价格|盘口|高风险|低风险|model|forecast|temperature|rank|buy|sell/i.test(
question,
);
}
async function generateWithGroq(params: {
question: string;
locale: string;
@@ -636,7 +648,8 @@ export async function POST(request: NextRequest) {
model: "rule-fallback",
};
if (!fallback.refused) {
const useRuleAnswer = shouldUseRuleAnswer(question, context);
if (!fallback.refused && !useRuleAnswer) {
try {
const generated = await generateWithGroq({
question,
@@ -6,6 +6,14 @@ import {
const API_BASE = process.env.POLYWEATHER_API_BASE_URL;
function parseBackendError(raw: string) {
try {
return JSON.parse(raw) as unknown;
} catch {
return raw.slice(0, 800);
}
}
export async function GET(
req: NextRequest,
context: { params: Promise<{ name: string }> },
@@ -49,7 +57,11 @@ export async function GET(
if (!res.ok) {
const raw = await res.text();
const response = NextResponse.json(
{ error: `Backend returned ${res.status}`, detail: raw.slice(0, 300) },
{
error: "Backend city market scan failed",
upstream_status: res.status,
detail: parseBackendError(raw),
},
{ status: 502 },
);
return applyAuthResponseCookies(response, auth.response);
@@ -63,8 +75,11 @@ export async function GET(
return applyAuthResponseCookies(response, auth.response);
} catch (error) {
const response = NextResponse.json(
{ error: "Failed to fetch city market scan", detail: String(error) },
{ status: 500 },
{
error: "Failed to fetch city market scan",
detail: String(error),
},
{ status: 502 },
);
return response;
}