Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created February 23, 2024 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/4960d9c217389d85a4458fe0e4c1d488 to your computer and use it in GitHub Desktop.
Save bjoerntx/4960d9c217389d85a4458fe0e4c1d488 to your computer and use it in GitHub Desktop.
string question = "Is contracting with other partners an option?";
//string question = "How will disputes be dealt with?";
//string question = "Can the agreement be changed or modified?";
string pdfPath = "Sample PDFs/SampleContract-Shuttle.pdf";
// load the PDF file
byte[] pdfDocument = File.ReadAllBytes(pdfPath);
// split the PDF document into chunks
var chunks = DocumentProcessing.Chunk(pdfDocument, 2500, 50);
Console.WriteLine($"{chunks.Count.ToString()} chunks generated from: {pdfPath}");
// get the keywords
List<string> generatedKeywords = GPTHelper.GetKeywords(question, 20);
// find the matches
var matches = DocumentProcessing.FindMatches(chunks, generatedKeywords).ToList().First();
// print the matches
Console.WriteLine($"The question: \"{question}\" was found in chunk {matches.Key}.");
// print the answer
Console.WriteLine("\r\n********\r\n" + GPTHelper.GetAnswer(chunks[matches.Key], question));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment