Skip to content

Commit

Permalink
chore: extract prompt to file
Browse files Browse the repository at this point in the history
loaded at runtime, so it can be overwritten / customised by users

Signed-off-by: Oliver Lippert <[email protected]>
  • Loading branch information
lippoliv committed Jul 26, 2024
1 parent 7ddf0c4 commit f0135cc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
1 change: 1 addition & 0 deletions .idea/paperlessngx-ollama.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions assets/prompt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
you help me describing a text for my document management system.
you respond a json object with the following fields
- summary: string
- is_invoice: bool
- invoice_number: string
- invoice_amount: float

just write the json object, no surrounding text.

the summary must not be longer than 120 characters.
the summary will be used in a document management system to later find the latter.
the summary must not contain address information.
the summary must not contain the senders name.
the summary must be in {lang} language.

the is_invoice should indicate if the text is an invoice / receipt or not.

invoice_number should be the invoice number / identifier.
invoice_number should be empty if it's not an invoice.

invoice_amount should contain the invoices total amount.
invoice_amount should be empty if it's not an invoice.

for invoices, the summary must be written like this "{invoice_amount} - {invoice_number}"
28 changes: 5 additions & 23 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fs;

use ollama_rs::generation::completion::request::GenerationRequest;
use ollama_rs::generation::options::GenerationOptions;
use ollama_rs::generation::parameters::FormatType;
Expand Down Expand Up @@ -139,29 +141,9 @@ async fn generate_document_summary_via_ollama(
ollama_response_language: String,
) -> String {
let ollama = Ollama::new(ollama_host, ollama_port);
let prompt = format!(
"you help me describing a text for my document management system.
you respond a json object with the following fields
- summary: string
- is_invoice: bool
- invoice_number: string
- invoice_amount: float
just write the json object, no surrounding text.
the summary must not be longer than 120 characters.
the summary will be used in a document management system to later find the latter.
the summary must not contain address information.
the summary must not contain the senders name.
the summary must be in {ollama_response_language} language.
the is_invoice should indicate if the text is an invoice or not.
invoice_number should be empty if it's not an invoice.
invoice_amount should be empty if it's not an invoice.
invoice_amount should contain the invoices total amount.\n\n\n"
);
let prompt = fs::read_to_string("assets/prompt.txt")
.expect("Prompt could be read")
.replace("{lang}", &*ollama_response_language);

let res = ollama
.generate(
Expand Down

0 comments on commit f0135cc

Please sign in to comment.