Integración
Una Appx es cómo su nombre lo indica una extensión, Suite Community Edition permite crear tus propias extensiones con poco código.
Una Appx es cómo su nombre lo indica una extensión. Puedes desarrollar tus propias extensiones utilizando la libreria de código abierto comunitaria. Las appx se instalan en una carpeta bien conocida dentro del directorio raíz del sistema. Para que el sistema pueda resolver las interacciones es necesario que entrenes el conjunto de datos con la información requerida (ver código de ejemplo):
Crear tu primera Appx
Crea un paquete Swift con Xcode y añade Suite Community Edition
import PackageDescription
let package = Package(
name: "suite-appx-stories",
platforms: [.macOS(.v11), .iOS(.v11)],
dependencies: Package.all,
cxxLanguageStandard: .cxx11
)
fileprivate extension Package {
static func url(package: String) -> String {
return "[email protected]:comdigis" + "/" + package + ".git"
}
static let all: [PackageDescription.Package.Dependency] = [
.package(url: url(package: "suite-sdk-community"), .branch(branch)),
]
static var branch: String {
return "develop"
}
}
package.targets += [
.target(name: "Stories.extension", dependencies: [
.product(name: "Appx", package: "suite-sdk-community"),
]),
]
2. Crear un Controlador
para manejar tus interacciones.
import Appx
import Foundation
class Controller: SceneController {
open override func load() {
super.load()
subscribe(to: Intent.Name(.generic), perform: application(intent:completion:))
}
open override func appear() {
super.appear()
}
/// Called when some `Intent` is received from current session
/// - parameter intent: The received intent from responder that should be forwarded to superclass
open override func intent(intent: Intent) {
super.intent(intent: intent)
}
/// Called when some `IntentResolution` is received
/// - parameter resolution: A given `IntentResolution`
open override func resolution(resolution: IntentResolution) {
super.resolution(resolution: resolution)
}
}
extension Controller {
/// Called when the main application `Intent` is resolved
/// - parameter intent: Any given `Intent`
/// - parameter completion: A block to return the resolution for the intent
func application(intent: Intent, completion: @escaping IntentRouteHandler) {
let speechValue: String = "La aplicación inició correctamente"
return completion(.success(value: .intent(intent, speechValue: speechValue)))
}
}
3. Crear un objeto delegado para tu aplicación
import Appx
import Foundation
class AppDelegate: Responder, AppxDelegate {
/// Called before the application launch
/// - note: We use this method to prepare the configuration
/// - parameter application: A pointer to the current application object (singleton)
/// - returns: A boolean that indicates if its ready
func prepare(_ application: Appx) -> Bool {
return true
}
/// Called once the application did finish launching
/// - note: We use this method to prepare the configuration
/// - parameter application: A pointer to the current application object (singleton)
/// - returns: A boolean that indicates if its ready
func initialize(_ application: Appx) -> Bool {
let session = VUI(controller: Controller())
application.start(session: session)
return true
}
/// Called right before the application will terminate
/// - parameter application: A pointer to the current application object (singleton)
func terminate(_ application: Appx) {
print("terminate")
}
}
4. Configura un entrypoint para tu aplicación Appx en el archivo main.swift
App(with: AppDelegate())
Despliegue
Cuando hayamos terminado nuestra primera interacción podemos compilar y desplegar utilizando la línea de comandos. Pero antes debemos crear nuestro JSON
para poder generar el paquete instalable. El JSON
deberá tener la siguiente estructura:
{
"identifier":"com.application.example",
"name": "example app",
"display": "example application",
"category": "extension",
"version": "",
"description": "some skill",
"utterances": [
"buscar algo",
"buscar {entity} en mi aplicacion",
"busqueda en mi aplicacion",
"encontrar en aplicacion"
],
"metadata" : [
{
"entity" : "entity",
"slotValue" : "",
"score" : "1",
"speechValue" : "que quieres buscar?"
}
],
"responses" : [],
"input" : "",
"languageCode" : "es",
"confidence" : ""
}
Instalación de Appx
Una vez tengamos el JSON
es posible generar el paquete y desplegar la appx.
ask appx.install --binary ~/path/to/binary/ --json ~/path/to/json/
Recuerda que éste no es el último paso, todavía debes re-entrenar el modelo de Tensorflow Lite.
ask train.json ~/path/to/folder/
Última actualización