chat
The 'chat' route is an essential part of the Flexibel API, allowing users to send questions to the AI chatbot and receive responses. This route is vital for real-time interaction with the chatbot, providing dynamic responses based on the provided question and conversation context.
POST https://api.flexibel.ai/v0/chat
Request
To send a question to the chatbot using curl:
curl https://api.flexibel.ai/v0/chat \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"question": "YOUR_QUESTION",
"history": "CONVERSATION_HISTORY",
"conversationId": "CONVERSATION_ID",
"temperature": TEMPERATURE_VALUE,
"relevanceThreshold": RELEVANCE_THRESHOLD,
"historyOn": true_or_false
}'
Response
The response includes the AI chatbot's answer to the submitted question:
{
"response": "AI_CHATBOT_RESPONSE"
}
Request Body
Below are the parameters that can be used in the request body for the chat route:
Parameter | Type | Required | Description |
---|---|---|---|
apiKey | string | yes | The necessary API key |
question | string | yes | The question asked to the chatbot |
conversationId | string | no | The id of the current conversation. If no id is provided a new conversation is created |
history | object | no | The conversation history, which helps in contextualizing the response. The previous history of the current conversation will be retrieved from the database. This parameter will replace the history from the database and should only be used if you want to provide your own conversation history. |
temperature | number | no | A value between 0 and 1 that determines the level of creativity and variance in the chatbot's answers. |
relevanceThreshold | number | no | A value between 0 and 1 to filter out sources below a specified relevance threshold. |
historyOn | boolean | no | Flag to determine if conversation history is considered. Defaults to true. |
History
The history parameter in the chat route plays a crucial role in providing context to the AI chatbot for more accurate and relevant responses. It's a list that chronicles the conversation's progression, including both user inputs and the chatbot's responses. Here's how you should structure the history list:
Structure
The history is an array of objects, where each object represents a message in the conversation. Each object should have two key properties: role and content.
- role: Specifies who the speaker is – either user, or assistant.
- content: Contains the actual text of the message.
Example
Here is an example of what a history list might look like:
[
{
role: "assistant",
content: "How can I be of assistance?",
},
{
role: "user",
content: "Hello!",
},
];
This route is pivotal for engaging with the Flexibel chatbot, allowing for dynamic and contextual conversations based on user queries. For managing the entire conversation lifecycle, refer to other routes like startChat, retrieveChat, and endChat.