Interactove Sample with AI Chatbot.
#include <cstdlib>
#include <iostream>
#include <string>
{
std::cout << "AI Chatbot - Type 'q' or 'quit' or 'exit' to stop" << std::endl;
std::cout << "==========================================" << std::endl;
{
std::cerr << "Failed to create Context" << std::endl;
return EXIT_FAILURE;
}
{
std::cerr << "Failed to create Graph" << std::endl;
return EXIT_FAILURE;
}
{
std::cerr << "Failed to create input string array" << std::endl;
return EXIT_FAILURE;
}
{
std::cerr << "Failed to create output string array" << std::endl;
return EXIT_FAILURE;
}
{
std::cerr << "Failed to get AI chatbot kernel. Make sure AI server target is loaded." << std::endl;
return EXIT_FAILURE;
}
{
std::cerr << "Failed to create chatbot node" << std::endl;
return EXIT_FAILURE;
}
std::string query;
while (true)
{
std::cout << "\nYou: ";
std::getline(std::cin, query);
if (query == "quit" || query == "exit" || query == "q")
{
std::cout << "Goodbye!" << std::endl;
break;
}
if (query.empty())
{
std::cout << "Please enter a question or type 'quit' to exit." << std::endl;
continue;
}
{
std::cerr << "Failed to clear input array" << std::endl;
continue;
}
{
std::cerr << "Failed to clear output array" << std::endl;
continue;
}
if (input_string->addItems(query.length() + 1, query.c_str(),
sizeof(
char)) !=
VX_SUCCESS)
{
std::cerr << "Failed to add input query to array" << std::endl;
continue;
}
{
std::cerr << "Failed to process graph" << std::endl;
continue;
}
auto num_items = output_string->numItems();
if (num_items > 0)
{
void *data_ptr = nullptr;
size_t stride = 0;
{
const char *response = static_cast<const char*>(data_ptr);
std::cout << "AI: " << std::string(response, num_items) << std::endl;
}
else
{
std::cerr << "Failed to access output data" << std::endl;
}
}
else
{
std::cout << "AI: No response received from AI server" << std::endl;
}
}
return EXIT_SUCCESS;
}
CoreVX single-include header for C++ development.
int main()
Definition blur_pipeline.cpp:15
@ VX_TYPE_CHAR
A vx_char.
Definition vx_types.h:435
@ VX_SUCCESS
No error.
Definition vx_types.h:543
@ VX_READ_ONLY
The memory shall be treated by the system as if it were read-only. If the User writes to this memory,...
Definition vx_types.h:1515
@ VX_KERNEL_AIS_CHATBOT
The AI Model Server Chatbot kernel.
Definition vx_corevx_ext.h:243
static vx_array createArray(vx_context context, vx_enum item_type, vx_size capacity, vx_bool is_virtual=vx_false_e, vx_enum type=VX_TYPE_ARRAY)
Create a Array object.
static vx_context createContext()
Create a new context.
static vx_status getStatus(vx_reference ref)
Provides a generic API to return status values from Object constructors if they fail.
static vx_graph createGraph(vx_context context)
Create a graph.
static vx_kernel getKernelByEnum(vx_context context, vx_enum kernelenum)
Get the Kernel By Enum.
static vx_node createNode(vx_graph graph, vx_kernel kernel)
Create a new node.
The internal representation of a vx_array.
Definition vx_array.h:34