feat: solution for 'Повторный экзамен: Граф с рефлексией и доработкой'

This commit is contained in:
2026-07-01 15:50:16 +03:00
parent e756e363b2
commit 6be5a5c753
7 changed files with 279 additions and 262 deletions
+2 -37
View File
@@ -1,37 +1,2 @@
import { OpenAI } from "langchain-openai";
import { BaseLLM } from "langchain-core";
/**
* Simple selfcorrecting agent demo.
* Requires an OpenAI API key set in the environment variable OPENAI_API_KEY.
*/
async function main() {
// Ensure the API key is available
if (!process.env.OPENAI_API_KEY) {
console.error("Error: OPENAI_API_KEY environment variable is not set.");
process.exit(1);
}
// Instantiate the OpenAI LLM provider
const llm = new OpenAI({
temperature: 0.7,
// The API key is automatically read from the environment variable
});
// Verify that llm is an instance of BaseLLM (from langchain-core)
if (!(llm instanceof BaseLLM)) {
console.error("Error: The LLM instance is not a BaseLLM.");
process.exit(1);
}
// Send a simple prompt to the LLM
const prompt = "Hello, world! What is the capital of France?";
try {
const response = await llm.invoke(prompt);
console.log("LLM response:", response);
} catch (error) {
console.error("Error invoking LLM:", error);
}
}
main();
export { Graph } from './graph.js';
export { Node, ReflectionNode, RewritingNode } from './nodes.js';