Use Botsonic Chatbot With Rest API

Outline

    Original Post

    Use Botsonic Chatbot With Rest API


    Botsonic is a great product of Writesonic. I used it to create a chatbot using ChatGPT 4 model, and then request API with Python. However, there are some obstacles you may need to overcome.

    Business Plan

    On the pricing page, you can see that the free and plus plans are unable to access the API. You need to upgrade to the business plan.


    The Right Way To Send A Request

    Perhaps Botsonic evolves too fast, so some documents are outdated. For example, when you generate a Rest API, get the Endpoint and API token, and then click “View docs” button to redirect to the documents.

    You will get a sample code. Everything seems perfect.

    However, when you run the code in your Python editor, you will get an 422 error message:

    {"detail":"Invalid Token"} <Response [422]> {"detail":[{"loc":["body"],"msg":"field required","type":"value_error.missing"}]}

    The solution is in the next tab, API Reference. On this page, you can find some required parameters that are not mentioned in the sample code. For example, chat_id and chat_history are required, you need to add them to the JSON.

    Here is the complete Python code and response:

    import uuid
    import requests
    endpoint = "your endpoint"
    token = "your token"
    payload = {
        "input_text": "How to develop these skills? please answer.",
        "chat_id": str(uuid.uuid4()),
        "chat_history": [
            {
                "sent": True,
                "sources": [
                    {
                        "newKey": "New Value",
                        "newKey2": "New Value"
                    }
                ],
                "message": "previous message"
            }
        ]
    }
    headers = {
        "accept": "application/json",
        "content-type": "application/json",
        "token": token
    }
    response = requests.post(endpoint, json=payload, headers=headers)
    print(response)
    # <Response [200]>
    print(response.text)
    # <Response [200]>
    # {"answer":"To develop skills like humor, cleverness, and extensive knowledge for live streaming, engage in diverse reading, practice improvisation, study successful streamers, participate in workshops or courses on communication and comedy, and consistently interact with your audience to refine your approach based on feedback.","sources":[],"chat_history":[{"message":"How to develop these skills? please answer in English.","sent":true,"sources":null,"generated_images":null},{"message":"To develop skills like humor, cleverness, and extensive knowledge for live streaming, engage in diverse reading, practice improvisation, study successful streamers, participate in workshops or courses on communication and comedy, and consistently interact with your audience to refine your approach based on feedback.","sent":false,"sources":[],"generated_images":null}],"generated_images":null,"follow_up_questions":["What resources are needed to develop skills?","What is the process to develop skills?"]}
    


    Related Posts

    Aron

    A data scientist working in a retail company, with experience in web design and marketing. Recently dives into cryptocurrency and quantitative investing.

    facebook telegram

    Leave a Reply

    • Required fields are market * .
    • Your email address will not be published.
    • Please ensure your email address is correct, then you will get a notification once a new comment reply.

    Your email address will not be published. Required fields are marked *