This is a simple chat app for oTree that allows participants to chat with a predefined ChatGPT personality using OpenAI's API. Please feel free to leave any feedback or open an issue if you spot a problem. A short blogpost on using this app can be found here!
You can use the system prompt to adjust the tendencies of the personality you want participants to speak to. Here is an example system prompt:
And what this looks like when chatting:
The app is set to randomize participants to view one of two personalities. You can adjust these or provide more/less as desired.
To use this, you will need to acquire a key from OpenAI's API. Add this as an environment variable to your local environment. If using on Heroku, you can use this command to add it to your application:
heroku config:add CHATGPT_KEY=sk-.....
When using locally, you will also need to install openai's Python package. Be sure to add this to your requrements.txt file before using online.
openai==0.27.0
Currently, I have this set up to use gpt-3.5-turbo. You can adjust this model and the temperature in the _init_.py file:
The text logs are saved in participant fields, but I also made a simple custom export function. This can be accessed in the "data" tab in oTree and will show the chat logs as a long-form csv.
As part of oTree's installation agreement, be sure to cite their paper:
- Chen, D.L., Schonger, M., Wickens, C., 2016. oTree - An open-source platform for laboratory, online and field experiments. Journal of Behavioral and Experimental Finance, vol 9: 88-97.
If this app was helpful, you may consider citing this github repository as well.
- McKenna, C., (2023). oTree GPT. https://github.com/clintmckenna/oTree_gpt