77#include " ort_genai.h"
88#include " ort_genai_c.h"
99
10- const size_t kMaxTokens = 64 ;
10+ const size_t kMaxTokens = 200 ;
1111
1212@interface GenAIGenerator () {
1313 std::unique_ptr<OgaModel> model;
@@ -34,7 +34,19 @@ - (void)setModelFolderPath:(NSString*)modelPath {
3434 @synchronized (self) {
3535 self->modelPath = [modelPath copy ];
3636 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+ }
3850 }
3951}
4052
@@ -82,7 +94,6 @@ - (void)generate:(nonnull NSString*)input_user_question {
8294 NSLog (@" Starting token generation loop..." );
8395
8496 startTime = Clock::now ();
85- firstTokenTime = Clock::now ();
8697 generator->AppendTokenSequences (*sequences);
8798 while (!generator->IsDone ()) {
8899 tokenStartTime = Clock::now ();
@@ -142,7 +153,7 @@ - (void)generate:(nonnull NSString*)input_user_question {
142153 // Send error to the UI
143154 NSDictionary * errorInfo = @{@" error" : errorMessage};
144155 dispatch_async (dispatch_get_main_queue (), ^{
145- [[NSNotificationCenter defaultCenter ] postNotificationName: @" TokenGenerationError " object: nil userInfo: errorInfo];
156+ [[NSNotificationCenter defaultCenter ] postNotificationName: @" GenAIError " object: nil userInfo: errorInfo];
146157 });
147158 }
148159}
0 commit comments