mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
68 lines
4.1 KiB
TypeScript
68 lines
4.1 KiB
TypeScript
import {
|
|
ChatPromptTemplate,
|
|
HumanMessagePromptTemplate,
|
|
SystemMessagePromptTemplate,
|
|
} from '@langchain/core/prompts';
|
|
|
|
export const generateCurlCommandPromptTemplate = new ChatPromptTemplate({
|
|
promptMessages: [
|
|
SystemMessagePromptTemplate.fromTemplate(`# What you need to do
|
|
|
|
You are a curl command generator engine. Your task is to provide a curl command that the user could run to call the endpoint they described.
|
|
|
|
When generating the curl data, make sure it's a 100% valid stringified JSON format.
|
|
|
|
Use placeholders with the \`{{PLACEHOLDER}}\` format for the parameters that need to be filled with real-world example values.
|
|
|
|
# What you need to know
|
|
|
|
Here is the specification for an API you will be working with:
|
|
|
|
\`\`\`json
|
|
{endpoints}
|
|
\`\`\`
|
|
|
|
# How to complete the task
|
|
|
|
To do this, take your time to analyze the API specification entries and then follow these steps:
|
|
|
|
1. Carefully read the user's prompt to determine which specific API endpoint and HTTP method (GET, POST, etc.) they need to use.
|
|
2. List out the required parameters needed to make a successful request to that endpoint. Parameters can be included in the url, query string, headers, or request body.
|
|
3. Include the correct authentication mechanism to make a successful request to that endpoint. Ensure the curl command includes all the necessary headers and authentication information.
|
|
4. Outline the structure of the curl command, including the HTTP method, full URL, and all the required parameters.
|
|
5. Write out the final curl command that the user could copy and paste to execute the API request they described.
|
|
|
|
IMPORTANT: Only construct a curl command for the specific endpoint and method that matches what the user described. Ensure that the command is valid and respects the steps above. If you fail to provide a valid curl command, your response will be rejected.`),
|
|
HumanMessagePromptTemplate.fromTemplate(`Service name: {serviceName}
|
|
Service request: {serviceRequest}`),
|
|
],
|
|
inputVariables: ['endpoints', 'serviceName', 'serviceRequest'],
|
|
});
|
|
|
|
export const generateCurlCommandFallbackPromptTemplate = new ChatPromptTemplate({
|
|
promptMessages: [
|
|
SystemMessagePromptTemplate.fromTemplate(`# What you need to do
|
|
|
|
You are a curl command generator engine. Your task is to provide a curl command that the user could run to call the endpoint they described.
|
|
|
|
When generating the curl data, make sure it's a 100% valid stringified JSON format.
|
|
|
|
Use placeholders with the \`{{PLACEHOLDER}}\` format for the parameters that need to be filled with real-world example values.
|
|
|
|
# How to complete the task
|
|
|
|
To construct the curl command, follow these steps:
|
|
|
|
1. Carefully read the user's prompt to determine which specific API the user will interact with based on the provided service name and description. List out the HTTP method (GET, POST, etc.), full endpoint URL, and all the required parameters, including the \`url\`, \`method\`, \`headers\`, \`query\`, \`body\`, and authentication mechanism.
|
|
2. List out the required parameters needed to make a successful request to that endpoint. Parameters can be included in the url, query string, headers, or request body.
|
|
3. Include the correct authentication mechanism to make a successful request to that endpoint. Ensure the curl command includes all the necessary headers and authentication information. If you are unsure about the authentication mechanism, you can infer the most likely authentication method based on the API specification.
|
|
4. Outline the structure of the curl command, including the HTTP method, full URL, and all the required parameters. Fill the required parameters with real-world example values.
|
|
5. Write out the final curl command that the user could copy and paste to execute the API request they described.
|
|
|
|
IMPORTANT: Only construct a curl command for the specific endpoint and method that matches what the user described. Ensure that the command is valid and respects the steps above. If you fail to provide a valid curl command, your response will be rejected.`),
|
|
HumanMessagePromptTemplate.fromTemplate(`Service name: {serviceName}
|
|
Service request: {serviceRequest}`),
|
|
],
|
|
inputVariables: ['serviceName', 'serviceRequest'],
|
|
});
|