Bottleneck Mass grave update< CAUSE IM A GOAT with No life please help me i need a life

This commit is contained in:
frostyripper1
2026-05-19 19:20:25 +02:00
parent 38927e16e0
commit fe97362aad
10 changed files with 1631 additions and 488 deletions
+62 -26
View File
@@ -115,8 +115,16 @@ pub async fn import_pdf_directory(
);
}
let (count, completed) =
process_pdf_chunks(pdf_path, &chunks, &mut writer, ollama, model_name, pages_count, prompt_each_chunk).await?;
let (count, completed) = process_pdf_chunks(
pdf_path,
&chunks,
&mut writer,
ollama,
model_name,
pages_count,
prompt_each_chunk,
)
.await?;
total_samples += count;
if !completed {
println!(
@@ -144,7 +152,14 @@ pub async fn import_pdf_path(
prompt_each_chunk: bool,
) -> Result<bool> {
if input_path.is_dir() {
import_pdf_directory(input_path, output_file, ollama, model_name, prompt_each_chunk).await
import_pdf_directory(
input_path,
output_file,
ollama,
model_name,
prompt_each_chunk,
)
.await
} else if input_path.is_file() {
if input_path
.extension()
@@ -175,8 +190,16 @@ pub async fn import_pdf_path(
);
}
let (total_samples, completed) =
process_pdf_chunks(input_path, &chunks, &mut writer, ollama, model_name, pages_count, prompt_each_chunk).await?;
let (total_samples, completed) = process_pdf_chunks(
input_path,
&chunks,
&mut writer,
ollama,
model_name,
pages_count,
prompt_each_chunk,
)
.await?;
writer.flush()?;
println!(
"✅ Wrote {} JSONL sample(s) to {}",
@@ -213,25 +236,35 @@ async fn process_pdf_chunks(
prompt_each_chunk: bool,
) -> Result<(usize, bool)> {
let mut total_samples = 0;
for (index, chunk) in chunks.iter().enumerate() {
let progress = format!("chunk {}/{}", index + 1, chunks.len());
let page_label = if pages_count > 0 {
let current_page = ((index * pages_count) / chunks.len()) + 1;
format!("page {}/{}", current_page, pages_count)
} else {
"page unknown".to_string()
};
println!(" ➜ Processing {} ({})", progress, page_label);
let batch_size: usize = 3;
for batch_start in (0..chunks.len()).step_by(batch_size) {
let batch_end = std::cmp::min(batch_start + batch_size, chunks.len());
let batch = &chunks[batch_start..batch_end];
for (offset, _chunk) in batch.iter().enumerate() {
let index = batch_start + offset;
let progress = format!("chunk {}/{}", index + 1, chunks.len());
let page_label = if pages_count > 0 {
let current_page = ((index * pages_count) / chunks.len()) + 1;
format!("page {}/{}", current_page, pages_count)
} else {
"page unknown".to_string()
};
println!(" ➜ Processing {} ({})", progress, page_label);
}
let owned_chunks: Vec<String> = batch.to_vec();
let samples =
derive_samples_from_pdf_text(pdf_path, &[chunk.clone()], ollama, model_name).await?;
for sample in samples {
derive_samples_from_pdf_text(pdf_path, owned_chunks, ollama, model_name).await?;
for sample in &samples {
let line = serde_json::to_string(&sample)?;
writeln!(writer, "{}", line)?;
total_samples += 1;
}
if index + 1 < chunks.len() && prompt_each_chunk {
if !prompt_continue()? {
if batch_end < chunks.len() && prompt_each_chunk {
if !prompt_continue().await? {
println!("⚠️ Stopped early. Partial output written to disk.");
return Ok((total_samples, false));
}
@@ -245,13 +278,16 @@ fn count_pdf_pages(pdf_path: &Path) -> Result<usize> {
Ok(doc.get_pages().len())
}
fn prompt_continue() -> Result<bool> {
print!("Press Enter to continue to the next chunk, or type 'quit' to stop: ");
let stdout = io::stdout();
let mut handle = stdout.lock();
handle.flush()?;
async fn prompt_continue() -> Result<bool> {
tokio::task::spawn_blocking(|| {
print!("Press Enter to continue to the next chunk, or type 'quit' to stop: ");
let stdout = io::stdout();
let mut handle = stdout.lock();
handle.flush()?;
let mut input = String::new();
io::stdin().read_line(&mut input)?;
Ok(!input.trim().eq_ignore_ascii_case("quit"))
let mut input = String::new();
io::stdin().read_line(&mut input)?;
Ok(!input.trim().eq_ignore_ascii_case("quit"))
})
.await?
}