| 2379 | } |
| 2380 | |
| 2381 | static PyObject* DAGAddModelRun(PyObject *self, PyObject *args, PyObject *kargs) { |
| 2382 | verifyRedisAILoaded(); |
| 2383 | PyDAGRunner *pyDag = (PyDAGRunner *)self; |
| 2384 | if(!_IsDagAPISupported(RedisAI_DAGCreateModelRunOp) || !_IsValidDag(pyDag)) { |
| 2385 | return NULL; |
| 2386 | } |
| 2387 | PyObject* modelName = GearsPyDict_GetItemString(kargs, "name"); |
| 2388 | if (!modelName) { |
| 2389 | PyErr_SetString(GearsError, "Model key name was not given"); |
| 2390 | return NULL; |
| 2391 | } |
| 2392 | if(!PyUnicode_Check(modelName)){ |
| 2393 | PyErr_SetString(GearsError, "Model name argument must be a string"); |
| 2394 | return NULL; |
| 2395 | } |
| 2396 | |
| 2397 | RAI_Error *err; |
| 2398 | RedisAI_InitError(&err); |
| 2399 | const char* modelNameStr = PyUnicode_AsUTF8AndSize(modelName, NULL); |
| 2400 | |
| 2401 | // Create MODELRUN op after bringing model from keyspace (raise an exception if it does not exist) |
| 2402 | RAI_DAGRunOp *modelRunOp = _createModelRunOp(modelNameStr, err); |
| 2403 | if (modelRunOp == NULL) { |
| 2404 | RedisAI_FreeError(err); |
| 2405 | return NULL; |
| 2406 | } |
| 2407 | PyObject *ret = NULL; |
| 2408 | |
| 2409 | // Add to the modelRun op with its inputs and output keys and insert it to the DAG |
| 2410 | PyObject *inputsIter = NULL; |
| 2411 | PyObject *outputsIter = NULL; |
| 2412 | PyObject *modelOutputs = NULL; |
| 2413 | PyObject *modelInputs = GearsPyDict_GetItemString(kargs, "inputs"); |
| 2414 | if (!modelInputs) { |
| 2415 | PyErr_SetString(GearsError, "Must specify model inputs"); |
| 2416 | goto cleanup; |
| 2417 | } |
| 2418 | inputsIter = PyObject_GetIter(modelInputs); |
| 2419 | if (!inputsIter) { |
| 2420 | PyErr_SetString(GearsError, "Model inputs must be iterable"); |
| 2421 | goto cleanup; |
| 2422 | } |
| 2423 | PyObject* input; |
| 2424 | while((input = (PyObject*)PyIter_Next(inputsIter)) != NULL) { |
| 2425 | if(!PyUnicode_Check(input)){ |
| 2426 | PyErr_SetString(GearsError, "Input name must be a string"); |
| 2427 | goto cleanup; |
| 2428 | } |
| 2429 | const char* inputStr = PyUnicode_AsUTF8AndSize(input, NULL); |
| 2430 | RedisAI_DAGRunOpAddInput(modelRunOp, inputStr); |
| 2431 | } |
| 2432 | |
| 2433 | modelOutputs = GearsPyDict_GetItemString(kargs, "outputs"); |
| 2434 | if (!modelOutputs) { |
| 2435 | PyErr_SetString(GearsError, "Must specify model outputs"); |
| 2436 | goto cleanup; |
| 2437 | } |
| 2438 | outputsIter = PyObject_GetIter(modelOutputs); |
nothing calls this directly
no test coverage detected