The script will:
- Connect to OpenAI's API using your key
- Send a prompt requesting a chain-of-thought response
- Save the response in JSON format to
results_raw.json
- Create a new conda environment from the provided
environment.ymlfile:
conda env create -f environment.yml- Activate the environment:
conda activate cot- Create a
.envfile in the root directory with your OpenAI API key:
OPENAI_API_KEY=your_api_key_hereThe script generates a results_raw.json file containing the structured response from GPT-4, with steps of reasoning and the final result.
You can modify the prompt variable in cot.py to ask different questions or adjust the response format as needed.
- If you get an import error for
dotenv, make sure you've installedpython-dotenv - If you get an import error for
openai, make sure you've installedopenai==0.28.0 - If you get an API key error, check that your
.envfile exists and contains the correct key - If you get a rate limit error, you may need to wait before making more API calls
This chain of thought example is licensed under the MIT License
Copyright (c) 2025 [Davide Mastricci]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.