Add error handling for the predictor

This commit is contained in:
2026-03-05 20:14:51 -08:00
parent 308076bfa6
commit 405872da39
2 changed files with 22 additions and 7 deletions
+11 -6
View File
@@ -35,13 +35,18 @@ namespace PythonInterop {
}
}
public int PredictAI(string StockSymbol) {
using (Py.GIL()) {
dynamic predictor = Py.Import("ai-predictor");
using (dynamic x = predictor.Predict(StockSymbol)) {
int result = (int)x;
return result;
// Return ( Error, Signal )
public (string, int) PredictAI(string StockSymbol) {
try {
using (Py.GIL()) {
dynamic predictor = Py.Import("ai-predictor");
using (dynamic x = predictor.Predict(StockSymbol)) {
int result = (int)x;
return ("", result);
}
}
} catch (Exception ex) {
return (ex.ToString(), 0);
}
}