https://github.com/janhkrueger/openai-api-cpp
https://github.com/janhkrueger/openai-api-cpp
cpp demo openai openai-api
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/janhkrueger/openai-api-cpp
- Owner: janhkrueger
- Created: 2023-08-29T22:58:04.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-11T10:11:10.000Z (almost 3 years ago)
- Last Synced: 2025-04-07T10:45:06.226Z (about 1 year ago)
- Topics: cpp, demo, openai, openai-api
- Language: C++
- Homepage: https://gitlab.com/janhkrueger/openai-api-cpp
- Size: 154 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# openai-api-cpp
## Introduction
A short demo how to use the OpenAI api via a C++ program based on [olrea/openai-cpp](https://github.com/olrea/openai-cpp)
Also included [nlohmann/json](https://github.com/nlohmann/json) as dependency for openai-cpp.
For reading the config value, [jbeder/yaml-cpp](https://github.com/jbeder/yaml-cpp) is used.
The entire project can be build and run inside Visual Studio Code and the shipped dev container.
## Create the dev container
When using Visual Studio Code with the Dev Container Plugin, upon opening the repository the IDE will recognize the devcontainer config under .devcontainer and ask if the repository should restarted and opened in the container. Do this and everything needed to build and run the application will be at hand.
## Adjust the config file
The shipped config file consists of:
```yaml
openai:
model: davinci-002
prompt: Say this is a test.
max_tokens: 9
temperature: 0
loglevel:
level: info
```
Feel free to adjust the model and the prompt regarding the desired question send to openai.
It is only intended to act as a sample, not as a production ready application.
## Compile the application
```bash
make -f build/makefile
```
## Set the environment variable with the openai token
```bash
export OPENAI_API_KEY='sk-abcdefghijklmnopqrstuvwxyz1234567890'
```
## Run the application
Then you can run the application with
```bash
bin/main
```
## Sample Prompt and Response
In the folder **samples** there are the sample json send to openai and the response.
## Project status
Finished. It is only there to demonstrate the usage.