test-graph.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const { createEvaluationGraph } = require('./server/src/assessment/graph/builder');
  2. const { HumanMessage } = require('@langchain/core/messages');
  3. async function testGraph() {
  4. const graph = createEvaluationGraph();
  5. const config = {
  6. configurable: {
  7. thread_id: "test-session",
  8. model: {
  9. invoke: async (msgs) => {
  10. console.log("Mock Model Invoked with:", msgs[0].content);
  11. if (msgs[0].content.includes("考官")) {
  12. return { content: JSON.stringify({ score: 9, feedback: "Good job", should_follow_up: false }) };
  13. }
  14. if (msgs[0].content.includes("教育顾问")) {
  15. return { content: "LEVEL: Proficient\nThis is a test report." };
  16. }
  17. return { content: JSON.stringify([{ question_text: "Test Question?", key_points: ["A"], difficulty: "Medium", basis: "[1]..." }]) };
  18. }
  19. },
  20. knowledgeBaseContent: "This is test content.",
  21. language: "zh"
  22. }
  23. };
  24. console.log("--- Starting Session ---");
  25. let state = await graph.invoke({ messages: [new HumanMessage("Start")] }, config);
  26. console.log("Interviewer said:", state.messages[state.messages.length - 1].content);
  27. console.log("Questions length:", state.questions.length);
  28. console.log("Current Index:", state.currentQuestionIndex);
  29. console.log("\n--- Submitting Answer ---");
  30. state = await graph.invoke({ messages: [new HumanMessage("My answer")] }, config);
  31. console.log("Interviewer said:", state.messages[state.messages.length - 1].content);
  32. console.log("Current Index:", state.currentQuestionIndex);
  33. console.log("Report:", state.report);
  34. }
  35. // Note: This script needs the environment set up correctly to run.
  36. // Since I can't easily run it with all dependencies, I'll rely on manual analysis first.