|
| 1 | +// ignore_for_file: avoid_print |
| 2 | + |
| 3 | +import 'dart:io'; |
| 4 | +import 'package:llama_cpp_dart/llama_cpp_dart.dart'; |
| 5 | + |
| 6 | +String prompt = """ |
| 7 | +in the object 7, the sentence should end with gender of newborn |
| 8 | +however duo to OCR erros, the gender could be misspelled |
| 9 | +so check the the next field "والد" |
| 10 | +then check whatever the value start with "ه" or "ها" as continued of label |
| 11 | +thefor the label would be "والده" or "والدها" |
| 12 | +print your guess |
| 13 | +then in field 7 you have to print the value with both the mispelled geneder and name of newborn removed and only keep the place name |
| 14 | +"""; |
| 15 | + |
| 16 | +String input = """ |
| 17 | +{ |
| 18 | + "fields": [ |
| 19 | + { |
| 20 | + "id": 1, |
| 21 | + "key": "الصفحة", |
| 22 | + "value": "4" |
| 23 | + }, |
| 24 | + { |
| 25 | + "id": 2, |
| 26 | + "key": "فى يوم", |
| 27 | + "value": "ثالث عشر ربيع الثاني" |
| 28 | + }, |
| 29 | + { |
| 30 | + "id": 3, |
| 31 | + "key": "من سنة", |
| 32 | + "value": "ثلاثة عشر\nواربعمائة والف" |
| 33 | + }, |
| 34 | + { |
| 35 | + "id": 4, |
| 36 | + "key": "(هجرية) موافق", |
| 37 | + "value": "عاشر اكتوبرائن\nوتنفيس نهائة والف" |
| 38 | + }, |
| 39 | + { |
| 40 | + "id": 5, |
| 41 | + "key": "على الساعة", |
| 42 | + "value": "" |
| 43 | + }, |
| 44 | + { |
| 45 | + "id": 6, |
| 46 | + "key": "والدقيقة", |
| 47 | + "value": "" |
| 48 | + }, |
| 49 | + { |
| 50 | + "id": 7, |
| 51 | + "key": "ولد ب", |
| 52 | + "value": "ـ دوار لوطي\nLaicen - لحسن وكر" |
| 53 | + }, |
| 54 | + { |
| 55 | + "id": 8, |
| 56 | + "key": "والد", |
| 57 | + "value": "ه الزموري\nمحمد" |
| 58 | + }, |
| 59 | + { |
| 60 | + "id": 9, |
| 61 | + "key": "الذي اتخذ الاسم العائلى", |
| 62 | + "value": "بند قاق\nBENDAKAK" |
| 63 | + }, |
| 64 | + { |
| 65 | + "id": 10, |
| 66 | + "key": "المغربي الجنسية المولود بـ", |
| 67 | + "value": "جماعة الشر الجديد\nاقليم الجديدة" |
| 68 | + }, |
| 69 | + { |
| 70 | + "id": 11, |
| 71 | + "key": "في", |
| 72 | + "value": "عام ثامن مشى رمضان ست وثمانين وثلاثمائة\nوالف -" |
| 73 | + }, |
| 74 | + { |
| 75 | + "id": 12, |
| 76 | + "key": "موافق", |
| 77 | + "value": "عشرين د جنى سبعة\nويتين تمائة والف" |
| 78 | + }, |
| 79 | + { |
| 80 | + "id": 13, |
| 81 | + "key": "حرفته", |
| 82 | + "value": "عامل نك حبي" |
| 83 | + }, |
| 84 | + { |
| 85 | + "id": 14, |
| 86 | + "key": "ووالدته", |
| 87 | + "value": "مريم بنت محمد" |
| 88 | + }, |
| 89 | + { |
| 90 | + "id": 15, |
| 91 | + "key": "جنسيتها", |
| 92 | + "value": "مغر بم" |
| 93 | + }, |
| 94 | + { |
| 95 | + "id": 16, |
| 96 | + "key": "ولدت بـ", |
| 97 | + "value": "جماعة\nالشر الجدية - اقليم الجد بدة" |
| 98 | + }, |
| 99 | + { |
| 100 | + "id": 17, |
| 101 | + "key": "في", |
| 102 | + "value": "عام تابع على" |
| 103 | + }, |
| 104 | + { |
| 105 | + "id": 18, |
| 106 | + "key": "موافق", |
| 107 | + "value": "ثامناً من يونية تسعة وستين\nربيع الأول عمان وثمانين وثل امانت و\nتسعمائة والا" |
| 108 | + }, |
| 109 | + { |
| 110 | + "id": 19, |
| 111 | + "key": "حرفتها", |
| 112 | + "value": "ربة بيت" |
| 113 | + }, |
| 114 | + { |
| 115 | + "id": 20, |
| 116 | + "key": "الساكنان بـ", |
| 117 | + "value": "دوار لوطى لعديرة" |
| 118 | + }, |
| 119 | + { |
| 120 | + "id": 21, |
| 121 | + "key": "وحرر في يوم", |
| 122 | + "value": "ثاني جمادى الاولى ثلاثة عشر واربعمائة\nوالف" |
| 123 | + }, |
| 124 | + { |
| 125 | + "id": 22, |
| 126 | + "key": "(هجرية) موافق", |
| 127 | + "value": "ثامناً وعشرين اكتوبر اتنين وتعين\nتمائة والف" |
| 128 | + }, |
| 129 | + { |
| 130 | + "id": 23, |
| 131 | + "key": "حسبما صرح به السيد", |
| 132 | + "value": "بند تا قان موري\nوالده تحت عدد 07" |
| 133 | + }, |
| 134 | + { |
| 135 | + "id": 24, |
| 136 | + "key": "عمره", |
| 137 | + "value": "خمس وعشريس" |
| 138 | + }, |
| 139 | + { |
| 140 | + "id": 25, |
| 141 | + "key": "سنة الساكن ب", |
| 142 | + "value": "ـ دوار لوطى\nلعد سيرة" |
| 143 | + }, |
| 144 | + { |
| 145 | + "id": 26, |
| 146 | + "key": "الذي بعد الاطلاع عليه أمضاه معنا أو أمضيناه وحدنا نحن", |
| 147 | + "value": "الطاهي رهيب رئيس المجلس\nالقروب بالغدر" |
| 148 | + }, |
| 149 | + { |
| 150 | + "id": 27, |
| 151 | + "key": "ضابط الحالة المدنية", |
| 152 | + "value": "" |
| 153 | + } |
| 154 | + ] |
| 155 | +} |
| 156 | +"""; |
| 157 | + |
| 158 | +void main() async { |
| 159 | + try { |
| 160 | + Llama.libraryPath = "bin/MAC_ARM64/libllama.dylib"; |
| 161 | + // String modelPath = "/Users/adel/Downloads/gemma-3-finetune.Q8_0.gguf"; |
| 162 | + // String modelPath = "/Users/adel/Workspace/gguf/gemma-3-12b-it-q4_0.gguf"; |
| 163 | + String modelPath = "/Users/adel/Workspace/gguf/gemma-3-4b-it-q4_0.gguf"; |
| 164 | + // String modelPath = "/Users/adel/Workspace/gguf/Qwen3-30B-A3B-Q4_K_M.gguf"; |
| 165 | + |
| 166 | + ChatHistory history = ChatHistory() |
| 167 | + ..addMessage(role: Role.user, content: "$prompt\n$input") |
| 168 | + ..addMessage(role: Role.assistant, content: ""); |
| 169 | + |
| 170 | + final modelParams = ModelParams(); |
| 171 | + |
| 172 | + final contextParams = ContextParams() |
| 173 | + ..nPredict = -1 |
| 174 | + ..nBatch = 8192 |
| 175 | + ..nCtx = 8192; |
| 176 | + |
| 177 | + final samplerParams = SamplerParams() |
| 178 | + ..temp = 0.1 |
| 179 | + ..topK = 64 |
| 180 | + ..topP = 0.95 |
| 181 | + ..penaltyRepeat = 1.1; |
| 182 | + |
| 183 | + Llama llama = |
| 184 | + Llama(modelPath, modelParams, contextParams, samplerParams, false); |
| 185 | + |
| 186 | + llama.setPrompt( |
| 187 | + history.exportFormat(ChatFormat.gemini, leaveLastAssistantOpen: true)); |
| 188 | + while (true) { |
| 189 | + var (token, done) = llama.getNext(); |
| 190 | + stdout.write(token); |
| 191 | + if (done) break; |
| 192 | + } |
| 193 | + stdout.write("\n"); |
| 194 | + |
| 195 | + llama.dispose(); |
| 196 | + } catch (e) { |
| 197 | + print("\nError: ${e.toString()}"); |
| 198 | + } |
| 199 | +} |
0 commit comments