import { createOpenAPIChain } from "langchain/chains";
import { ChatOpenAI } from "langchain/chat_models/openai";
const chatModel = new ChatOpenAI({ modelName: "gpt-4-0613", temperature: 0 });
const chain = await createOpenAPIChain("https://api.speak.com/openapi.yaml", {
llm: chatModel,
headers: {
authorization: "Bearer SOME_TOKEN",
},
});
const result = await chain.run(`How would you say no thanks in Russian?`);
console.log(JSON.stringify(result, null, 2));
/*
{
"explanation": "\\nНет, спасибо.\\n\\n\\n\\n1. \\"Нет, не надо\\" *(Neutral/Formal - a polite way to decline something)*\\n2. \\"Ни в коем случае\\" *(Strongly informal - used when you want to emphasize that you absolutely do not want something)*\\n3. \\"Нет, благодарю\\" *(Slightly more formal - a polite way to decline something while expressing gratitude)*\\n\\n\\n\\nMike offers Anna some cake, but she doesn't want any.\\n* Mike: \\"Анна, хочешь попробовать мой волшебный торт? Он сделан с любовью и волшебством!\\"\\n* Anna: \\"Спасибо, Майк, но я на диете. Нет, благодарю.\\"\\n* Mike: \\"Ну ладно, больше для меня!\\"\\n\\n\\n*[Report an issue or leave feedback](https://speak.com/chatgpt?rid=bxw1xq87kdua9q5pefkj73ov})*",
"extra_response_instructions": "Use all information in the API response and fully render all Markdown.\\nAlways end your response with a link to report an issue or leave feedback on the plugin."
}
*/