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/06/25 23:20:40 UTC

[incubator-nlpcraft] branch NLPCRAFT-344 updated (373a44d -> fb3a281)

This is an automated email from the ASF dual-hosted git repository.

aradzinski pushed a change to branch NLPCRAFT-344
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git.


    from 373a44d  Merge branch 'master' into NLPCRAFT-344
     new 208c4ae  Update NCCliCommands.scala
     new ad7fea7  WIP.
     new fb3a281  WIP.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/nlpcraft/common/util/NCUtils.scala  |  2 +-
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 24 ++++++++++++++++---
 .../nlpcraft/model/tools/cmdline/NCCliBase.scala   |  1 +
 .../model/tools/cmdline/NCCliCommands.scala        | 28 +++++++++++++++++++---
 4 files changed, 48 insertions(+), 7 deletions(-)

[incubator-nlpcraft] 02/03: WIP.

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aradzinski pushed a commit to branch NLPCRAFT-344
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git

commit ad7fea7cbb242993da3ee0cae2e5436c4f097c82
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Fri Jun 25 15:57:09 2021 -0700

    WIP.
---
 .../scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala  |  9 ++++++++-
 .../org/apache/nlpcraft/model/tools/cmdline/NCCliBase.scala    |  1 +
 .../apache/nlpcraft/model/tools/cmdline/NCCliCommands.scala    | 10 +++++-----
 3 files changed, 14 insertions(+), 6 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 2676651..e7893db 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
@@ -1719,7 +1719,14 @@ object NCCli extends NCCliBase {
     private [cmdline] def cmdAsk(cmd: Command, args: Seq[Argument], repl: Boolean): Unit =
         state.accessToken match {
             case Some(acsTok) =>
-                val mdlId = getParam(cmd, args, "mdlId")
+                val mdlId = getParamOpt(cmd, args, "mdlId") match {
+                    case Some(id) => id
+                    case None =>
+                        if (state.probes.size == 1 && state.probes.head.models.length == 1)
+                            state.probes.head.models.head.id
+                        else
+                            throw MissingOptionalParameter(cmd, "mdlId")
+                }
                 val txt = getParam(cmd, args, "txt")
                 val data = getParamOrNull(cmd, args, "data")
                 val enableLog = getFlagParam(cmd, args, "enableLog", dflt = false)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliBase.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliBase.scala
index 9a19e3e..bde8ddd 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliBase.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliBase.scala
@@ -141,6 +141,7 @@ class NCCliBase extends App {
     case class TooManyArguments(cmd: Command) extends ISE(s"Too many arguments, ${help(cmd)}")
     case class NotEnoughArguments(cmd: Command) extends ISE(s"Not enough arguments, ${help(cmd)}")
     case class MissingParameter(cmd: Command, paramId: String) extends ISE( s"Missing mandatory parameter $C${"'" + cmd.params.find(_.id == paramId).get.names.head + "'"}$RST, ${help(cmd)}")
+    case class MissingOptionalParameter(cmd: Command, paramId: String) extends ISE( s"Missing optional but required in this context parameter $C${"'" + cmd.params.find(_.id == paramId).get.names.head + "'"}$RST, ${help(cmd)}")
     case class MissingMandatoryJsonParameters(cmd: Command, missingParams: Seq[RestSpecParameter], path: String) extends ISE(s"Missing mandatory JSON parameters (${missingParams.map(s => y(s.name)).mkString(",")}) for $C${"'" + cmd.name + s" --path=$path'"}$RST, ${help(cmd)}")
     case class InvalidParameter(cmd: Command, paramId: String) extends ISE(s"Invalid parameter $C${"'" + cmd.params.find(_.id == paramId).get.names.head + "'"}$RST, ${help(cmd)}")
     case class InvalidJsonParameter(cmd: Command, param: String) extends ISE(s"Invalid JSON parameter $C${"'" + param + "'"}$RST, ${help(cmd)}")
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 8235e5b..d78f8ab 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
@@ -299,9 +299,9 @@ private [cmdline] object NCCliCommands {
                     value = Some("model.id"),
                     optional = true,
                     desc =
-                        s"ID of the data model to send the request to. Note that this is optional ONLY if the connected " +
-                        s"probe has only one model deployed - which will be used by default. If the probe has more " +
-                        s"than one model deployed - this parameter is mandatory." +
+                        s"ID of the data model to send the request to. Note that this is optional ONLY if there is only one " +
+                        s"connected probe and it has only one model deployed - which will be used by default. In all other " +
+                        s"cases - this parameter is mandatory." +
                         s"In REPL mode, hit ${rv(" Tab ")} to see auto-suggestion for possible model IDs."
                 ),
                 Parameter(
@@ -563,8 +563,8 @@ private [cmdline] object NCCliCommands {
                     desc =
                         s"ID of the model to run synonym suggestion on. " +
                         s"In REPL mode, hit ${rv(" Tab ")} to see auto-suggestion for possible model IDs. Note that " +
-                        s"this is optional ONLY if the connected probe has only one model deployed - which will be " +
-                        s"used by default. If the probe has more than one model deployed - this parameter is mandatory." 
+                        s"this is optional ONLY if there is only one connected probe and it has only one model deployed - which will be " +
+                        s"used by default. In all other cases - this parameter is mandatory."
                 ),
                 Parameter(
                     id = "minScore",

[incubator-nlpcraft] 03/03: WIP.

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aradzinski pushed a commit to branch NLPCRAFT-344
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git

commit fb3a28108cddd79f6e6e48f589c4e174d1641fe8
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Fri Jun 25 16:20:32 2021 -0700

    WIP.
---
 .../org/apache/nlpcraft/common/util/NCUtils.scala    |  2 +-
 .../apache/nlpcraft/model/tools/cmdline/NCCli.scala  | 15 +++++++++++++--
 .../nlpcraft/model/tools/cmdline/NCCliCommands.scala | 20 ++++++++++++++++++--
 3 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
index dcf9feb..20f90f6 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
@@ -147,7 +147,7 @@ object NCUtils extends LazyLogging {
     def nowUtcTs(): Timestamp = new Timestamp(Instant.now().toEpochMilli)
 
     /**
-     * Shortcut.
+     * Shortcut - current timestamp in milliseconds.
      */
     def now(): Long = System.currentTimeMillis()
 
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 e7893db..1551af1 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
@@ -1692,7 +1692,14 @@ object NCCli extends NCCliBase {
     private [cmdline] def cmdSugSyn(cmd: Command, args: Seq[Argument], repl: Boolean): Unit =
         state.accessToken match {
             case Some(acsTok) =>
-                val mdlId = getParam(cmd, args, "mdlId")
+                val mdlId = getParamOpt(cmd, args, "mdlId") match {
+                    case Some(id) => id
+                    case None =>
+                        if (state.probes.size == 1 && state.probes.head.models.length == 1)
+                            state.probes.head.models.head.id
+                        else
+                            throw MissingOptionalParameter(cmd, "mdlId")
+                }
                 val minScore = getDoubleParam(cmd, args, "minScore", 0.5)
 
                 httpRest(
@@ -2211,6 +2218,8 @@ object NCCli extends NCCliBase {
 
         spinner.start()
 
+        val start = U.now()
+
         // Make the REST call.
         val resp =
             try
@@ -2218,8 +2227,10 @@ object NCCli extends NCCliBase {
             finally
                 spinner.stop()
 
+        val durMs = U.now() - start
+
         // Ack HTTP response code.
-        logln(s"HTTP ${if (resp.code == 200) g("200") else r(resp.code)}")
+        logln(s"HTTP ${if (resp.code == 200) g("200") else r(resp.code)} [${durMs}ms]")
 
         if (U.isValidJson(resp.data))
             logln(U.colorJson(U.prettyJson(resp.data)))
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 d78f8ab..02b292d 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
@@ -328,12 +328,20 @@ private [cmdline] object NCCliCommands {
             examples = Seq(
                 Example(
                     usage = Seq(
-                        s"""> ask --txt="User request" --mdlId=my.model.id""",
-                        s"""> ask --txt="User text""""
+                        s"""> ask --txt="User request" --mdlId=my.model.id"""
                     ),
                     desc =
                         s"Issues ${y("'ask/sync'")} REST call with given text and model ID."
+                ),
+                Example(
+                    usage = Seq(
+                        s"""> ask --txt="User text""""
+                    ),
+                    desc =
+                        s"Issues ${y("'ask/sync'")} REST call with given text and default model ID " +
+                        s"(single connected probe that has a single model deployed)."
                 )
+
             )
         ),
         Command(
@@ -581,6 +589,14 @@ private [cmdline] object NCCliCommands {
                     ),
                     desc =
                         s"Issues ${y("'model/sugsyn'")} REST call with default min score and given model ID."
+                ),
+                Example(
+                    usage = Seq(
+                        s"""> sugsyn"""
+                    ),
+                    desc =
+                        s"Issues ${y("'model/sugsyn'")} REST call with default min score and default model ID " +
+                        s"(single connected probe that has a single deployed model)."
                 )
             )
         ),

[incubator-nlpcraft] 01/03: Update NCCliCommands.scala

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aradzinski pushed a commit to branch NLPCRAFT-344
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git

commit 208c4ae81d78c767aba91600cf92eb4fc2b50404
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Fri Jun 25 15:49:07 2021 -0700

    Update NCCliCommands.scala
---
 .../nlpcraft/model/tools/cmdline/NCCliCommands.scala       | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

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 e0760d8..8235e5b 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
@@ -297,8 +297,11 @@ private [cmdline] object NCCliCommands {
                     id = "mdlId",
                     names = Seq("--mdlId", "-m"),
                     value = Some("model.id"),
+                    optional = true,
                     desc =
-                        s"ID of the data model to send the request to. " +
+                        s"ID of the data model to send the request to. Note that this is optional ONLY if the connected " +
+                        s"probe has only one model deployed - which will be used by default. If the probe has more " +
+                        s"than one model deployed - this parameter is mandatory." +
                         s"In REPL mode, hit ${rv(" Tab ")} to see auto-suggestion for possible model IDs."
                 ),
                 Parameter(
@@ -325,7 +328,8 @@ private [cmdline] object NCCliCommands {
             examples = Seq(
                 Example(
                     usage = Seq(
-                        s"""> ask --txt="User request" --mdlId=my.model.id"""
+                        s"""> ask --txt="User request" --mdlId=my.model.id""",
+                        s"""> ask --txt="User text""""
                     ),
                     desc =
                         s"Issues ${y("'ask/sync'")} REST call with given text and model ID."
@@ -555,10 +559,12 @@ private [cmdline] object NCCliCommands {
                     id = "mdlId",
                     names = Seq("--mdlId", "-m"),
                     value = Some("model.id"),
+                    optional = true,
                     desc =
                         s"ID of the model to run synonym suggestion on. " +
-                        s"In REPL mode, hit ${rv(" Tab ")} to see auto-suggestion for possible model IDs. " +
-                        s"Note that the probe hosting this model must be connected to the server."
+                        s"In REPL mode, hit ${rv(" Tab ")} to see auto-suggestion for possible model IDs. Note that " +
+                        s"this is optional ONLY if the connected probe has only one model deployed - which will be " +
+                        s"used by default. If the probe has more than one model deployed - this parameter is mandatory." 
                 ),
                 Parameter(
                     id = "minScore",