Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/d7ead/liboai
A C++17 library to access the entire OpenAI API.
https://github.com/d7ead/liboai
ai api artificial-intelligence chatgpt chatgpt-api chatgpt3 dall-e generator gpt interface library machine-learning ml neural-network openai openai-api
Last synced: 2 months ago
JSON representation
A C++17 library to access the entire OpenAI API.
- Host: GitHub
- URL: https://github.com/d7ead/liboai
- Owner: D7EAD
- License: mit
- Created: 2022-12-23T18:54:25.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-22T23:17:00.000Z (6 months ago)
- Last Synced: 2024-08-02T01:25:38.419Z (6 months ago)
- Topics: ai, api, artificial-intelligence, chatgpt, chatgpt-api, chatgpt3, dall-e, generator, gpt, interface, library, machine-learning, ml, neural-network, openai, openai-api
- Language: C++
- Homepage: https://openai.com/api/
- Size: 885 KB
- Stars: 330
- Watchers: 12
- Forks: 55
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ChatGPT-repositories - liboai - A C++17 library to access the entire OpenAI API. (Openai)
README
Introduction
liboai
is a simple, unofficial C++17 library for the OpenAI API. It allows developers to access OpenAI endpoints through a simple collection of methods and classes. The library can most effectively be thought of as a spiritual port of OpenAI's Python library, simply calledopenai
, due to its similar structure - with few exceptions.Features
- [x] [ChatGPT](https://github.com/D7EAD/liboai/tree/main/documentation/chat)
- [X] [Audio](https://github.com/D7EAD/liboai/tree/main/documentation/audio)
- [X] [Azure](https://github.com/D7EAD/liboai/tree/main/documentation/azure)
- [X] [Functions](https://platform.openai.com/docs/api-reference/chat/create)
- [x] [Image DALL·E](https://github.com/D7EAD/liboai/tree/main/documentation/images)
- [x] [Models](https://github.com/D7EAD/liboai/tree/main/documentation/models)
- [x] [Completions](https://github.com/D7EAD/liboai/tree/main/documentation/completions)
- [x] [Edit](https://github.com/D7EAD/liboai/tree/main/documentation/edits)
- [x] [Embeddings](https://github.com/D7EAD/liboai/tree/main/documentation/embeddings)
- [x] [Files](https://github.com/D7EAD/liboai/tree/main/documentation/files)
- [x] [Fine-tunes](https://github.com/D7EAD/liboai/tree/main/documentation/fine-tunes)
- [x] [Moderation](https://github.com/D7EAD/liboai/tree/main/documentation/moderations)
- [X] Asynchronous SupportUsage
See below for just how similar in styleliboai
and its Python alternative are when generating an image using DALL-E.DALL-E Generation in Python.
```py
import openai
import osopenai.api_key = os.getenv("OPENAI_API_KEY")
response = openai.Image.create(
prompt="A snake in the grass!",
n=1,
size="256x256"
)
print(response["data"][0]["url"])
```DALL-E Generation in C++.
```cpp
#include "liboai.h"using namespace liboai;
int main() {
OpenAI oai;
oai.auth.SetKeyEnv("OPENAI_API_KEY");
Response res = oai.Image->create(
"A snake in the grass!",
1,
"256x256"
);std::cout << res["data"][0]["url"] << std::endl;
}
```Running the above will print out the URL to the resulting generated image, which may or may not look similar to the one found below.
Example Image
Keep in mind the above C++ example is a minimal example and is not an exception-safe snippet. Please see the documentation for more detailed and exception-safe code snippets.
Dependencies
For the library to work the way it does, it relies on two major dependencies. These dependencies can be found listed below.
- nlohmann-json
- cURL*If building the library using the provided solution, it is recommended to install these dependencies using vcpkg.*
Documentation
For detailed documentation and additional code examples, see the library's documentation here.
Contributing
Artificial intelligence is an exciting and quickly-changing field.
If you'd like to partake in further placing the power of AI in the hands of everyday people, please consider contributing by submitting new code and features via a **Pull Request**. If you have any issues using the library, or just want to suggest new features, feel free to contact me directly using the info on my profile or open an **Issue**.
Please note that all Pull Requests should target the [dev](https://github.com/D7EAD/liboai/tree/dev) branch where additions will be tested and pushed to `main` once finalized.