Skip to content

Instantly share code, notes, and snippets.

@yourbuddyconner
Created February 17, 2023 00:16
Show Gist options
  • Save yourbuddyconner/76f9b71f746f43dfe0713d1d8bdd75ee to your computer and use it in GitHub Desktop.
Save yourbuddyconner/76f9b71f746f43dfe0713d1d8bdd75ee to your computer and use it in GitHub Desktop.
// Define a function to handle the document and return its type
function discoverDocumentType(document) {
// Code to discover the type of document
return documentType;
}
// Define a function to retrieve pre-built question examples from a database
function getQuestionExamples(documentType) {
if (documentType === "legal contract") {
return [
{ input: "What is the purpose of this contract?", response: "The purpose of this contract is to outline the terms of the agreement between the parties." },
{ input: "What is the term of the contract?", response: "The term of the contract is [insert term here]." },
{ input: "What are the payment terms?", response: "The payment terms are [insert payment terms here]." },
{ input: "What happens if one party breaches the contract?", response: "If one party breaches the contract, the other party may seek legal remedies." }
];
}
return questionExamples;
}
// Define a function to build a ChatEngine prompt using the question examples
function buildChatEnginePrompt(questionExamples) {
const description = "A conversation about " + documentType;
const examples = questionExamples;
const chatEngineConfig = {
user: "User",
bot: "Bot"
};
const chatEngine = new ChatEngine(description, examples, "", chatEngineConfig);
return chatEngine;
}
// Use the functions to create a prompt pipeline for a given document
const document = "The quick brown fox jumps over the lazy dog.";
const documentType = discoverDocumentType(document);
const questionExamples = getQuestionExamples(documentType);
const chatEnginePrompt = buildChatEnginePrompt(questionExamples);
// Use the ChatEngine prompt to ask questions and extract pertinent facts from the document
let prompt = chatEnginePrompt.buildPrompt("What is the main subject of the document?");
// Pass the prompt to a large language model (e.g. GPT-3) to get an answer
let answer = prompt.answer;
// Continue the dialog by adding the user query and the model's answer to the ChatEngine
chatEnginePrompt.addInteraction("What is the main subject of the document?", answer);
// Ask more questions and extract more facts as needed
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment