Genie Engine

Genie Engine APIs provide a method to instantiate a standalone engine, which later can bounded to a active dialog. This helps in switching engine in an active dialog.

Engine switching can be exercised by using “–allow_engine_switch <ENGINE_TYPE>, <path-to-engine-config>” in genie-t2t-run. After switching the engine, dialog will be queried with given prompt.

Note

Currently engine switching is only supported in multi-engine dialogs, and you can only switch “draft” engines.

Example on how to perform Engine Switching APIs

// Create Dialog Config
GenieDialogConfig_Handle_t dialogConfigHandle   = NULL;
GenieDialogConfig_createFromJson(dialogConfigStr, &dialogConfigHandle);

// Create Dialog
GenieDialog_Handle_t dialogHandle = NULL;
GenieDialog_create(dialogConfigHandle, &dialogHandle);

// Create Engine Config
GenieEngineConfig_Handle_t engineConfigHandle   = NULL;
GenieEngineConfig_createFromJson(engineConfigStr, &engineConfigHandle);

//Create Engine
GenieEngine_Handle_t engineHandle = NULL;
GenieEngine_create(engineConfigHandle, &engineHandle);

//Get old Engine from Dialog, If not called, then the engine will be unloaded when switching occurs.
GenieEngine_Handle_t dialogEngineHandle = NULL;
std::string engineType = "draft";
// Every call to getEngine API will increase the internal reference count of the engine and Engine will only
// be freed once reference count reached zero.
GenieDialog_getEngine(dialogHandle, engineType.c_str(), &dialogEngineHandle);

// Bind Engine Handle to active Dialog
GenieDialog_bindEngine(dialogHandle, engineType.c_str(), engineHandle);

// In case dialog had previous query, need to flush the KV cache also.
GenieDialog_reset(dialogHandle);

// Run Dialog Query API
GenieDialog_query(dialogHandle, promptStr, GenieDialog_SentenceCode_t::GENIE_DIALOG_SENTENCE_COMPLETE, queryCallback);

// Free engine Handle, this will not free engine if ref count is non zero even after the call.
GenieEngine_free(engineHandle);

// Free old Dialog engine, as it is not associated with the dialog anymore.
GenieEngine_free(dialogEngineHandle);

// Free Dialog
GenieDialog_free(dialogHandle);