API
Utilize our Rest API to handle user queries and whatnot!
You can find your unique API Endpoint and API Token in the API section available at the top. Also, add a website that can use this API to Allowed Hosts.
Below are some examples of different programming languages using Botsonic. Replace the values of the API endpoint and API token with your unique values that can be found in Embeddings> API.
fetch('<your-API-endpoint>', {
method: 'POST',
headers: {
'Accept-Encoding': 'gzip, deflate',
'Connection': 'keep-alive',
'Content-Type': 'application/json',
'User-Agent': 'python-requests/2.28.1',
'accept': 'application/json',
'token': '<Your Botsonic token>'
},
// body: '{"question": "How to develop these skills?", "chat_history": []}',
body: JSON.stringify({
'input_text': 'How to develop these skills?',
'chat_id': "a uuid"
})
});
import requests
headers = {
# 'Accept-Encoding': 'gzip, deflate',
'Connection': 'keep-alive',
# Already added when you pass json=
# 'Content-Type': 'application/json',
'User-Agent': 'python-requests/2.28.1',
'accept': 'application/json',
'token': '<Your Botsonic token>',
}
json_data = {
'question': 'How to develop these skills?',
'chat_history': [],
}
response = requests.post('<your-API-endpoint>', headers=headers, json=json_data)
package main
import (
"fmt"
"io"
"log"
"net/http"
"strings"
)
func main() {
client := &http.Client{}
var data = strings.NewReader(`{"question": "How to develop these skills?", "chat_history": []}`)
req, err := http.NewRequest("POST", "<your-API-endpoint>", data)
if err != nil {
log.Fatal(err)
}
// req.Header.Set("Accept-Encoding", "gzip, deflate")
req.Header.Set("Connection", "keep-alive")
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", "python-requests/2.28.1")
req.Header.Set("accept", "application/json")
req.Header.Set("token", "<Your Botsonic token>")
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
bodyText, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", bodyText)
}
import 'package:http/http.dart' as http;
void main() async {
var headers = {
'Accept-Encoding': 'gzip, deflate',
'Connection': 'keep-alive',
'Content-Type': 'application/json',
'User-Agent': 'python-requests/2.28.1',
'accept': 'application/json',
'token': '<Your Botsonic token>',
};
var data = '{"question": "How to develop these skills?", "chat_history": []}';
var url = Uri.parse('<your-API-endpoint>');
var res = await http.post(url, headers: headers, body: data);
if (res.statusCode != 200) throw Exception('http.post error: statusCode= ${res.statusCode}');
print(res.body);
}
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;
class Main {
public static void main(String[] args) throws IOException {
URL url = new URL("<your-API-endpoint>");
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Accept-Encoding", "gzip, deflate");
httpConn.setRequestProperty("Connection", "keep-alive");
httpConn.setRequestProperty("Content-Type", "application/json");
httpConn.setRequestProperty("User-Agent", "python-requests/2.28.1");
httpConn.setRequestProperty("accept", "application/json");
httpConn.setRequestProperty("token", "<Your Botsonic token>");
httpConn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
writer.write("{\"question\": \"How to develop these skills?\", \"chat_history\": []}");
writer.flush();
writer.close();
httpConn.getOutputStream().close();
InputStream responseStream = httpConn.getResponseCode() / 100 == 2
? httpConn.getInputStream()
: httpConn.getErrorStream();
if ("gzip".equals(httpConn.getContentEncoding())) {
responseStream = new GZIPInputStream(responseStream);
}
Scanner s = new Scanner(responseStream).useDelimiter("\\A");
String response = s.hasNext() ? s.next() : "";
System.out.println(response);
}
}
curl -X POST -H 'Accept-Encoding: gzip, deflate' -H 'Connection: keep-alive' -H 'Content-Type: application/json' -H 'User-Agent: python-requests/2.28.1' -H 'accept: application/json' -H 'token: <Your Botsonic token>' -d '{"question": "How to develop these skills?", "chat_history": []}' <your-API-endpoint>
const axios = require('axios');
const response = await axios.post(
'<your-API-endpoint>',
// '{"question": "How to develop these skills?", "chat_history": []}',
{
'question': 'How to develop these skills?',
'chat_history': []
},
{
headers: {
'Accept-Encoding': 'gzip, deflate',
'Connection': 'keep-alive',
'Content-Type': 'application/json',
'User-Agent': 'python-requests/2.28.1',
'accept': 'application/json',
'token': '<Your Botsonic token>'
}
}
);
The output would look something like this. To retain memory from previous chats, you can pass back the chat_history in the next request. Refer Above code examples for more details.
[{
"data": {
"answer": "Consistent practice, learning opportunities, courses, workshops, mentorship, and feedback are all great ways to improve your skills and knowledge. By actively seeking out these opportunities, you can stay up-to-date with the latest trends and techniques in your field, and develop a deeper understanding of your craft.",
"sources": "[{\"url\": \"https://bhagavadgita.ai/\", \"content\": \"Radhey Radhey, I am Gita AI, a repository of knowledge and wisdom. Allow me to assist you by answering any inquiries you may have. Ask me anything.\", \"id\": \"89a7cd8c-e460-4023-871b-d4aba7d58f54\"}, {\"url\": \"https://bhagavadgita.ai//\", \"content\": \"Radhey Radhey, I am Gita AI, a repository of knowledge and wisdom. Allow me to assist you by answering any inquiries you may have. Ask me anything.\", \"id\": \"ef751649-edb3-4751-86b0-4d26e01e0472\"}, {\"url\": \"https://bhagavadgita.ai//about\", \"content\": \"Do you ever feel like Sanatana Dharma websites and apps are stuck in the past? Like they're not keeping up with the times and don't appeal to younger generations?\\nAt the Ved Vyas Foundation, we are on a mission to change that!\\nWe are devoted to making the transcendental wisdom from the Indian scriptures accessible to anyone, anywhere, anytime. We do this by creating state-of-the-art web and mobile applications, educational content on social media as well as working with like-minded individuals and organisations.\\nWe believe that by making the ancient teachings of Sanatana Dharma relevant to modern life, we can inspire a new generation of Dharma followers and create a more compassionate and harmonious world.\\n\\ud83d\\udca1\\nIf you share our vision, we would love for you to join us in our mission to keep the Dharma alive and thriving!\\n\\ud83d\\udcac\\nReach out:\\nIf you are passionate about making a difference and want to help us in our mission, then we would love to have you on board!\\nHere are some ways in which you can contribute:\\nSo what are you waiting for? Get in touch with us today and let's work together to make a difference!\", \"id\": \"2ddafb5a-3fb7-41e6-97ff-a4c88d351f4a\"}]",
"chat_history": [{
"message": "How to develop these skills?",
"sent": true
}, {
"message": "To develop skills, it's important to practice consistently and seek out opportunities for learning and growth. This can include taking courses, attending workshops, seeking mentorship, and actively seeking feedback to improve.",
"sources": [],
"sent": false
}]
}
}]
Updated 9 months ago