You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by ar...@apache.org on 2021/07/02 19:30:38 UTC
[incubator-nlpcraft] branch master updated: Fix for NLPCRAFT-355.
This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/master by this push:
new ee0c006 Fix for NLPCRAFT-355.
ee0c006 is described below
commit ee0c006a3af2f57fe35309c25e2d75992af612d2
Author: Aaron Radzinzski <ar...@datalingvo.com>
AuthorDate: Fri Jul 2 12:30:29 2021 -0700
Fix for NLPCRAFT-355.
---
.../nlpcraft/model/tools/cmdline/NCCli.scala | 40 +++++++++++++++++-----
.../model/tools/cmdline/NCCliCommands.scala | 34 ++++++++++++++----
2 files changed, 60 insertions(+), 14 deletions(-)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
index 9053cc5..f8a573e 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
@@ -113,7 +113,8 @@ object NCCli extends NCCliBase {
var serverLog: Option[File] = None,
var probeLog: Option[File] = None,
var probes: List[Probe] = Nil, // List of connected probes.
- var lastArgs: Option[Seq[Argument]] = None
+ var lastStartProbeArgs: Option[Seq[Argument]] = None,
+ var lastTestModelArgs: Option[Seq[Argument]] = None
) {
/**
* Resets server sub-state.
@@ -337,12 +338,12 @@ object NCCli extends NCCliBase {
val tstamp = U.now() - 1000 * 60 * 60 * 24 * 2 // 2 days ago.
val files = new File(SystemUtils.getUserHome, NLPCRAFT_LOC_DIR).listFiles()
-
+
if (files != null)
for (file <- files)
if (file.lastModified() < tstamp) {
val name = file.getName
-
+
if (name.startsWith("server_log") || name.startsWith("server_log") || name.startsWith(".pid_"))
file.delete()
}
@@ -609,6 +610,9 @@ object NCCli extends NCCliBase {
validatorPb.directory(new File(USR_WORK_DIR))
validatorPb.inheritIO()
+ // Capture this mode test arguments (used in restart command).
+ state.lastTestModelArgs = Some(args)
+
logln(s"Validator:")
logln(s" ${y("+--")} cmd: \n ${c(jvmArgs.mkString("\n "))}")
@@ -617,7 +621,10 @@ object NCCli extends NCCliBase {
}
catch {
case _: InterruptedException => () // Ignore.
- case e: Exception => error(s"Failed to run model validator: ${y(e.getLocalizedMessage)}")
+ case e: Exception =>
+ error(s"Failed to run model validator: ${y(e.getLocalizedMessage)}")
+
+ state.lastTestModelArgs = None
}
}
@@ -629,13 +636,13 @@ object NCCli extends NCCliBase {
private [cmdline] def cmdRestartProbe(cmd: Command, args: Seq[Argument], repl: Boolean): Unit = {
if (!repl)
error(s"The ${y("'restart-probe'")} command only works in REPL mode - use ${c("'stop-probe'")} and ${c("'start-probe'")} commands instead.")
- else if (state.lastArgs.isEmpty)
+ else if (state.lastStartProbeArgs.isEmpty)
error(s"Probe has not been previously started - see ${c("'start-probe'")} command.")
else {
if (loadProbeBeacon().isDefined)
cmdStopProbe(CMDS.find(_.name == "stop-probe").get, Seq.empty[Argument], repl)
- cmdStartProbe(CMDS.find(_.name == "start-probe").get, state.lastArgs.get, repl)
+ cmdStartProbe(CMDS.find(_.name == "start-probe").get, state.lastStartProbeArgs.get, repl)
}
}
@@ -644,6 +651,20 @@ object NCCli extends NCCliBase {
* @param args Arguments, if any, for this command.
* @param repl Whether or not running from REPL.
*/
+ private [cmdline] def cmdRetestModel(cmd: Command, args: Seq[Argument], repl: Boolean): Unit = {
+ if (!repl)
+ error(s"The ${y("'retest-model'")} command only works in REPL mode - use ${c("'test-model'")} commands instead.")
+ else if (state.lastTestModelArgs.isEmpty)
+ error(s"Model has not been previously tested - see ${c("'test-model'")} command.")
+ else
+ cmdTestModel(CMDS.find(_.name == "test-model").get, state.lastTestModelArgs.get, repl)
+ }
+
+ /**
+ * @param cmd Command descriptor.
+ * @param args Arguments, if any, for this command.
+ * @param repl Whether or not running from REPL.
+ */
private [cmdline] def cmdStartProbe(cmd: Command, args: Seq[Argument], repl: Boolean): Unit = {
// Ensure that there is a local server running since probe
// cannot finish its start unless there's a server to connect to.
@@ -836,14 +857,17 @@ object NCCli extends NCCliBase {
logConnectedProbes()
// Capture this probe start arguments (used in restart command).
- state.lastArgs = Some(args)
+ state.lastStartProbeArgs = Some(args)
showTip()
}
}
}
catch {
- case e: Exception => error(s"Probe failed to start: ${y(e.getLocalizedMessage)}")
+ case e: Exception =>
+ error(s"Probe failed to start: ${y(e.getLocalizedMessage)}")
+
+ state.lastStartProbeArgs = None
}
}
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliCommands.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliCommands.scala
index b465ab5..991fae2 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliCommands.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliCommands.scala
@@ -740,7 +740,7 @@ private [cmdline] object NCCliCommands {
fsPath = true,
desc =
s"Additional JVM classpath that will be appended to the default NLPCraft JVM classpath. " +
- s"When starting a probe with your own models you must " +
+ s"When starting a probe with your models you must " +
s"provide this additional classpath for the models and their dependencies this probe will be hosting. " +
s"Note that you can use ${y("'~'")} at the beginning of the classpath component to specify user home directory."
),
@@ -836,7 +836,7 @@ private [cmdline] object NCCliCommands {
group = "3. Miscellaneous",
synopsis = s"Runs ${y("'NCTestAutoModelValidator'")} model auto-validator.",
desc = Some(
- s"Validation consists " +
+ s"Auto-validation consists " +
s"of starting an embedded probe, scanning all deployed models for ${y("'NCIntentSample'")} annotations and their corresponding " +
s"callback methods, submitting each sample input sentences from ${y("'NCIntentSample'")} annotation and " +
s"checking that resulting intent matches the intent the sample was attached to. " +
@@ -851,10 +851,8 @@ private [cmdline] object NCCliCommands {
fsPath = true,
desc =
s"Additional JVM classpath that will be appended to the default NLPCraft JVM classpath. " +
- s"Although this configuration property is optional, when testing your own models you must " +
- s"provide this additional classpath for the models and their dependencies. " +
- s"Note that this is only optional if you are testing example models shipped with NLPCraft. " +
- s"Note also that you can use ${y("'~'")} at the beginning of the classpath component to specify user home directory."
+ s"When testing your models you must provide this additional classpath for the models and their dependencies. " +
+ s"Note that you can use ${y("'~'")} at the beginning of the classpath component to specify user home directory."
),
Parameter(
id = "config",
@@ -902,6 +900,30 @@ private [cmdline] object NCCliCommands {
)
),
Command(
+ name = "retest-model",
+ group = "3. Miscellaneous",
+ synopsis = s"Re-runs ${y("'NCTestAutoModelValidator'")} model auto-validator (REPL mode only).",
+ desc = Some(
+ s"Re-runs mode auto-validator with the same parameters as the last run. Works only in REPL mode. " +
+ s"Auto-validation consists " +
+ s"of starting an embedded probe, scanning all deployed models for ${y("'NCIntentSample'")} annotations and their corresponding " +
+ s"callback methods, submitting each sample input sentences from ${y("'NCIntentSample'")} annotation and " +
+ s"checking that resulting intent matches the intent the sample was attached to. " +
+ s"See more details at https://nlpcraft.apache.org/tools/test_framework.html"
+ ),
+ body = NCCli.cmdRetestModel,
+ params = Seq(),
+ examples = Seq(
+ Example(
+ usage = Seq(
+ s"> retest-model"
+ ),
+ desc =
+ s"Re-runs model auto-validator with the same parameters as the last run."
+ )
+ )
+ ),
+ Command(
name = "info-server",
group = "1. Server & Probe Commands",
synopsis = s"Info about local server.",