Ask
Overview
To initiate or continue a chat against the bot you have created with Lexy
Authentication
To access this API, you need to include your Bot Token in the JSON body of your HTTP requests.
You can get the bot token Here
Request
--request POST 'https://server.lexy.so/api/bot/ask'
Body Attributes
Parameter | Type | Description |
---|---|---|
token | string | The bot token that you need to ask questions against. You can learn how to get bot token Here |
query | string | The question or request you want to ask the bot |
chatHistory | ChatMessageInput[] | The chat history of the conversation that you want to pass in |
ChatHistory Type
interface ChatMessageInput {
role: string!; // "assistant" | "user"
content: string; // typically your message and questions
}
ChatHistoryInput Example:
[
{
role: "user",
content: "What is Lexy?",
},
{
role: "assistant",
content:
"Lexy is a powerful AI chatbot that acts as your quick knowledge wiki and responds questions for you!",
},
];
Example
Body
{
query: "How will Lexy help me with my company?";
token: "(YOUR BOT TOKEN HERE)";
chatHistory: [
{
role: "user",
content: "What is Lexy?",
},
{
role: "assistant",
content:
"Lexy is a powerful AI chatbot that acts as your quick knowledge wiki and responds questions for you!",
},
];
}
Request
var body = JSON.stringify({
query: "How will Lexy help me with my company?"
token: "(YOUR BOT TOKEN HERE)"
chatHistory: [
{
role: "user",
content: "What is Lexy?"
},
{
role: "assistant",
content: "Lexy is a powerful AI chatbot that acts as your quick knowledge wiki and responds questions for you!"
}
]
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: body,
};
const res = await fetch("https://server.lexy.so/api/bot/ask", {
body,
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
});
const response = res.json()
Response
{
"success": true,
"res": {
"role": "assistant",
"content": "Lexy AI is a game-changer for businesses as it offers several benefits. \n
1. Improved Conversion Rates: Lexy provides instant responses to customer inquiries, keeping prospects engaged and moving them forward in their buyer journey. This helps businesses improve their conversion rates and speed up their sales cycle \n
2. Personal Shopper and Assistant: Lexy is not just a chatbot, but a powerful AI assistant that learns and improves over time. In the future, Lexy will have the ability to upsell products, take orders, and complete actions right from the chat interface, essentially functioning as a personal shopper or assistant for customers. This streamlines the customer journey and improves the bottom line."
},
"err": "",
"code": 200
}
Potential Errors
Bot Not Found
{
success: false,
res: undefined,
err: "Bot not found"
code: 400,
};
Vector Store Not Found
{
success: false,
res: undefined,
err: "Vector store not found"
code: 400,
};
User Limit Exceeded
{
success: false,
res: undefined,
err: "User message limit exceeded. Upgrade your plan to continue using Lexy."
code: 400,
};