Skip to content

Commit 301637b

Browse files
committed
PWD
1 parent bd20db2 commit 301637b

File tree

3 files changed

+289
-0
lines changed

3 files changed

+289
-0
lines changed

example/apple_pie.r1.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// ignore_for_file: avoid_print
2+
3+
import 'dart:io';
4+
5+
import 'package:llama_cpp_dart/llama_cpp_dart.dart';
6+
7+
void main() async {
8+
try {
9+
ContextParams contextParams = ContextParams();
10+
contextParams.nPredict = 512 * 12;
11+
contextParams.nCtx = 512 * 12;
12+
contextParams.nBatch = 512 * 12;
13+
14+
final samplerParams = SamplerParams();
15+
samplerParams.temp = 0.6;
16+
samplerParams.minP = 0;
17+
samplerParams.topK = 20;
18+
samplerParams.topP = 0.95;
19+
// samplerParams.penaltyRepeat = 1.1;
20+
21+
Llama.libraryPath = "bin/MAC_ARM64/libllama.dylib";
22+
String modelPath =
23+
"/Users/adel/Workspace/gguf/DeepSeek-R1-0528-Qwen3-8B-Q4_K_M.gguf";
24+
Llama llama =
25+
Llama(modelPath, ModelParams(), contextParams, samplerParams, true);
26+
27+
ChatHistory history = ChatHistory();
28+
history.addMessage(role: Role.user, content: "apple pie recipe?");
29+
history.addMessage(role: Role.assistant, content: "");
30+
31+
llama.setPrompt(history.exportFormat(ChatFormat.chatml));
32+
while (true) {
33+
var (token, done) = llama.getNext();
34+
stdout.write(token);
35+
if (done) break;
36+
}
37+
stdout.write("\n");
38+
39+
llama.dispose();
40+
} catch (e) {
41+
print("Error: ${e.toString()}");
42+
}
43+
}

example/arabic_correction.dart

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
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+
}

example/test_finetune.dart

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
"""please correct this sentence by adding spaces between words \n ثمتحريرالمحضرفيمدينةإفني """;
8+
9+
void main() async {
10+
try {
11+
Llama.libraryPath = "bin/MAC_ARM64/libllama.dylib";
12+
// String modelPath = "/Users/adel/Downloads/gemma-3-finetune.Q8_0.gguf";
13+
String modelPath = "/Users/adel/Workspace/gguf/gemma-3-12b-it-q4_0.gguf";
14+
15+
ChatHistory history = ChatHistory()
16+
..addMessage(role: Role.user, content: prompt)
17+
..addMessage(role: Role.assistant, content: "");
18+
19+
final modelParams = ModelParams();
20+
21+
final contextParams = ContextParams()
22+
..nPredict = -1
23+
..nCtx = 8192;
24+
25+
final samplerParams = SamplerParams()
26+
..temp = 0.1
27+
..topK = 64
28+
..topP = 0.95
29+
..penaltyRepeat = 1.1;
30+
31+
Llama llama =
32+
Llama(modelPath, modelParams, contextParams, samplerParams, false);
33+
34+
llama.setPrompt(
35+
history.exportFormat(ChatFormat.gemini, leaveLastAssistantOpen: true));
36+
while (true) {
37+
var (token, done) = llama.getNext();
38+
stdout.write(token);
39+
if (done) break;
40+
}
41+
stdout.write("\n");
42+
43+
llama.dispose();
44+
} catch (e) {
45+
print("\nError: ${e.toString()}");
46+
}
47+
}

0 commit comments

Comments
 (0)