@cognigy/rest-api-client
Version:
Cognigy REST-Client
55 lines (52 loc) • 2.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLLMEntityExtractSystemMessage = exports.getLLMEntityExtractPrompt = void 0;
/**
* Helper function for the LLM Entity Extract functionality
* @param entityName Name of the entity to extract
* @param entityDescription Description of the entity to extract
* @param examples Examples of the entity to extract
* @param text The text to extract the entity from
* @returns The prompt for the LLM Entity Extract functionality
*/
const getLLMEntityExtractPrompt = (entityName, entityDescription, examples, text) => {
let formattedExamples = "";
examples && Object.keys(examples).forEach((key) => {
formattedExamples += `- "${key}" - { "${entityName}": "` + examples[key] + `" }\n`;
});
// add one negative example to formattedExamples
formattedExamples += `- "sdf sdf sdf" - { "${entityName}": null }\n`;
const prompt = `Your task is to parse an unstructured text and return a valid JSON with an extracted entity.
The entity you're to extract is ${entityName} - ${entityDescription}.
If you can't find a ${entityName}, return { "${entityName}": null }.
Examples:
${formattedExamples}
The given text is: "${text}"
Answer: {"${entityName}":`;
return prompt;
};
exports.getLLMEntityExtractPrompt = getLLMEntityExtractPrompt;
/**
* Helper function for the LLM Entity Extract functionality
* @param entityName Name of the entity to extract
* @param entityDescription Description of the entity to extract
* @param examples Examples of the entity to extract
* @returns The system instrctions for the LLM Entity Extract functionality when using chat models
*/
const getLLMEntityExtractSystemMessage = (entityName, entityDescription, examples) => {
let formattedExamples = "";
examples && Object.keys(examples).forEach((key) => {
formattedExamples += `- "${key}" - { "${entityName}": "` + examples[key] + `" }\n`;
});
// add one negative example to formattedExamples
formattedExamples += `- "sdf sdf sdf" - { "${entityName}": null }\n`;
const prompt = `Your task is to parse an unstructured text and return a valid JSON with an extracted entity.
The entity you're to extract is ${entityName} - ${entityDescription}.
If you can't find a ${entityName}, return { "${entityName}": null }.
Examples:
${formattedExamples}
Answer: {"${entityName}":`;
return prompt;
};
exports.getLLMEntityExtractSystemMessage = getLLMEntityExtractSystemMessage;
//# sourceMappingURL=generativeAIPrompts.js.map