Chat V1 Response

Example response for Chat V1 API


Brutus AI api response documentation, the api is reference is available at Chat API.

API Request Precap

When sending a request to the /v1/chat/completions endpoint, you need to include the following information in the request body:

  • /v1/chat/completions: This endpoint allows you to query the BrutusAI search engine and retrieve relevant search results based on the user's query.

    It accepts a history parameter, which is a list of of previous messages in the conversation, and other parameters such as search_mode, image_result, and search_result are also available.

    Parameters such as search_mode, image_result, and search_result are optional and can be used to customize the search results.

    By default, the search_mode is set to auto, image_result and search_result are set to 4. That means the API would automatically determine based on conversation if it's required to generate search results or not, and it would return 4 search results and 4 image results. Many times, if conversation includes general meesages like "Hi there", "How are you?", "I am good", etc, then it's not required to generate search results.

  • So the example request to the /v1/chat/completions endpoint would look like this:

import http.client
import json
 
conn = http.client.HTTPSConnection("brutusai.com")
payload = json.dumps({
    "history": [
    {
        "content": "When is America's next general election?",
        "role": "user"
    }
    ],
})
headers = {
    'x-api-key': 'your_api_key',
    'Content-Type': 'application/json'
}
conn.request("POST", "/api/v1/chat/completions", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

Example request without the optional fields

  • So the example request to the /v1/chat/completions without the optional parameters would look like:

    import http.client
    import json
     
    conn = http.client.HTTPSConnection("brutusai.com")
    payload = json.dumps({
        "history": [
        {
            "content": "When is America's next general election?",
            "role": "user"
        }
        ]
    })
    headers = {
        'x-api-key': 'your_api_key',
        'Content-Type': 'application/json'
    }
    conn.request("POST", "/api/v1/chat/completions", payload, headers)
    res = conn.getresponse()
    data = res.read()
    print(data.decode("utf-8"))

Example Response

  • Example response from the /v1/chat/completions endpoint be something like this:

    {
        "data": {
            "history": [
                {
                    "content": "When is America's next general election?",
                    "role": "user"
                },
                {
                    "content": "The next general election in America is the 2024 United States presidential election, where incumbent President Joe Biden, a member of the Democratic Party, is running for re-election. His predecessor Donald Trump, a member of the Republican Party, is also expected to participate in the election. The election is scheduled for a date in 2024, and more information can be found on the Wikipedia page dedicated to the 2024 United States presidential election. Additionally, a PDF document highlighting key dates related to the 2024 elections, including the presidential qualifying date, is available for further reference.",
                    "image_result": "[{\"title\": \"General Election\", \"imageUrl\": \"https://www.votecalhounfl.gov/portals/calhoun/Images/2024revElectionDates.jpg?ver=xwPVS3zdnC5VFXsU9QoTgw%3D%3D\", \"link\": \"https://www.votecalhounfl.gov/portals/calhoun/Images/2024revElectionDates.jpg?ver=xwPVS3zdnC5VFXsU9QoTgw%3D%3D\", \"snippet\": \"General Election\"}, {\"title\": \"Chart: 2024: The Super Election Year | Statista\", \"imageUrl\": \"http://cdn.statcdn.com/Infographic/images/normal/31604.jpeg\", \"link\": \"http://cdn.statcdn.com/Infographic/images/normal/31604.jpeg\", \"snippet\": \"Chart: 2024: The Super Election Year | Statista\"}, {\"title\": \"US 2024 presidential election: Dates, candidates and latest issues ...\", \"imageUrl\": \"https://cloudfront-us-east-2.images.arcpublishing.com/reuters/5ARS5ZBCEVK5DP6JSVWL6XGPR4.jpg\", \"link\": \"https://cloudfront-us-east-2.images.arcpublishing.com/reuters/5ARS5ZBCEVK5DP6JSVWL6XGPR4.jpg\", \"snippet\": \"US 2024 presidential election: Dates, candidates and latest issues ...\"}, {\"title\": \"US Presidential Elections 2024: Key dates and events, what lies ...\", \"imageUrl\": \"https://img.etimg.com/thumb/width-1200,height-900,imgsize-41570,resizemode-75,msid-106923480/news/international/world-news/us-presidential-elections-2024-key-dates-and-events-what-lies-ahead.jpg\", \"link\": \"https://img.etimg.com/thumb/width-1200,height-900,imgsize-41570,resizemode-75,msid-106923480/news/international/world-news/us-presidential-elections-2024-key-dates-and-events-what-lies-ahead.jpg\", \"snippet\": \"US Presidential Elections 2024: Key dates and events, what lies ...\"}]",
                    "peopleAlsoAsk": "[]",
                    "role": "assistant",
                    "search_result": "[{\"title\": \"2024 United States presidential election - Wikipedia\", \"link\": \"https://en.wikipedia.org/wiki/2024_United_States_presidential_election\", \"snippet\": \"Incumbent President Joe Biden, a member of the Democratic Party, is running for re-election. His predecessor Donald Trump, a member of the Republican Party, is ...\"}, {\"title\": \"[PDF] 2024 ELECTIONS\", \"link\": \"https://www.sos.la.gov/ElectionsAndVoting/PublishedDocuments/ElectionsCalendar2024.pdf\", \"snippet\": \"***Early voting advanced one day due to the state observed holiday for Thanksgiving and Acadian Day. PRESIDENTIAL QUALIFYING. 3/23/2024 Presidential Preference ...\"}]"
                }
            ]
        },
        "message": "Success"
    }

Understanding Response

  • Understanding the response:

    The history field contains the response to the user's query, it's the part of history. So it will include conversation history.

    • The history is list of objects, each object contains the content field which contains the response to the user's query, the role field which contains the role of the message, it can be either user or assistant.
    • The other fields such as image_result, search_result, and peopleAlsoAsk are optional and contain the search results and related questions.
    • The image_result field contains a list of image results related to the user's query.
    • The search_result field contains a list of search results related to the user's query.
    • The peopleAlsoAsk field contains a list of related questions that the user might be interested in. This is only generated when ai detects that user might be interested in related questions.