Function calling via the SDK
For this tutorial we are going to use the function Suggest Movie
, which takes two query params rating
and score
and returns a random movie that will satisfy the criteria.
We are going to use the SDK (Software Development Kit) which is a key feature of JellyFaaS, the SDK allows you to rapidly interact and call functions from a number of supported languages.
The SDK includes a number of error handling and validation checks, ensuring you do not call out to the function unless it stands a chance of success. For example Suggest Movie
required two query params, if you do not supply them the SDK will not even attempt to invoke the function and fail (fast). The same happens on a POST
if the required parameters are not in the body passed in, then the SDK will not attempt to call out to the JellyFaaS servers,
Information
All information on the required parameters, POST
bodies, code samples and copy and paste structures/classes can be found on the function details page
Later on you will see how the SDK help speed up complex AI functionality and how you can easily use the SDK to use these functions as part of an AI query.
Prerequisites
You will need to install the SDK for the language(s) you are using, for instructions see here
Create the code to call the server
Copy the following code into your IDE:
const {Config, Client} = require('jellyfaas')
query_params = {
"rating": "PG",
"score": "5.8"
}
new Config("<JELLYFAAS_SECRET>").then(config => { // Construct Config
new Client(config) // Construct Client
.lookupFunction("suggestmovie").then(client => { // Loopup function
client.setFunctionQueryParams(query_params) // Set query params
.invoke(null, false).then(resp => { // invoke (overriding validation)
console.log(resp)
})
})
})
Information
This code is in the simplest form for clarity, it doesn't handle exceptions for example.
Output
Once ran, you will see the following output:
Congratulations, you just called your first function via the SDK! Now look at the next tutorials, or play around with other functions!
Help, it didn't work
- First, check you have correctly imported the library, do you have any errors? can you not 'inspect' the library to see the SDK's actual code?
- Check you have pasted or typed in the correct endpoint from here.
- Is the api token correct, this should be your secret key from your profile page
For further help, please contact support
Next Steps
- Next try creating your own function here