Skip to content

jschang19/chatcpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChatGPT-Cpp

A C++ text game features ChatGPT API intergration. The options and the ending of the game are generated by ChatGPT randomly.

image

Introduction

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.

Table of Contents

Run with Docker

You can run this project with Docker. This is the easiest way to get started.

Steps

  1. Clone this repository:
git clone https://github.com/jschang19/chatcpp.git
cd chatcpp
  1. Get your OpenAI token from here and set it as the ENV in the Dockerfile file ( or pass it as an argument to docker run command later).

  2. 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

Development

To develop this project, you need to install CMake and Vcpkg first.

  1. Export your OpenAI token to environment variable
export OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>
  1. 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
  1. 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
  1. Everytime you make changes to the code, you need to run cmake --build . in the build folder again to rebuild the project.
cd build
cmake --build .

Update Vcpkg

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.

Reminder

  • 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.

References

About

NTU IM 2023 期末專案

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •