SDK Components
API Key Usage
The API supports retrieving responses in 2 Formats:
1. Stream Response 2. Blob response
Our SDK also provides an option to incorporate custom context, allowing clients to tailor the response to their specific requirements. The following cases illustrate how the API key can be utilized effectively.
Stream Response
Case 1: Simple General Chat (without Custom Context)
To retrieve a response using the API's default settings, the following code snippet should be used. The user must input their API key, generated through the API dashboard, in the highlighted section.
Case 2: Use Custom Context From AI Hub
Step 1: Create Your API Key (as mentioned in Configurations)
Obtain your API key from AI Hub to access the SDK.
Step 2: Add Company Details from AI Hub/ User Side
Define your company details, including name, description, website, whitepaper, and chatbot purpose in apiKey (additional information).
Step 3: Set Custom Context true (Additional information fetched from AI Hub)
When using CustomContext is true and no context Injection object is provided, the default custom context is fetched based on the API key (additional information).
Case 3: Use Custom Context From API/ SDK
The contextInjection object is optional, and all its fields are optional. You can provide additional company details for a more tailored chatbot experience . Any chunk of information added here will override the company default details (custom context) that are added from AI Hub.
Example Usage
Example 1: Using Minimal context/ chunk of context using SDK.
The following examples demonstrate how minimal context injection can be utilized to obtain the desired response. A code snippet can be added via the SDK to override specific information added from the AI Hub while preserving all other data.
Example 2: Using extended context injection using sdk.
The following examples demonstrate how detailed/ extended context injection can be utilized to obtain the desired response. A code snippet can be added via the SDK to override all the company information added from the AI Hub.
Additional Parameters Usage
We take inputs for various types of blockchains , Tones and styles , Social media links. The input are taken is following format to enhance the response generated by Chat bot
Blockchain Options
We support multiple blockchains to fetch and display crypto token information for chat interactions.
AI Tones
Our AI supports multiple tone options to customize responses based on user preferences. The following tone selection options are available:
DEFAULT_TONE // if we select DEFAULT_TONE then no need for customTone and selectedTone
CUSTOM_TONE // if we select CUSTOM_TONE then customTone text is required
PRE_SET_TONE // if we select PRE_SET_TONE then selectedTone is required
Preset AI Tones:
If PRE_SET_TONE is selected, users can choose from the following tones: If we select PRE_SET_TONE then we select given option:
Social Media Options
History Feature
Our chatbot SDK also stores the chat history for later usage. History is enabled/ Disabled within the code using Chat History function. If chat history is “On” it means that history of requests shall be saved and can be retrieved later . If the Chat History function is “Off” then History won’t be saved and can’t be accessed later.
Users can retrieve the history using the following code:
Pricing/Credits Deduction
In case of both stream and Blob Response , On sending each chat API request, 1 Credit will be deducted from the user account in AI HUB.
In addition, if user enables chat history feature, an additional 1 Credit will be deducted
Error Handling
When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), an error of the class GeneralChatError will be thrown:
Language/Framework Compatibility
Our SDK supports JavaScript language and will run on Node application
Security Considerations
To ensure the security, SDK is made accessible using an authentication key. User having credits in the web-app and valid API key shall e able to access the SDK
Request limitation has been handled to avoid any misuse. Users are allowed to make 200 requests per minute and on each request 1 credit shall be deducted.
Code Documentation
Please check out this link for SDK code documentation
https://www.npmjs.com/package/@chaingpt/generalchat
Support/Help
If you need further assistance, explore the available support channels provided in our website https://www.chaingpt.org/contact-us
Last updated
Was this helpful?