Skip to content

xhqm-xyz/openai-cpp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAI C++ library

Language Standard License Github worflow GitHub version

A lightweight header only modern C++ library

OpenAI-C++ library is a community-maintained library which provides convenient access to the OpenAI API from applications written in the C++ language.
The library is small with two header files (only one if you already use Nlohmann Json).

Requirements

No special requirement. You should already have these :

  • C++11/C++14/C++17/C++20 compatible compiler
  • libcurl (check Install curl to make sure you have the development package)

OpenAI C++ current implementation

The library should implement all requests on OpenAI references. If any are missing (due to an update), feel free to open an issue.

API reference Method Example file
API models List models 1-model.cpp
API models Retrieve model 1-model.cpp
API completions Create completion 2-completion.cpp
API edits Create completion 3-edit.cpp
API images Create image 4-image.cpp
API images Create image edit 4-image.cpp
API images Create image variation 4-image.cpp
API embeddings Create embeddings 5-embedding.cpp
API files List file 6-file.cpp
API files Upload file 6-file.cpp
API files Delete file 6-file.cpp
API files Retrieve file 6-file.cpp
API files Retrieve file content 6-file.cpp
API fine-tunes Create fine-tune 7-fine-tune.cpp
API fine-tunes List fine-tune 7-fine-tune.cpp
API fine-tunes Retrieve fine-tune 7-fine-tune.cpp
API fine-tunes Cancel fine-tune 7-fine-tune.cpp
API fine-tunes List fine-tune events 7-fine-tune.cpp
API fine-tunes Delete fine-tune model 7-fine-tune.cpp
API chat Create chat completion 10-chat.cpp
API audio Create transcription 11-audio.cpp
API audio Create translation 11-audio.cpp
API moderation Create moderation 12-moderation.cpp

Installation

The library consists of three files: https://github.com/xhqm-xyz/openai-cpp https://github.com/yhirose/cpp-httplib https://github.com/nlohmann/json

License

MIT

对比

基于httplib的版本优势:

  1. 代码简洁性和现代性 • 使用C++11/14现代特性,代码更简洁 • 智能指针管理资源,减少内存泄漏风险 • 更符合现代C++编程风格

  2. 依赖管理 • 只需单个头文件依赖,更容易集成 • 无需预编译库,构建更简单

  3. 错误处理 • 异常安全性更好 • 更清晰的错误信息传递

  4. 性能 • 更轻量级的实现 • 减少系统调用开销 • 更好的连接复用

基于libcurl的版本优势:

  1. 成熟度和稳定性 • libcurl是经过长期验证的稳定库 • 支持更多HTTP协议特性 • 更好的SSL/TLS支持

  2. 功能完整性 • 支持更多高级HTTP特性 • 更好的代理支持 • 更完善的multipart/form-data处理

  3. 平台兼容性 • 在旧系统上兼容性更好 • 对Windows平台支持更成熟 • 更好的SSL证书处理

  4. 调试和监控 • 更详细的错误信息 • 更好的调试支持 • 更成熟的性能优化

About

OpenAI C++接口 使用httplib库替换libcurl,使系统依赖更加简洁

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C++ 100.0%