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

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


The following commit(s) were added to refs/heads/NLPCRAFT-491 by this push:
     new bec3fb35 WIP.
bec3fb35 is described below

commit bec3fb3500d75c1bde587067aca23412bdfbf219
Author: Sergey Kamov <[email protected]>
AuthorDate: Thu Apr 7 22:51:01 2022 +0300

    WIP.
---
 .../nlpcraft/examples/pizzeria/PizzeriaOrder.scala     |  6 +++---
 .../nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala |  4 ++--
 .../examples/pizzeria/cli/PizzeriaModelClientCli.scala |  2 +-
 .../examples/pizzeria/cli/PizzeriaModelServer.scala    | 18 +++++++-----------
 4 files changed, 13 insertions(+), 17 deletions(-)

diff --git 
a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaOrder.scala
 
b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaOrder.scala
index f7708dbb..c76788cf 100644
--- 
a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaOrder.scala
+++ 
b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaOrder.scala
@@ -142,8 +142,8 @@ class PizzeriaOrder:
       */
     def getDesc: String =
         if !isEmpty then
-            val ps = if pizzas.nonEmpty then s"Pizza: ${pizzas.mkString(", 
")}" else ""
-            val ds = if drinks.nonEmpty then s"Drinks: ${drinks.mkString(", 
")}" else ""
+            val ps = if pizzas.nonEmpty then s"pizza: ${pizzas.mkString(", 
")}" else ""
+            val ds = if drinks.nonEmpty then s"drinks: ${drinks.mkString(", 
")}" else ""
 
             if ds.isEmpty then ps else if ps.isEmpty then ds else s"$ps, $ds"
-        else "Nothing ordered."
\ No newline at end of file
+        else "nothing ordered"
\ No newline at end of file
diff --git 
a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala
 
b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala
index 68bd42fa..f175a090 100644
--- 
a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala
+++ 
b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala
@@ -49,7 +49,6 @@ class PizzeriaModelSpec:
             this
         def build: PizzeriaOrder = o
 
-
     private val mdl = new ModelTestWrapper()
     private val client = new NCModelClient(mdl)
 
@@ -70,7 +69,7 @@ class PizzeriaModelSpec:
 
         require(errs.isEmpty)
 
-    private def dialog(exp: PizzeriaOrder, reqs: (String , NCResultType)*): 
Unit =
+    private def dialog(exp: PizzeriaOrder, reqs: (String, NCResultType)*): 
Unit =
         val testMsgs = mutable.ArrayBuffer.empty[String]
         msgs += testMsgs
 
@@ -115,6 +114,7 @@ class PizzeriaModelSpec:
     def test(): Unit =
         given Conversion[String, (String, NCResultType)] with
             def apply(txt: String): (String, NCResultType) = (txt, ASK_DIALOG)
+            
         dialog(
             new Builder().withDrink("tea", 1).build,
             "One tea",
diff --git 
a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelClientCli.scala
 
b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelClientCli.scala
index 7c35164f..91c31f96 100644
--- 
a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelClientCli.scala
+++ 
b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelClientCli.scala
@@ -51,7 +51,7 @@ object PizzeriaModelClientCli extends LazyLogging :
     def main(args: Array[String]): Unit =
         println("Application started.")
 
-        // Clears possible saved sessions.
+        // Clears possible saved sessions.tea
         ask("stop")
 
         var applStarted = true
diff --git 
a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelServer.scala
 
b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelServer.scala
index 1f89208d..ba9ad12c 100644
--- 
a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelServer.scala
+++ 
b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelServer.scala
@@ -41,8 +41,8 @@ object PizzeriaModelServer:
 
         srv.createContext(
             s"/$path",
-            (e: HttpExchange) =>
-                def response(txt: String): Unit =
+            (e: HttpExchange) => {
+                def doResponse(txt: String): Unit =
                     Using.resource(new 
BufferedOutputStream(e.getResponseBody)) { out =>
                         val arr = txt.getBytes
                         e.sendResponseHeaders(200, arr.length)
@@ -53,25 +53,21 @@ object PizzeriaModelServer:
                     val req =
                         e.getRequestMethod match
                             case "GET" => 
e.getRequestURI.toString.split("\\?").last
-                            case "POST" =>
-                                Using.resource(new BufferedReader(new 
InputStreamReader(e.getRequestBody))) { r =>
-                                    r.readLine
-                                }
+                            case "POST" => Using.resource(new 
BufferedReader(new InputStreamReader(e.getRequestBody))) { _.readLine }
                             case _ => throw new Exception(s"Unsupported 
request method: ${e.getRequestMethod}")
 
                     if req == null || req.isEmpty then Exception(s"Empty 
request")
 
                     val resp = nlpClient.ask(req, null, "userId")
                     val prompt = if resp.getType == ASK_DIALOG then "(Your 
should answer on the model's question below)\n" else ""
-
-                    response(s"$prompt${resp.getBody}")
+                    doResponse(s"$prompt${resp.getBody}")
                 catch
-                    case e: NCRejection => response(s"Request rejected: 
${e.getMessage}")
+                    case e: NCRejection => doResponse(s"Request rejected: 
${e.getMessage}")
                     case e: Throwable =>
                         System.err.println("Unexpected error.")
                         e.printStackTrace()
-                        response(s"Unexpected error: ${e.getMessage}")
-            )
+                        doResponse(s"Unexpected error: ${e.getMessage}")
+            })
 
         srv.start()
 

Reply via email to