Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
rasa core -> rasa open source
Browse files Browse the repository at this point in the history
  • Loading branch information
space-pope committed Apr 20, 2021
1 parent 0aa8b15 commit 91f7573
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 47 deletions.
25 changes: 13 additions & 12 deletions src/main/java/io/spokestack/spokestack/Spokestack.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import io.spokestack.spokestack.nlu.tensorflow.parsers.IdentityParser;
import io.spokestack.spokestack.nlu.tensorflow.parsers.IntegerParser;
import io.spokestack.spokestack.nlu.tensorflow.parsers.SelsetParser;
import io.spokestack.spokestack.rasa.RasaCoreNLU;
import io.spokestack.spokestack.rasa.RasaOpenSourceNLU;
import io.spokestack.spokestack.rasa.RasaDialoguePolicy;
import io.spokestack.spokestack.tts.SynthesisRequest;
import io.spokestack.spokestack.tts.TTSEvent;
Expand Down Expand Up @@ -580,7 +580,7 @@ public static class Builder {
* <p>
* Note that NLU properties are not required if Rasa NLU and
* dialogue management are in use
* (see {@link #useRasaCore(String)}),
* (see {@link #useRasaOpenSource(String)}),
* but other properties are required to configure the Rasa
* integration.
* </p>
Expand Down Expand Up @@ -650,7 +650,7 @@ public static class Builder {
* <p>
* Like NLU, these properties are not required if Rasa NLU and
* dialogue management are in use via
* {@link #useRasaCore(String)}.
* {@link #useRasaOpenSource(String)}.
* </p>
* <ul>
* <li>
Expand Down Expand Up @@ -811,23 +811,24 @@ public Builder setProperty(String key, Object value) {
}

/**
* Use the Rasa Core NLU and dialogue policy components to handle user
* utterances.
* Use the Rasa Open Source NLU and dialogue policy components to
* handle user utterances.
*
* <p>
* This method sets the {@code rasa-core-url} property automatically;
* (see {@link io.spokestack.spokestack.rasa.RasaCoreNLU}
* This method sets the {@code rasa-oss-url} property automatically;
* (see {@link RasaOpenSourceNLU}
* and {@link io.spokestack.spokestack.rasa.RasaDialoguePolicy} for
* other relevant properties).
* </p>
*
* @param rasaCoreUrl URL to the Rasa Core server. The Rasa Core
* component is designed to use Rasa's REST channel.
* @param rasaCoreUrl URL to the Rasa Open Source server.
* The Rasa Open Source component is designed to use
* Rasa's REST channel.
* @return the updated builder
*/
public Builder useRasaCore(String rasaCoreUrl) {
this.setProperty("rasa-core-url", rasaCoreUrl);
this.nluBuilder.setServiceClass(RasaCoreNLU.class.getName());
public Builder useRasaOpenSource(String rasaCoreUrl) {
this.setProperty("rasa-oss-url", rasaCoreUrl);
this.nluBuilder.setServiceClass(RasaOpenSourceNLU.class.getName());
this.dialogueBuilder
.withDialoguePolicy(RasaDialoguePolicy.class.getName());
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import java.util.List;

/**
* A dialogue policy that examines the response from a Rasa Core server
* retrieved by a {@link RasaCoreNLU} component and dispatches events based on
* its contents.
* A dialogue policy that examines the response from a Rasa Open Source server
* retrieved by a {@link RasaOpenSourceNLU} component and dispatches events
* based on its contents.
*
* <p>
* A {@code text} response is dispatched as a {@code PROMPT} event, and an image
Expand All @@ -28,8 +28,8 @@
* </p>
*
* <p>
* Intents that do not match the one produced by {@link RasaCoreNLU} are not
* supported and will result in {@code ERROR} events.
* Intents that do not match the one produced by {@link RasaOpenSourceNLU} are
* not supported and will result in {@code ERROR} events.
* </p>
*/
public final class RasaDialoguePolicy implements DialoguePolicy {
Expand All @@ -38,7 +38,8 @@ public final class RasaDialoguePolicy implements DialoguePolicy {
private final Gson gson;

/**
* Create a new dialogue policy for handling responses from Rasa Core.
* Create a new dialogue policy for handling responses from Rasa Open
* Source.
*
* @param speechConfig configuration properties for this policy.
*/
Expand All @@ -63,7 +64,7 @@ public void handleTurn(
ConversationData conversationData,
DialogueDispatcher eventDispatcher) {
String intent = userTurn.getIntent();
if (!intent.equals(RasaCoreNLU.RASA_INTENT)) {
if (!intent.equals(RasaOpenSourceNLU.RASA_INTENT)) {
// we can't handle non-Rasa intents
dispatchError(eventDispatcher, intent);
}
Expand All @@ -84,7 +85,8 @@ private void dispatchError(DialogueDispatcher dispatcher, String intent) {
}

private List<RasaResponse> getResponses(NLUResult userTurn) {
Object response = userTurn.getContext().get(RasaCoreNLU.RESPONSE_KEY);
Object response = userTurn.getContext()
.get(RasaOpenSourceNLU.RESPONSE_KEY);
String json = response != null ? response.toString() : "{}";
return this.gson.fromJson(json, RasaResponse.TYPE);
}
Expand Down Expand Up @@ -123,7 +125,7 @@ public void completeTurn(
}

/**
* Wrapper class used to deserialize JSON responses from Rasa Core.
* Wrapper class used to deserialize JSON responses from Rasa Open Source.
*/
private static class RasaResponse {
private static final Type TYPE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
import java.util.concurrent.TimeUnit;

/**
* An NLU component that submits utterances to a Rasa Core server to retrieve
* responses.
* An NLU component that submits utterances to a Rasa Open Source server to
* retrieve responses.
*
* <p>
* Since the input for a Rasa Core request is a user utterance, this component
* occupies the position in Spokestack of an NLU, but a Rasa webhook response
* includes results from the dialogue model, leaving out NLU results. Therefore,
* this component returns a constant value as the intent and includes the
* webhook response as a list inside the result context under a {@code
* "responses"} key.
* Since the input for a Rasa Open Source request is a user utterance, this
* component occupies the position in Spokestack of an NLU, but a Rasa webhook
* response includes results from the dialogue model, leaving out NLU results.
* Therefore, this component returns a constant value as the intent and
* includes the webhook response as a list inside the result context under a
* {@code "responses"} key.
* </p>
*
* <p>
Expand All @@ -45,38 +45,38 @@
* </p>
* <ul>
* <li>
* <b>rasa-core-url</b> (string, required): URL to the Rasa core
* <b>rasa-oss-url</b> (string, required): URL to the Rasa Open Source
* server. This component is designed to use Rasa's REST channel.
* </li>
* <li>
* <b>rasa-sender-id</b> (string, optional): Sender ID for Rasa requests.
* Defaults to "spokestack-android".
* </li>
* <li>
* <b>rasa-core-token</b> (string, optional): Token to use in requests to
* the Rasa core server. See
* <b>rasa-oss-token</b> (string, optional): Token to use in requests to
* the Rasa Open Source server. See
* <a href="https://rasa.com/docs/rasa/http-api#token-based-auth">Rasa's
* documentation</a> for more details.
* </li>
* <li>
* <b>rasa-core-jwt</b> (string, optional): A full JWT header (including
* the "Bearer " prefix) to use in requests to the Rasa core server. See
* <a href="https://rasa.com/docs/rasa/http-api#jwt-based-auth">Rasa's
* <b>rasa-oss-jwt</b> (string, optional): A full JWT header (including
* the "Bearer " prefix) to use in requests to the Rasa Open Source server.
* See <a href="https://rasa.com/docs/rasa/http-api#jwt-based-auth">Rasa's
* documentation</a> for more details.
* </li>
* </ul>
*/
public final class RasaCoreNLU implements NLUService {
public final class RasaOpenSourceNLU implements NLUService {

/**
* The designated intent produced by this component since Rasa core
* The designated intent produced by this component since Rasa Open Source
* responses do not include classification results.
*/
public static final String RASA_INTENT = "rasa.core";

/**
* The designated key for response messages from Rasa core in an {@link
* NLUResult} produced by this component.
* The designated key for response messages from Rasa Open Source in an
* {@link NLUResult} produced by this component.
*/
public static final String RESPONSE_KEY = "responses";

Expand All @@ -96,13 +96,13 @@ public final class RasaCoreNLU implements NLUService {
private final Gson gson;

/**
* Create a new Rasa NLU component.
* Create a new Rasa Open Source NLU component.
*
* @param config configuration properties
* @param nluContext The NLU context used to dispatch trace events and
* errors.
*/
public RasaCoreNLU(SpeechConfig config, NLUContext nluContext) {
public RasaOpenSourceNLU(SpeechConfig config, NLUContext nluContext) {
this(config,
nluContext,
new OkHttpClient.Builder()
Expand All @@ -112,12 +112,12 @@ public RasaCoreNLU(SpeechConfig config, NLUContext nluContext) {
);
}

RasaCoreNLU(SpeechConfig config,
NLUContext nluContext,
OkHttpClient client) {
this.coreUrl = config.getString("rasa-core-url");
this.token = config.getString("rasa-core-token", null);
this.jwt = config.getString("rasa-core-jwt", null);
RasaOpenSourceNLU(SpeechConfig config,
NLUContext nluContext,
OkHttpClient client) {
this.coreUrl = config.getString("rasa-oss-url");
this.token = config.getString("rasa-oss-token", null);
this.jwt = config.getString("rasa-oss-jwt", null);
this.senderId = config.getString("rasa-sender-id", DEFAULT_SENDER);
this.context = nluContext;
this.gson = new Gson();
Expand Down

0 comments on commit 91f7573

Please sign in to comment.