feat: solution for 'Повторный экзамен: Граф с рефлексией и доработкой'
This commit is contained in:
+2
-37
@@ -1,37 +1,2 @@
|
||||
import { OpenAI } from "langchain-openai";
|
||||
import { BaseLLM } from "langchain-core";
|
||||
|
||||
/**
|
||||
* Simple self‑correcting 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';
|
||||
Reference in New Issue
Block a user