Sentence Similarity
SkillfulAPI.
SentenceSimilarity
SkillfulAPI.
SentenceSimilarity
Overview
The SentenceSimilarity
function is a simple example of how to interact with the SkillfulAI API to compare an input sentence against multiple context sentences. This functionality can be used to enhance dialogue systems, improve search relevance, and more.
Function Example
Detailed Explanation
Start Method
Description: Unity's Start method is called once when the script is initialized. This method initiates the sentence similarity check.
Code:
Functionality:
Calls the
CheckSimilarity
method to begin the process.
CheckSimilarity Method
Description: The CheckSimilarity
method handles the sentence similarity logic, using the SkillfulAI API to compare an input sentence against a set of context sentences.
Code:
Functionality:
Defines a
context
array containing sentences for comparison.Defines an
inputSentence
string that will be compared against the context sentences.Calls
SkillfulAPI.SentenceSimilarity
, passing theinputSentence
,context
, and callback functions to handle the response and errors.The success callback processes the similarity scores, identifies the best match, and logs it to the Unity console.
The error callback logs any errors to the Unity console.
Usage Example
Add the Script to a GameObject:
Attach the
SentenceSimilarity
script to any GameObject in your Unity scene.
Run the Scene:
When you start the scene, the
Start
method is called, which in turn calls theCheckSimilarity
method.The
CheckSimilarity
method sends the input sentence and context sentences to the SkillfulAI API and logs the best match to the console.
Conclusion
The SentenceSimilarity
function provides a straightforward example of how to leverage the SkillfulAI Gaming SDK to integrate AI-powered sentence similarity checks into your Unity project. This can be expanded and customized to suit more complex scenarios and interactions in your game.
Last updated