OpenAI api implementation in c++. This is a community-maintained library.
C++ library for calling OpenAI's api. Only one OpenAIService class implements all network requests.
it’s a "community-maintained" library and welcome anyone who holds interest in General Language Model to join us.
The library currently supports Windows, Linux and Android platforms.
SET(CMAKE_TOOLCHAIN_FILE "absolute/path/to/vcpkg.cmake")
install perl
install nasm and add nasm path to the environment variables list
open Visual Studio Developer Command Prompt with administrative privileges and find where vcvarsall.bat is.(you can use the commandline below and probably find it at "../visual_studio_2022/VC/Auxiliary/Build/")
find ../visual_studio_2022/ -name "vcvarsall*"
query your windows SDK version(open Visual Studio Installer and find the installed SDK's version)
go into the directory where vcvarsall.bat locates and input the commandline into the prompt
vcvarsall.bat <your computer soc's architecture> <windows SDK version>
From the root of the OpenSSL source directory enter perl Configure VC-WIN32 if you want 32-bit OpenSSL or perl Configure VC-WIN64A if you want 64-bit OpenSSL or perl Configure VC-WIN64-ARM if you want Windows on Arm (win-arm64) OpenSSL or perl Configure to let Configure figure out the platform
input the commandlines into the prompt
nmake
nmake test
nmake install
cd <curl root directory>
./buildconf.bat
cd winbuild
nmake /f Makefile.vc mode=static WITH_DEVEL=<path/to/your/installed/openssl/library> VC=14 WITH_SSL=static ENABLE_NGHTTP2=no ENABLE_SSPI=no ENABLE_IDN=no GEN_PDB=no ENABLE_WINSSL=no DEBUG=no MACHINE=<your computer soc's architecture>
SET(CURL_INCLUDE_DIR "path/to/curl/headers")
target_link_libraries(openai-cpp "path/to/libcurl_a.lib")
set system environment variable VCPKG_DEFAULT_TRIPLET=x64-windows
TODO
TODO
OpenAIService service{};
service.GetVersion();
service.InitClient("your API key", "your organization ID");
service.SetUpCAPath("absolute/path/to/SSL/CA");
service.UseCustomCA(true);
service.SetUpProxy("your proxy"); // e.g. http://127.0.0.1:7890
service.EnableProxy(true);
OpenAIModel *model = service.RetrieveModel("text-davinci-003");
printf("model owned by %s\n", model->owned_by.c_str());
// remember to delete the pointer after using
delete model;