7
7
#include " ort_genai.h"
8
8
#include " ort_genai_c.h"
9
9
10
- const size_t kMaxTokens = 64 ;
10
+ const size_t kMaxTokens = 200 ;
11
11
12
12
@interface GenAIGenerator () {
13
13
std::unique_ptr<OgaModel> model;
@@ -34,7 +34,19 @@ - (void)setModelFolderPath:(NSString*)modelPath {
34
34
@synchronized (self) {
35
35
self->modelPath = [modelPath copy ];
36
36
NSLog (@" Model folder path set to: %@ " , modelPath);
37
- [self loadModelFromPath ];
37
+
38
+ try {
39
+ [self loadModelFromPath ];
40
+ } catch (const std::exception & e) {
41
+ NSString * errorMessage = [NSString stringWithUTF8String: e.what ()];
42
+ NSLog (@" Error loading model: %@ " , errorMessage);
43
+
44
+ // Notify the UI about the error
45
+ NSDictionary * errorInfo = @{@" error" : errorMessage};
46
+ dispatch_async (dispatch_get_main_queue (), ^{
47
+ [[NSNotificationCenter defaultCenter ] postNotificationName: @" GenAIError" object: nil userInfo: errorInfo];
48
+ });
49
+ }
38
50
}
39
51
}
40
52
@@ -82,7 +94,6 @@ - (void)generate:(nonnull NSString*)input_user_question {
82
94
NSLog (@" Starting token generation loop..." );
83
95
84
96
startTime = Clock::now ();
85
- firstTokenTime = Clock::now ();
86
97
generator->AppendTokenSequences (*sequences);
87
98
while (!generator->IsDone ()) {
88
99
tokenStartTime = Clock::now ();
@@ -142,7 +153,7 @@ - (void)generate:(nonnull NSString*)input_user_question {
142
153
// Send error to the UI
143
154
NSDictionary * errorInfo = @{@" error" : errorMessage};
144
155
dispatch_async (dispatch_get_main_queue (), ^{
145
- [[NSNotificationCenter defaultCenter ] postNotificationName: @" TokenGenerationError " object: nil userInfo: errorInfo];
156
+ [[NSNotificationCenter defaultCenter ] postNotificationName: @" GenAIError " object: nil userInfo: errorInfo];
146
157
});
147
158
}
148
159
}
0 commit comments