How to add prompt here #5647
Unanswered
lakshya29154
asked this question in
Q&A
Replies: 1 comment
-
To resolve the Add the following import statement at the beginning of your script: import { PromptTemplate } from "@langchain/core/prompts"; Here is your updated code with the necessary import: import * as fs from "fs";
import { JsonSpec } from "langchain/tools";
import { createOpenApiAgent, OpenApiToolkit } from "langchain/agents";
import { OpenAI } from "@langchain/openai";
import { config } from "dotenv";
import { getPromptTemplateFromKey } from "langchain/retrievers/hyde";
import { PromptTemplate } from "@langchain/core/prompts"; // Add this import
config();
const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
const prompt = PromptTemplate.fromTemplate("I am given you the documentation, find the relevant API URLs there can be multiple url so give all the url step by step give the response and call you also give method with it.You should build the API URLs in order to get a response that is as short as possible, while still getting the necessary information to answer the question. Pay attention to deliberately exclude any unnecessary pieces of data in the API call.");
async function generateAPIEndpoints(specFilePath) {
let data;
try {
const jsonFile = fs.readFileSync(specFilePath, "utf8");
data = JSON.parse(jsonFile);
if (!data) {
throw new Error("Failed to load OpenAPI spec");
}
} catch (e) {
console.error(e);
return;
}
const headers = {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
};
const model = new OpenAI({ temperature: 0, apiKey: OPENAI_API_KEY });
const toolkit = new OpenApiToolkit(new JsonSpec(data), model, headers, prompt);
const executor = createOpenApiAgent(model, toolkit);
const input = `Generate a list of API endpoints in the correct order to first add a new pet, then find the pet by ID, and finally delete the pet.`;
console.log(`Executing with input "${input}"...`);
const result = await executor.invoke({ input });
console.log(`Got output ${result.output}`);
console.log(
`Got intermediate steps ${JSON.stringify(
result.intermediateSteps,
null,
2
)}`
);
}
const specFilePath = './swagger.json';
generateAPIEndpoints(specFilePath); This should resolve the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Checked other resources
Commit to Help
Example Code
Description
I want to pass the prompt here to find the list of api but facing the problem for the prompt Can you help once
System Info
all good
Beta Was this translation helpful? Give feedback.
All reactions