This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-41
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-41 by this push:
new 7c71200 WIP.
7c71200 is described below
commit 7c712008665651e718006a2fef9a3846dc9255a4
Author: Sergey Kamov <[email protected]>
AuthorDate: Mon Aug 31 12:59:26 2020 +0300
WIP.
---
nlpcraft/src/main/resources/nlpcraft.conf | 6 +-
.../nlpcraft/probe/mgrs/cmd/NCCommandManager.scala | 16 ++-
.../nlpcraft/probe/mgrs/model/NCModelManager.scala | 6 +-
.../probe/mgrs/nlp/NCProbeEnrichmentManager.scala | 8 +-
.../inspectors/NCInspectorSuggestions.scala | 150 +++++++++++++--------
.../opencensus/NCOpenCensusServerStats.scala | 1 +
.../nlpcraft/server/probe/NCProbeManager.scala | 16 +--
.../nlpcraft/server/rest/NCBasicRestApi.scala | 88 ++++++++++--
openapi/nlpcraft_swagger.yml | 112 ++++++++++++++-
9 files changed, 308 insertions(+), 95 deletions(-)
diff --git a/nlpcraft/src/main/resources/nlpcraft.conf
b/nlpcraft/src/main/resources/nlpcraft.conf
index 0b0fe7a..1a2c6cb 100644
--- a/nlpcraft/src/main/resources/nlpcraft.conf
+++ b/nlpcraft/src/main/resources/nlpcraft.conf
@@ -206,11 +206,7 @@ nlpcraft {
# spacy.proxy.url=http://localhost:5002
# 'ctxword' module configuration.
- ctxword {
- url="http://localhost:5000"
-
- suggestions.minScore = 0
- }
+ ctxword.url="http://localhost:5000"
}
# +---------------------+
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/cmd/NCCommandManager.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/cmd/NCCommandManager.scala
index bc0cfee..6749a82 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/cmd/NCCommandManager.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/cmd/NCCommandManager.scala
@@ -18,11 +18,13 @@
package org.apache.nlpcraft.probe.mgrs.cmd
import java.io.Serializable
+import java.util.concurrent.{ExecutorService, Executors}
import com.google.gson.Gson
import io.opencensus.trace.Span
import org.apache.nlpcraft.common.NCService
import org.apache.nlpcraft.common.nlp.NCNlpSentence
+import org.apache.nlpcraft.common.util.NCUtils
import org.apache.nlpcraft.model.NCToken
import org.apache.nlpcraft.probe.mgrs.NCProbeMessage
import org.apache.nlpcraft.probe.mgrs.conn.NCConnectionManager
@@ -33,6 +35,7 @@ import org.apache.nlpcraft.probe.mgrs.model.NCModelManager
import org.apache.nlpcraft.probe.mgrs.nlp.NCProbeEnrichmentManager
import scala.collection.JavaConverters._
+import scala.concurrent.{ExecutionContext, ExecutionContextExecutor}
/**
* Probe commands processor.
@@ -40,12 +43,21 @@ import scala.collection.JavaConverters._
object NCCommandManager extends NCService {
private final val GSON = new Gson()
+ @volatile private var pool: ExecutorService = _
+ @volatile private var executor: ExecutionContextExecutor = _
+
override def start(parent: Span = null): NCService =
startScopedSpan("start", parent) { _ ⇒
+ pool = Executors.newCachedThreadPool()
+ executor = ExecutionContext.fromExecutor(pool)
+
super.start()
}
override def stop(parent: Span = null): Unit = startScopedSpan("stop",
parent) { _ ⇒
super.stop()
+
+ NCUtils.shutdownPools(pool)
+ executor = null
}
/**
@@ -108,8 +120,8 @@ object NCCommandManager extends NCService {
),
span
)
-
- }(scala.concurrent.ExecutionContext.Implicits.global)
+ case e: Throwable ⇒ logger.error(s"Message cannot
be processed: $msg", e)
+ }(executor)
case "S2P_MODEL_INFO" ⇒
val res =
NCModelManager.getModelTransferData(msg.data[String]("mdlId"))
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelManager.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelManager.scala
index 1deb26e..337edad 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelManager.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelManager.scala
@@ -18,6 +18,7 @@
package org.apache.nlpcraft.probe.mgrs.model
import java.util
+import java.util.concurrent.{ExecutorService, Executors}
import java.util.regex.{Pattern, PatternSyntaxException}
import io.opencensus.trace.Span
@@ -39,7 +40,9 @@ import scala.collection.convert.DecorateAsScala
import scala.collection.convert.ImplicitConversions._
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
+import scala.concurrent.{ExecutionContext, ExecutionContextExecutor}
import scala.util.control.Exception._
+import scala.concurrent.ExecutionContext.Implicits.global
/**
* Model manager.
@@ -125,7 +128,8 @@ object NCModelManager extends NCService with
DecorateAsScala {
res.suggestions().asScala.foreach(
p ⇒ logger.info(s"Validation suggestion
[model=$mdlId, inspection=$insId, text=$p")
)
- }(scala.concurrent.ExecutionContext.Implicits.global)
+ case e: Throwable ⇒ logger.error(s"Error processing
inspections: $mdlId", e)
+ }
}
addTags(
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
index 5c3b7c1..d8de0bc 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
@@ -66,7 +66,7 @@ object NCProbeEnrichmentManager extends NCService with
NCOpenCensusModelStats {
@volatile private var embeddedCbs: mutable.Set[EMBEDDED_CB] = _
@volatile private var pool: ExecutorService = _
- @volatile private var execCtxExecutor: ExecutionContextExecutor = _
+ @volatile private var executor: ExecutionContextExecutor = _
private object Config extends NCConfigurable {
final private val pre = "nlpcraft.probe"
@@ -84,7 +84,7 @@ object NCProbeEnrichmentManager extends NCService with
NCOpenCensusModelStats {
override def start(parent: Span = null): NCService =
startScopedSpan("start", parent) { _ ⇒
embeddedCbs = mutable.HashSet.empty[EMBEDDED_CB]
pool = Executors.newFixedThreadPool(8 *
Runtime.getRuntime.availableProcessors())
- execCtxExecutor = ExecutionContext.fromExecutor(pool)
+ executor = ExecutionContext.fromExecutor(pool)
super.start()
}
@@ -96,7 +96,7 @@ object NCProbeEnrichmentManager extends NCService with
NCOpenCensusModelStats {
}
U.shutdownPools(pool)
- execCtxExecutor = null
+ executor = null
super.stop()
}
@@ -686,6 +686,6 @@ object NCProbeEnrichmentManager extends NCService with
NCOpenCensusModelStats {
finally
onFinish()
}
- )(execCtxExecutor)
+ )(executor)
}
}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/inspections/inspectors/NCInspectorSuggestions.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/inspections/inspectors/NCInspectorSuggestions.scala
index 28f9580..89973e5 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/inspections/inspectors/NCInspectorSuggestions.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/inspections/inspectors/NCInspectorSuggestions.scala
@@ -19,8 +19,7 @@ package org.apache.nlpcraft.server.inspections.inspectors
import java.util
import java.util.concurrent.atomic.{AtomicInteger, AtomicReference}
-import java.util.concurrent.{ConcurrentHashMap, CopyOnWriteArrayList,
CountDownLatch, TimeUnit}
-import java.util.{List => JList}
+import java.util.concurrent.{ConcurrentHashMap, CopyOnWriteArrayList,
CountDownLatch, ExecutorService, Executors, TimeUnit}
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
@@ -42,34 +41,56 @@ import org.apache.nlpcraft.server.probe.NCProbeManager
import scala.collection.JavaConverters._
import scala.collection.{Seq, mutable}
-import scala.concurrent.{Future, Promise}
+import scala.concurrent.{ExecutionContext, ExecutionContextExecutor, Future,
Promise}
-// TODO:
+// TODO: Possible parameter 'minScore' (double 0 .. 1)
object NCInspectorSuggestions extends NCService with NCInspector {
// For context word server requests.
private final val MAX_LIMIT: Int = 10000
private final val BATCH_SIZE = 20
+ private final val DFLT_MIN_SCORE = 0.0
// For warnings.
private final val MIN_CNT_INTENT = 5
private final val MIN_CNT_MODEL = 20
+ private final val GSON = new Gson
+ private final val TYPE_RESP = new
TypeToken[util.List[util.List[Suggestion]]]() {}.getType
+ private final val TYPE_ARGS = new TypeToken[util.HashMap[String,
AnyRef]]() {}.getType
+ private final val SEPARATORS = Seq('?', ',', '.', '-', '!')
+
private object Config extends NCConfigurable {
val urlOpt: Option[String] =
getStringOpt("nlpcraft.server.ctxword.url")
- val suggestionsMinScore: Int =
getInt("nlpcraft.server.ctxword.suggestions.minScore")
-
- @throws[NCE]
- def check(): Unit =
- if (suggestionsMinScore < 0 || suggestionsMinScore > 1)
- throw new NCE("Invalid
'nlpcraft.server.ctxword.suggestions.minScore' parameter value. It should be
double value between 0 and 1, inclusive")
}
- Config.check()
+ @volatile private var pool: ExecutorService = _
+ @volatile private var executor: ExecutionContextExecutor = _
+
+ private final val HANDLER: ResponseHandler[Seq[Seq[Suggestion]]] =
+ (resp: HttpResponse) ⇒ {
+ val code = resp.getStatusLine.getStatusCode
+ val e = resp.getEntity
+
+ val js = if (e != null) EntityUtils.toString(e) else null
+
+ if (js == null)
+ throw new RuntimeException(s"Unexpected empty response
[code=$code]")
+
+ code match {
+ case 200 ⇒
+ val data: util.List[util.List[Suggestion]] =
GSON.fromJson(js, TYPE_RESP)
+
+ data.asScala.map(p ⇒ if (p.isEmpty) Seq.empty else
p.asScala.tail)
+
+ case 400 ⇒ throw new RuntimeException(js)
+ case _ ⇒ throw new RuntimeException(s"Unexpected response
[code=$code, response=$js]")
+ }
+ }
case class Suggestion(word: String, score: Double)
case class RequestData(sentence: String, example: String, elementId:
String, index: Int)
- case class RestRequestSentence(text: String, indexes: JList[Int])
- case class RestRequest(sentences: JList[RestRequestSentence], limit: Int,
min_score: Double)
+ case class RestRequestSentence(text: String, indexes: util.List[Int])
+ case class RestRequest(sentences: util.List[RestRequestSentence], limit:
Int, min_score: Double)
case class Word(word: String, stem: String) {
require(!word.contains(" "), s"Word cannot contains spaces: $word")
require(
@@ -89,31 +110,6 @@ object NCInspectorSuggestions extends NCService with
NCInspector {
suggestedCount: Int
)
- private final val GSON = new Gson
- private final val TYPE_RESP = new TypeToken[JList[JList[Suggestion]]]()
{}.getType
- private final val SEPARATORS = Seq('?', ',', '.', '-', '!')
-
- private final val HANDLER: ResponseHandler[Seq[Seq[Suggestion]]] =
- (resp: HttpResponse) ⇒ {
- val code = resp.getStatusLine.getStatusCode
- val e = resp.getEntity
-
- val js = if (e != null) EntityUtils.toString(e) else null
-
- if (js == null)
- throw new RuntimeException(s"Unexpected empty response
[code=$code]")
-
- code match {
- case 200 ⇒
- val data: JList[JList[Suggestion]] = GSON.fromJson(js,
TYPE_RESP)
-
- data.asScala.map(p ⇒ if (p.isEmpty) Seq.empty else
p.asScala.tail)
-
- case 400 ⇒ throw new RuntimeException(js)
- case _ ⇒ throw new RuntimeException(s"Unexpected response
[code=$code, response=$js]")
- }
- }
-
private def split(s: String): Seq[String] = s.split("
").toSeq.map(_.trim).filter(_.nonEmpty)
private def toStem(s: String): String =
split(s).map(NCNlpPorterStemmer.stem).mkString(" ")
private def toStemWord(s: String): String = NCNlpPorterStemmer.stem(s)
@@ -144,22 +140,43 @@ object NCInspectorSuggestions extends NCService with
NCInspector {
val promise = Promise[NCInspectionResult]()
NCProbeManager.getModelInfo(mdlId, parent).collect {
- case data ⇒
- println("data=" + data)
- println("args=" + args)
-
+ case m ⇒
try {
- val macrosJ =
data.get("macros").asInstanceOf[util.Map[String, String]]
- val elementsSynonymsJ =
data.get("elementsSynonyms").asInstanceOf[util.Map[String, util.List[String]]]
- val intentsSamplesJ =
data.get("intentsSamples").asInstanceOf[util.Map[String, util.List[String]]]
+ require(
+ m.containsKey("macros") &&
m.containsKey("elementsSynonyms") && m.containsKey("intentsSamples")
+ )
+
+ val macros = m.get("macros").
+ asInstanceOf[util.Map[String, String]].asScala
+ val elementsSynonyms = m.get("elementsSynonyms").
+ asInstanceOf[util.Map[String,
util.List[String]]].asScala.map(p ⇒ p._1 → p._2.asScala)
+ val intentsSamples = m.get("intentsSamples").
+ asInstanceOf[util.Map[String,
util.List[String]]].asScala.map(p ⇒ p._1 → p._2.asScala)
+
+ val minScore =
+ args match {
+ case Some(a) ⇒
+ val v =
+ try {
+ val m: util.Map[String, AnyRef] =
GSON.fromJson(a, TYPE_ARGS)
+
+ val v = m.get("minScore")
+
+ if (v == null)
+ throw new NCE("Missed
parameter: 'minScore'")
+
+ v.asInstanceOf[Double]
+ }
+ catch {
+ case e: Exception ⇒ throw new
NCE("Invalid 'minScore' parameter", e)
+ }
- require(macrosJ != null)
- require(elementsSynonymsJ != null)
- require(intentsSamplesJ != null)
+ if (v < 0 || v > 1)
+ throw new NCE("'minScore' parameter
value must be between 0 and 1")
- val macros = macrosJ.asScala
- val elementsSynonyms = elementsSynonymsJ.asScala.map(p
⇒ p._1 → p._2.asScala)
- val intentsSamples = intentsSamplesJ.asScala.map(p ⇒
p._1 → p._2.asScala)
+ v
+ case None ⇒ DFLT_MIN_SCORE
+ }
def onError(err: String): Unit =
promise.success(
@@ -283,7 +300,7 @@ object NCInspectorSuggestions extends NCService with
NCInspector {
if (allReqsCnt == 0)
onError(s"Suggestions cannot be prepared:
'$mdlId'. Samples don't contain synonyms")
else {
- val allSuggs = new ConcurrentHashMap[String,
JList[Suggestion]]()
+ val allSuggs = new ConcurrentHashMap[String,
util.List[Suggestion]]()
val cdl = new CountDownLatch(1)
val debugs =
mutable.HashMap.empty[RequestData, Seq[Suggestion]]
val cnt = new AtomicInteger(0)
@@ -304,7 +321,7 @@ object NCInspectorSuggestions extends NCService with
NCInspector {
RestRequest(
sentences =
batch.map(p ⇒ RestRequestSentence(p.sentence, Seq(p.index).asJava)).asJava,
// ContextWord
server range is (0, 2), input range is (0, 1)
- min_score =
Config.suggestionsMinScore * 2,
+ min_score =
minScore * 2,
// We set big
limit value and in fact only minimal score is taken into account.
limit = MAX_LIMIT
)
@@ -411,13 +428,14 @@ object NCInspectorSuggestions extends NCService with
NCInspector {
}
})
- val resJ: util.Map[String,
JList[util.HashMap[String, Any]]] =
+ val resJ: util.Map[String,
util.List[util.HashMap[String, Any]]] =
res.map { case (id, data) ⇒
id → data.map(d ⇒ {
val m = new util.HashMap[String,
Any]()
m.put("synonym", d.synonym)
- m.put("ctxWorldServerScore",
d.ctxWorldServerScore)
+ // ContextWord server range is (0,
2)
+ m.put("ctxWorldServerScore",
d.ctxWorldServerScore / 2)
m.put("suggestedCount",
d.suggestedCount)
m
@@ -446,9 +464,29 @@ object NCInspectorSuggestions extends NCService with
NCInspector {
promise.failure(e)
}
+ case e: Throwable ⇒
+ logger.warn(s"Error getting model information: $mdlId", e)
- }(scala.concurrent.ExecutionContext.Implicits.global)
+ promise.failure(e)
+
+ }(executor)
promise.future
}
+
+ override def start(parent: Span): NCService =
+ startScopedSpan("start", parent) { _ ⇒
+ pool = Executors.newCachedThreadPool()
+ executor = ExecutionContext.fromExecutor(pool)
+
+ super.start(parent)
+ }
+
+ override def stop(parent: Span): Unit =
+ startScopedSpan("stop", parent) { _ ⇒
+ super.stop(parent)
+
+ NCUtils.shutdownPools(pool)
+ executor = null
+ }
}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/opencensus/NCOpenCensusServerStats.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/opencensus/NCOpenCensusServerStats.scala
index 9148289..26bb6cd 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/opencensus/NCOpenCensusServerStats.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/opencensus/NCOpenCensusServerStats.scala
@@ -32,6 +32,7 @@ trait NCOpenCensusServerStats {
val M_ASK_LATENCY_MS: MeasureLong = MeasureLong.create("ask_latency", "The
latency of '/ask' REST call", "ms")
val M_CHECK_LATENCY_MS: MeasureLong = MeasureLong.create("check_latency",
"The latency of '/check' REST call", "ms")
val M_MODEL_INSPECT_LATENCY_MS: MeasureLong =
MeasureLong.create("model_inspect_latency", "The latency of '/model/inspect'
REST call", "ms")
+ val M_MODEL_INSPECTIONS_LATENCY_MS: MeasureLong =
MeasureLong.create("model_inspections_latency", "The latency of
'/model/inspections' REST call", "ms")
val M_CANCEL_LATENCY_MS: MeasureLong =
MeasureLong.create("cancel_latency", "The latency of '/cancel' REST call", "ms")
val M_SIGNIN_LATENCY_MS: MeasureLong =
MeasureLong.create("signin_latency", "The latency of '/signin' REST call", "ms")
val M_SIGNOUT_LATENCY_MS: MeasureLong =
MeasureLong.create("signout_latency", "The latency of '/signout' REST call",
"ms")
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
index 0616a4a..f619d7a 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
@@ -985,18 +985,12 @@ object NCProbeManager extends NCService {
*/
def getProbeInspection(mdlId: String, inspId: String, args:
Option[String], parent: Span = null): Future[NCInspectionResult] =
startScopedSpan("inspect", parent, "modelId" → mdlId, "inspId" →
inspId) { _ ⇒
- val m =
- Map(
- "mdlId" → mdlId,
- "inspId" → inspId,
- "args" →
- (args match {
- case Some(a) ⇒ GSON.toJson(a)
- case None ⇒ null
- })
- )
+ val params = mutable.HashMap.empty[String, Serializable] ++
Map("mdlId" → mdlId, "inspId" → inspId)
+
+ if (args.isDefined)
+ params += "args" → GSON.toJson(args.get)
- probePromise(parent, mdlId, probeInspecs, "S2P_PROBE_INSPECTION",
m.filter(_._2 != null).toSeq :_*)
+ probePromise(parent, mdlId, probeInspecs, "S2P_PROBE_INSPECTION",
params.toSeq :_*)
}
/**
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
index b293b56..0e1e148 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
@@ -39,12 +39,14 @@ import org.apache.nlpcraft.server.probe.NCProbeManager
import org.apache.nlpcraft.server.query.NCQueryManager
import org.apache.nlpcraft.server.user.NCUserManager
import spray.json.DefaultJsonProtocol._
-import spray.json.{DeserializationException, JsObject, JsValue, RootJsonFormat}
+import spray.json.{JsObject, JsValue, RootJsonFormat}
import scala.collection.JavaConverters._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import akka.http.scaladsl.coding.Coders
+import org.apache.nlpcraft.common.inspections.NCInspectionParameter
+import org.apache.nlpcraft.probe.mgrs.cmd.NCCommandManager.logger
import org.apache.nlpcraft.server.inspections.NCInspectionManager
/**
@@ -672,6 +674,71 @@ class NCBasicRestApi extends NCRestApi with LazyLogging
with NCOpenCensusTrace w
*
* @return
*/
+ protected def inspections$All(): Route = {
+ case class Req(
+ acsTok: String
+ )
+ case class Parameter(
+ id: String,
+ name: String,
+ value: String,
+ valueType: String,
+ synopsis: String,
+ description: String
+ )
+ case class Inspection(
+ id: String,
+ name: String,
+ synopsis: String,
+ parameters: Seq[Parameter],
+ description: String,
+ isServerSide: Boolean
+ )
+ case class Res(
+ status: String,
+ inspections: Seq[Inspection]
+ )
+
+ implicit val reqFmt: RootJsonFormat[Req] = jsonFormat1(Req)
+ implicit val paramFmt: RootJsonFormat[Parameter] =
jsonFormat6(Parameter)
+ implicit val inspFmt: RootJsonFormat[Inspection] =
jsonFormat6(Inspection)
+ implicit val resFmt: RootJsonFormat[Res] = jsonFormat2(Res)
+
+ entity(as[Req]) { req ⇒
+ startScopedSpan("inspections$All", "acsTok" → req.acsTok) { span ⇒
+ checkLength("acsTok", req.acsTok, 256)
+
+ authenticateAsAdmin(req.acsTok)
+
+ val inspections =
NCInspectionManager.getInspections(span).map(i ⇒ Inspection(
+ id = i.id(),
+ name = i.name(),
+ synopsis = i.synopsis(),
+ parameters = i.parameters().asScala.map(p ⇒
+ Parameter(
+ id = p.id(),
+ name = p.name(),
+ value = p.value(),
+ valueType = p.valueType(),
+ synopsis = p.synopsis(),
+ description = p.description()
+ )
+ ),
+ description = i.description(),
+ isServerSide = i.isServerSide
+ ))
+
+ complete {
+ Res(API_OK, inspections)
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ * @return
+ */
protected def clear$Conversation(): Route = {
case class Req(
acsTok: String,
@@ -1794,14 +1861,6 @@ class NCBasicRestApi extends NCRestApi with LazyLogging
with NCOpenCensusTrace w
path(API / "feedback" / "delete") {
withLatency(M_FEEDBACK_DELETE_LATENCY_MS, feedback$Delete) } ~
path(API / "probe" / "all") {
withLatency(M_PROBE_ALL_LATENCY_MS, probe$All) } ~
path(API / "ask") {
withLatency(M_ASK_LATENCY_MS, ask$) } ~
- (path(API / "model" / "inspect") &
- entity(as[JsValue])
- ) {
- req ⇒
-
onSuccess(withLatency(M_MODEL_INSPECT_LATENCY_MS, inspect$(req))) {
- js ⇒ complete(HttpResponse(entity
= HttpEntity(ContentTypes.`application/json`, js)))
- }
- } ~
(path(API / "ask" / "sync") &
entity(as[JsValue]) &
optionalHeaderValueByName("User-Agent") &
@@ -1811,7 +1870,16 @@ class NCBasicRestApi extends NCRestApi with LazyLogging
with NCOpenCensusTrace w
onSuccess(withLatency(M_ASK_SYNC_LATENCY_MS, ask$Sync(req, userAgentOpt,
rmtAddr))) {
js ⇒ complete(HttpResponse(entity
= HttpEntity(ContentTypes.`application/json`, js)))
}
- }}
+ }} ~
+ (path(API / "model" / "inspect") &
+ entity(as[JsValue])
+ ) {
+ req ⇒
+
onSuccess(withLatency(M_MODEL_INSPECT_LATENCY_MS, inspect$(req))) {
+ js ⇒ complete(HttpResponse(entity
= HttpEntity(ContentTypes.`application/json`, js)))
+ }
+ } ~
+ path(API / "model" / "inspections") {
withLatency(M_MODEL_INSPECTIONS_LATENCY_MS, inspections$All) }
}
}
}
diff --git a/openapi/nlpcraft_swagger.yml b/openapi/nlpcraft_swagger.yml
index 66eda92..cc9b945 100644
--- a/openapi/nlpcraft_swagger.yml
+++ b/openapi/nlpcraft_swagger.yml
@@ -176,7 +176,7 @@ paths:
required:
- acsTok
- mdlId
- - types
+ - inspId
properties:
acsTok:
type: string
@@ -186,12 +186,14 @@ paths:
type: string
maxLength: 32
description: Data model ID for which elements synonyms will be
suggested
- types:
- type: array
- items:
- type: string
+ inspId:
+ type: string
+ maxLength: 32
+ description: Inspection ID, currently supported are `macros`,
`synonyms`, `intents` and `suggestions`
+ args:
+ type: object
description: >-
- Inspections set. Possible values are: INSPECTION_MACROS,
INSPECTION_SYNONYMS, INSPECTION_INTENTS, SUGGEST_SYNONYMS or ALL.
+ Inspection parameter. Currently supported `minScore` double
value for `suggestions` inspection.
responses:
'200':
description: Successful operation.
@@ -214,6 +216,104 @@ paths:
description: Failed operation.
schema:
$ref: '#/definitions/Error'
+ /model/inspectons:
+ post:
+ tags:
+ - Models inspections
+ summary: Gets all models inspections.
+ description: >-
+ Gets all models inspections.. Administrative privileges required.
+ operationId: getAllInspections
+ parameters:
+ - in: body
+ name: Payload body
+ description: JSON request.
+ required: true
+ schema:
+ type: object
+ required:
+ - acsTok
+ properties:
+ acsTok:
+ maxLength: 256
+ description: Access token obtain via '/signin' call
+ type: string
+ responses:
+ '200':
+ description: Successful operation.
+ schema:
+ type: object
+ required:
+ - status
+ - inspections
+ properties:
+ status:
+ type: string
+ description: Status code of this operation
+ enum:
+ - API_OK
+ probes:
+ type: array
+ items:
+ type: object
+ required:
+ - id
+ - name
+ - synopsis
+ - parameters
+ - description
+ - isServerSide
+ properties:
+ id:
+ description: Inspection ID
+ type: string
+ name:
+ description: Inspection name
+ type: string
+ synopsis:
+ description: Inspection synopsis
+ type: string
+ parameters:
+ description: Parameters
+ type: array
+ items:
+ type: object
+ required:
+ - id
+ - name
+ - value
+ - valueType
+ - synopsis
+ - description
+ properties:
+ id:
+ description: Parameters ID
+ type: string
+ name:
+ description: Parameters name
+ type: string
+ value:
+ description: Parameters value
+ type: string
+ valueType:
+ description: Parameters valueType
+ type: string
+ synopsis:
+ description: Parameters synopsis
+ type: string
+ description:
+ description: Parameters description
+ type: string
+ description:
+ description: Inspection description
+ type: string
+ isServerSide:
+ description: Inspection `is-Server-Side` flag
+ type: boolean
+ '400':
+ description: Failed operation.
+ schema:
+ $ref: '#/definitions/Error'
/check:
post:
tags: