Run a chatbot against a real OpenAI-compatible server.
#include "example_support.hpp"
#include <iostream>
#include <utility>
using namespace neuralplus;
using namespace neuralplus_examples;
namespace {
void usage() {
std::cout
<< "Chatbot for a real OpenAI-compatible Chat Completions server\n"
<< "Usage: neuralplus_openai_compatible_chatbot [options]\n"
<< " --base-url URL Server root, default http://localhost:8000/v1\n"
<< " --model ID Server model ID, default local-model\n"
<< " --api-key KEY Optional bearer token\n"
<< " --api-key-env NAME Read bearer token from this environment variable\n"
<< " --system TEXT Set the system instruction\n"
<< " --prompt TEXT Run one prompt instead of interactive mode\n"
<< " --help Show this message\n";
}
}
int main(int argc, const char* const* argv) {
try {
const Arguments arguments(
argc,
argv,
{"--base-url",
"--model",
"--api-key",
"--api-key-env",
"--system",
"--prompt"});
if (arguments.help()) {
usage();
return 0;
}
arguments.value_or("--model", "local-model"),
arguments.value_or(
"--base-url", "http://localhost:8000/v1"));
require_secure_base_url(config.base_url);
apply_api_key(arguments, config.api_key);
config.api_key_environment =
arguments.optional("--api-key-env");
"--system", "Be helpful, accurate, and concise.");
Session session(std::move(options));
return run_chatbot(
*client, session, arguments.optional("--prompt"));
} catch (const std::exception& error) {
return print_exception(error);
}
}
Definition session.hpp:106
NEURALPLUS_API std::unique_ptr< AIClient > make_client(OpenAIConfig config, const ClientOptions &options={})
Creates an OpenAI client. Credentials resolve as explicit value, environment, error.
Definition providers.hpp:96
Options used when creating or restoring a Session.
Definition session.hpp:91
std::optional< std::string > system_message
Provider-independent system instruction.
Definition session.hpp:96