feat: solution for 'Экзамен: Самокорректирующийся агент'

This commit is contained in:
2026-07-01 14:45:31 +03:00
parent 08e0fee223
commit e97be7f2af
4 changed files with 63 additions and 77 deletions
+24 -14
View File
@@ -1,17 +1,27 @@
import { getResponse } from './agent.js';
const { OpenAI } = require("langchain-openai");
/**
* Entry point for the selfcorrecting agent demo.
*/
export async function main() {
const prompt = 'Hello, world! What is the capital of France?';
const answer = await getResponse(prompt);
console.log('LLM response:', answer);
// Ensure the OpenAI API key is set in the environment
if (!process.env.OPENAI_API_KEY) {
console.error("Error: OPENAI_API_KEY environment variable is not set.");
process.exit(1);
}
if (import.meta.url === `file://${process.argv[1]}`) {
main().catch((err) => {
console.error('Error:', err);
process.exit(1);
});
}
// Instantiate the OpenAI LLM with desired parameters
const llm = new OpenAI({
temperature: 0.7,
modelName: "gpt-3.5-turbo",
});
async function main() {
const prompt = "Hello, world!";
try {
// Invoke the LLM with the prompt
const response = await llm.invoke(prompt);
console.log("Response:", response);
} catch (error) {
console.error("Error invoking LLM:", error);
}
}
main();