Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/harvester/blob/main/src/export.rs # harvester Zero-telemetry documentation and knowledge extraction engine Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `harvester / src / export.rs` 74 lines ยท 2287 bytes Raw Blame History 1 use serde_json::json; 2 use std::fs::OpenOptions; 3 use std::io::{self, Write}; 4 use std::path::Path; 5 use crate::extractor::ExtractedPair; 6 7 pub struct DatasetExporter; 8 9 impl DatasetExporter { 10 pub fn append_to_jsonl(path: &Path, pairs: &[ExtractedPair]) -> io::Result { 11 let mut file = OpenOptions::new() 12 .create(true) 13 .append(true) 14 .open(path)?; 15 16 let mut written = 0; 17 for pair in pairs { 18 let record = json!({ 19 "instruction": pair.prompt, 20 "reasoning": pair.reasoning, 21 "response": pair.completion, 22 "metadata": { 23 "source_provider": pair.provider, 24 "source_model": pair.model, 25 "tokens": pair.token_count, 26 "quality": pair.quality_score, 27 "license": "SRCL-1.0 (Apache-2.0 WITH LLVM-exception)" 28 } 29 }); 30 writeln!(file, "{}", record)?; 31 written += 1; 32 } 33 Ok(written) 34 } 35 36 pub fn to_sharegpt_format(pair: &ExtractedPair) -> serde_json::Value { 37 let human_text = pair.prompt.clone(); 38 let gpt_text = if let Some(r) = &pair.reasoning { 39 format!("\n{}\n\n\n{}", r, pair.completion) 40 } else { 41 pair.completion.clone() 42 }; 43 44 json!({ 45 "conversations": [ 46 {"from": "human", "value": human_text}, 47 {"from": "gpt", "value": gpt_text} 48 ], 49 "source": pair.provider 50 }) 51 } 52 } 53 54 #[cfg(test)] 55 mod tests { 56 use super::*; 57 58 #[test] 59 fn test_sharegpt_format() { 60 let pair = ExtractedPair { 61 prompt: "Say hi".to_string(), 62 reasoning: Some("Greeting thought".to_string()), 63 completion: "Hello".to_string(), 64 provider: "gemini".to_string(), 65 model: "gemini-2.5-pro".to_string(), 66 token_count: 20, 67 quality_score: 0.9, 68 }; 69 let val = DatasetExporter::to_sharegpt_format(&pair); 70 let convos = val["conversations"].as_array().unwrap(); 71 assert_eq!(convos.len(), 2); 72 assert!(convos[1]["value"].as_str().unwrap().contains("")); 73 } 74 }