Coder Social home page Coder Social logo

sdk-android's Introduction

SAP Conversational AI - SDK-Android

SAP Conversational AI Logo

🚨 Sunset of Open Source SDKs for SAP Conversational AI

SAP Conversational AI provides several SDKs, which are all open-source and hosted on GitHub.
Starting from January 2021, please note that we inform you that the SDKs will not be available anymore and the public repository of the project will be archived from GitHub.

✨ Why are we sunsetting our SDKs?

Firstly, we noticed over the past year that these SDKs were not used much by our users.
This is because our platform usage has become easier, including the APIs.

Secondly, our APIs have undergone major changes. We would need to adapt the SDKs in order to keep them working, which will lead to a significant cost from our side.

Hence, we decided to sunset this open source version starting from January 2021.

✨ What does it mean for me as a user?

Any changes in our API’s will not be reflected in our SDKs. Hence, the code might not work unless you adjust the same.

✨ What are the next steps?

If you are interested in taking the ownership of the project on GitHub, please get in touch with us and we can discuss the process. Otherwise, if there are no objections from anyone, we would archive the project following the open source sunset process.

Please use the platform SAP Answers if you have any other questions related to this topic.

Happy bot building!

The SAP Conversational AI team


Synopsis

This module is an Android interface to the SAP Conversational AI API. It allows you to make requests to your bots.

Installation

Just update your build.gradle files:

In your module:

dependencies {
  compile 'ai.sapcai.sdk_android:sdk-android:4.0.0'
}

Usage

import ai.sapcai.sdk_android.Client;

Client client = new Client(YOUR_TOKEN);
Response resp;

try {
  resp = client.textRequest(YOUR_TEXT);
} catch (SapcaiException e) {
  // error
}

Specs

Classes

This module contains 9 main classes as follows:

  • Client is the client allowing you to make requests to SAP Conversational AI API.
  • Response contains the response from SAP Conversational AI.
  • Entity represents an entity found in you user's input as defined in SAP Conversational AI Manual
  • Intent represents the intent of your user
  • Action represents the actions of a conversation
  • Memory represents the memory of a conversation
  • MemoryEntity represents the entity inside the memory object
  • Conversation allowing you to handle a conversation
  • SapcaiException is the error thrown by the module.

Class Client

The SAP Conversational AI Client can be instanciated with a token and provides the following methods:

Request:

  • textRequest(String text)
  • fileRequest(String filename)

These methods both return a Response object.

Conversation

  • textConverse(String text)

This method return a Conversation object.

Audio Recording:

  • startRecording() Starts the audio recording to a file
  • stopRecording() Stops the audio recording, sends the audio to SAP Conversational AI and returns a Response object

Note that all these methods should be called in separated tasks because they do http requests.

import ai.sapcai.sdk_android.Client;

Client client = new Client(YOUR_TOKEN);
Response resp;

try {
  resp = client.textRequest("Hello World!");
  // Do your code...
} catch (Exception e) {
  // Handle error
}

try {
  resp = client.fileRequest("my_file.wav");
  // Do you code..
} catch (Exception e) {
  // Handle error
}

try {
  Conversation conversation = client.textConverse("Hello, my name is Paul");
} catch (Exception e) {
  // Handle error
}

Class Response

The SAP Conversational AI Response is generated after a call with the Client methods and contains the following methods:

  • getAct() Returns the act of the sentence
  • getType() Returns the type of the sentence
  • getSentiment() Returns the sentiment of the sentence
  • getEntity(String name) Returns the first entity matching -name- or null
  • getEntities(String name) Returns an array of all entities matching -name- or null
  • getStatus() Returns the status of the Response
  • getSource() Returns the source of the input
  • getIntent() Returns the main intent detected by SAP Conversational AI
  • getIntents() Returns all intents ordered by probability
  • getVersion() Returns the version of the JSON
  • getUuid() Returns the uuid of the response
  • IsAbbreviation() IsAbbreviation returns whether or not the sentence is asking for an abbreviation
  • IsEntity() IsEntity returns whether or not the sentence is asking for an entity
  • IsDescription() IsDescription returns whether or not the sentence is asking for an description
  • IsHuman() IsHuman returns whether or not the sentence is asking for an human
  • IsLocation() IsLocation returns whether or not the sentence is asking for an location
  • IsNumber() IsNumber returns whether or not the sentence is asking for an number
  • IsPositive() IsPositive returns whether or not the sentiment is positive
  • IsVeryPositive() IsVeryPositive returns whether or not the sentiment is very positive
  • IsNeutral() IsNeutral returns whether or not the sentiment is neutral
  • IsNegative() IsNegative returns whether or not the sentiment is negative
  • IsVeryNegative() IsVeryNegative returns whether or not the sentiment is very negative
  • IsAssert() IsAssert returns whether or not the sentence is an assertion
  • IsCommand() IsCommand returns whether or not the sentence is a command
  • IsWhQuery() IsWhQuery returns whether or not the sentence is a wh query
  • IsYnQuery() IsYnQuery returns whether or not the sentence is a yes-no question
  • Get(name string) Returns the first entity matching -name-
  • All(name string) Returns all entities matching -name-
resp = client.textRequest("Give me a recipe with Asparagus.");
String intent = resp.getIntent();
if (intent != null && intent.equals("recipe")) {
  //get all the entities matching 'ingredient'
  Entities[] entities = resp.getEntities("ingredient");

  // ...
}

Class Entity

The SAP Conversational AI Entity is returned by Response and provides the following methods:

  • String getName() Returns the name of the entity
  • String getRaw() Returns the raw text on which the entity was detected
  • Object getField(String fieldName)

In addition to getName and getRaw, more attributes can be accessed by the getField method which can be one of the following:

  • hex
  • value
  • deg
  • formatted
  • lng
  • lat
  • unit
  • code
  • person
  • number
  • gender
  • next
  • grain
  • order

SAP Conversational AI entity fields types are dependant on the entity itself, so value returned must be casted depending on the entity you wait.

Refer to SAP Conversational AI Entities Manual for details about entities

Response resp = client.textRequest("What's the weather in San Francisco?");
if (resp.getIntent() != null && resp.getIntent().equals("weather")) {
  Entity e = resp.getEntity("location");
  if (e != null) {
    System.out.printf("You asked me for a weather in %s\n", (String)e.getField("formated"));
  }
}

Class SapcaiException

This exception is thrown when an error occurs during the request

More

You can view the whole API reference at cai.tools.sap/docs/api-reference.

You can follow us on Twitter at @sapcai for updates and releases.

License

Copyright (c) [2019] SAP Conversational AI

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

sdk-android's People

Contributors

janteuni avatar jhoudan avatar thbeucher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sdk-android's Issues

Blank Names

Hello;
I am using the SDK and everything works fine but when I try to get the name of the returned Intent, nothing appears, I actually get the confidence and the other properties but not the name.
I use getIntent().getName().
Have no method getUuid() too.

Should know that I downloaded the OI after adding this maven url https://dl.bintray.com/recast-ai/maven/
Thank you:

Failed to resolve ai.recast

When i add the dependency in the build.gradle file, the sync throws an error saying that it cannot resolve ai.recast. Please suggest me any fixes for this issue.

Dependancy add failed

trying to add the dependancy - compile 'ai.recast.sdk_android:sdk-android:4.0.0' in android studio 3.5 .Gradel sync failed.

Dependancy add failed

trying to add the dependancy - compile 'ai.recast.sdk_android:sdk-android:4.0.0' in android studio 3.1.1. .Gradel sync failed.

Call the dialog url

Hi
I am trying to send http request to the dialog i succeed with curl but i dotn know why its not working in java code I am always recieve 400 code when I am trying to pass teh message and the conversation_id

This is my code
please advice ?
``public String doApiRequest(String text, String token, String language, URL obj,boolean conversation) throws RecastException {
HttpURLConnection con=null;
OutputStream os;
int responseCode = 0;
String inputLine;
StringBuffer responseBuffer;
String recastJson;

    try {

        con = (HttpURLConnection) obj.openConnection();

        con.setRequestMethod("POST");
        con.setRequestProperty("Authorization", "Token " + token);
        con.setDoOutput(true);
        os = con.getOutputStream();
        if(conversation){
            JSONObject messageJson = new JSONObject();
            messageJson.put("message","{\"content\":\""+text+"\",\"type\":\"text\"}");
            messageJson.put("conversation_id","fgbotconv123456");
            
            os.write(messageJson.toString().getBytes());
        }

        text = "text=" + text;
        os.write(text.getBytes());

        if (language != null) {
            String l = "&language=" + language;
            os.write(l.getBytes());
        }
        os.flush();
        os.close();

        responseCode = con.getResponseCode();
    } catch (MalformedURLException e) {
        throw new RecastException("Invalid URL", e);
    } catch (IOException e) {
        throw new RecastException("Unable to read response from Recast", e);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    if (responseCode == HttpURLConnection.HTTP_OK) {
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
            responseBuffer = new StringBuffer();
            while ((inputLine = reader.readLine()) != null) {
                responseBuffer.append(inputLine);
            }
            reader.close();
        } catch (IOException e) {
            throw new RecastException("Unable to read response from Recast", e);
        }
        recastJson = responseBuffer.toString();
    } else {
        System.out.println(responseCode);
        throw new RecastException(responseCode);
    }
    return recastJson;
}``

Dependancy Not Working

trying to add the dependancy - compile 'ai.recast.sdk_android:sdk-android:4.0.0' in android studio 3.1.1. .Gradel sync failed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.