Integrating wit.ai with Flutter

wit.ai

wit.ai is a NLP engine by Facebook that allows users to convert statements into a queried structural data hence allowing developers to build conversational applications such as chatbots.

To get started you can simply visit wit.ai a…


This content originally appeared on DEV Community and was authored by Amey Sunu

wit.ai

wit.ai is a NLP engine by Facebook that allows users to convert statements into a queried structural data hence allowing developers to build conversational applications such as chatbots.

Logo

To get started you can simply visit wit.ai and login with your existing Facebook account. You can also make the use of amazing documentation provided by the wit.ai team.

Integration

  • To add wit.ai to your Flutter app, simply install the flutter_witai package from pub.dev.

  • Now create a wit object and set it to the WitManager class from the package, which consists of 2 parameters namely utterance, headers.

final wit = WitManager(utterance: "hello",headers: "XXXXXXXXXX");

Utterance will be your query statement for which you'd be creating a structured data response and headers will be the wit.ai project SERVER ACCESS TOKEN which can be found in the settings.

  • Call the fetchLink() function to trigger the wit.ai function and get the structured JSON response based on whatever utterance query you mentioned.
wit.fetchLink();
  • You can view the results by printing out the json to the console, by setting the fetchLink() function to a dynamic variable
dynamic response = await wit.fetchLink();
print(response);

The response should look somewhat like this:

{"text":"hello","intents":[{"id":"985952918880417","name":"search","confidence":1}],"entities":{},"traits":{"wit$sentiment":[{"id":"5ac2b50a-44e4-466e-9d49-bad6bd40092c","value":"positive","confidence":0.5435}]}}

  • You can now get any values from the response json, such as entities, traits or any such values.
print(response['entities']);

It's that simple. You can create any Flutter button such as TextButton and then simply call the function within it's onPressed parameter to call the wit.ai function. Also remember to use the async keyword for asynchronous operations.

You can also take a look at the example code written in the package.


This content originally appeared on DEV Community and was authored by Amey Sunu


Print Share Comment Cite Upload Translate Updates
APA

Amey Sunu | Sciencx (2021-06-21T05:27:13+00:00) Integrating wit.ai with Flutter. Retrieved from https://www.scien.cx/2021/06/21/integrating-wit-ai-with-flutter/

MLA
" » Integrating wit.ai with Flutter." Amey Sunu | Sciencx - Monday June 21, 2021, https://www.scien.cx/2021/06/21/integrating-wit-ai-with-flutter/
HARVARD
Amey Sunu | Sciencx Monday June 21, 2021 » Integrating wit.ai with Flutter., viewed ,<https://www.scien.cx/2021/06/21/integrating-wit-ai-with-flutter/>
VANCOUVER
Amey Sunu | Sciencx - » Integrating wit.ai with Flutter. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/21/integrating-wit-ai-with-flutter/
CHICAGO
" » Integrating wit.ai with Flutter." Amey Sunu | Sciencx - Accessed . https://www.scien.cx/2021/06/21/integrating-wit-ai-with-flutter/
IEEE
" » Integrating wit.ai with Flutter." Amey Sunu | Sciencx [Online]. Available: https://www.scien.cx/2021/06/21/integrating-wit-ai-with-flutter/. [Accessed: ]
rf:citation
» Integrating wit.ai with Flutter | Amey Sunu | Sciencx | https://www.scien.cx/2021/06/21/integrating-wit-ai-with-flutter/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.