A C++ text game features ChatGPT API intergration. The options and the ending of the game are generated by ChatGPT randomly.
This project is a C++ text game that uses ChatGPT API to generate the options and the ending of the game.
The game is a simple text adventure game that takes place in National Taiwan University. You can choose options based on the situation happened in the game. The game will give you the ending based on your choices. The options and the ending are generated by ChatGPT randomly.
You can run this project with Docker. This is the easiest way to get started.
- Clone this repository:
git clone https://github.com/jschang19/chatcpp.git
cd chatcpp
-
Get your OpenAI token from here and set it as the
ENV
in theDockerfile
file ( or pass it as an argument todocker run
command later). -
Install Docker, then run the following commands:
docker build -t chatcpp . # this will take a while
docker run -it --env=OPENAI_API_KEY=<YOUR_OPENAI_API_KEY> chatcpp:latest # run with interactive mode
To develop this project, you need to install CMake and Vcpkg first.
- Export your OpenAI token to environment variable
export OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>
- Install dependencies with VCPKG
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
# Windows
./bootstrap-vcpkg.bat
# Mac/Linux
./bootstrap-vcpkg.sh
./vcpkg install nlohmann-json
./vcpkg install cpr
./vcpkg integrate install
- Build the project with CMake
rm -rf build
mkdir build
cmake -B build/ -S . -DCMAKE_TOOLCHAIN_FILE=/Users/liaohuizhong/Library/CloudStorage/OneDrive-個人/文件/大學/大學課業/大一上/程式設計/ntu-im-final-project/vcpkg/scripts/buildsystems/vcpkg.cmake
cd build
cmake --build .
xcvv/c/ 4. Run the project
./ChatBot
- Everytime you make changes to the code, you need to run
cmake --build .
in thebuild
folder again to rebuild the project.
cd build
cmake --build .
If getting error when running cmake --build .
in the build
folder, you need to update the vcpkg:
cd ~/vcpkg # or where you install vcpkg
git pull
rm -rf installed
./vcpkg install nlohmann-json
./vcpkg install cpr
Then run the cmake command again. You need to rm -rf build/
and build again.
- This project is still under developmentm and ChatGPT might return invalid json sometimes.
- This project uses gpt3.5 model with
json
formatted response. Check the official API for more details. - The reply generation is not very stable. You may see unrelevant options sometimes.
- This repository is based on deni2312/ChatGPT-Cpp
- Dockerize this C++ project with this article