Files
zhuiguang-ai/scripts/debug-json.mjs
T

64 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import OpenAI from "openai";
import "dotenv/config";
const openai = new OpenAI({
apiKey: process.env.DEEPSEEK_API_KEY,
baseURL: "https://api.deepseek.com/v1",
});
async function main() {
const prompt = `你是一个GitHub开源项目评测专家。请基于以下项目信息进行五维深度评测,并以JSON格式返回。务必只返回JSON,不要包含任何其他文字或Markdown格式。
项目信息:
- 仓库全名:TabbyML/tabby
- 简介:Self-hosted AI coding assistant
- GitHub Stars:33538
- 开源许可证:Apache-2.0
- README摘要:An open-source, self-hosted AI coding assistant.
请严格按照以下JSON结构输出:
{
"capability": { "score": 4.5, "summary": "一句话亮点", "detail": "80-120字分析" },
"devExp": { "score": 3.5, "summary": "体验总结", "detail": "80-120字" },
"costLicense": { "score": 4.0, "summary": "成本总结", "detail": "80-120字" },
"community": { "score": 4.5, "summary": "社区总结", "detail": "80-120字" },
"performance": { "score": 3.5, "summary": "性能总结", "detail": "80-120字" },
"overall": 4.0,
"tags": ["标签1", "标签2", "标签3"]
}`;
const { choices } = await openai.chat.completions.create({
model: "deepseek-v4-pro",
messages: [{ role: "user", content: prompt }],
temperature: 0.3,
});
const content = choices[0]?.message?.content;
console.log("=== RAW RESPONSE ===");
console.log(content);
console.log("\n=== LENGTH ===", content?.length);
// Test extractJSON
const trimmed = content.trim();
const codeBlockMatch = trimmed.match(/```(?:json)?\s*([\s\S]*?)```/);
let jsonStr = codeBlockMatch ? codeBlockMatch[1].trim() : trimmed;
console.log("\n=== AFTER CODE BLOCK REMOVAL ===");
console.log("Has code block:", !!codeBlockMatch);
console.log("First 200 chars:", jsonStr.substring(0, 200));
const braceMatch = jsonStr.match(/\{[\s\S]*\}/);
if (braceMatch) {
console.log("\n=== BRACE MATCH ===");
console.log("First 200 chars:", braceMatch[0].substring(0, 200));
try {
const parsed = JSON.parse(braceMatch[0]);
console.log("\n=== PARSED KEYS ===", Object.keys(parsed));
console.log("Has capability:", !!parsed.capability);
console.log("Has devExp:", !!parsed.devExp);
} catch (e) {
console.log("Parse error:", e.message);
}
}
}
main().catch(console.error);