https://github.com/niftycode/ai-chatbot
Fetch Python related answers from OpenAI using the OpenAI api
https://github.com/niftycode/ai-chatbot
openai-api python tkinter
Last synced: about 1 year ago
JSON representation
Fetch Python related answers from OpenAI using the OpenAI api
- Host: GitHub
- URL: https://github.com/niftycode/ai-chatbot
- Owner: niftycode
- License: mit
- Created: 2023-11-14T09:55:20.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-14T12:47:11.000Z (about 1 year ago)
- Last Synced: 2025-02-14T13:41:30.198Z (about 1 year ago)
- Topics: openai-api, python, tkinter
- Language: Python
- Homepage:
- Size: 2.12 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# ai-chatbot



[](https://github.com/psf/black)


This chatbot is using the OpenAI API to fetch **Python** related answers.
The program is inspired by an article from [heise.de](https://www.heise.de/ratgeber/Python-Eigene-KI-Programmierhilfe-entwickeln-9330993.html). In contrast to the code in the article, the new API (> 1.0.0) is used here.
Information on how to use the new API can be found on Github:
[v1.0.0 Migration Guide #742](https://github.com/openai/openai-python/discussions/742)
In the [heise.de](https://www.heise.de/ratgeber/Python-Eigene-KI-Programmierhilfe-entwickeln-9330993.html) code, the API key is hard coded. In the code used here, however, it is stored in a **binary file**. By default the key is located in
> ~/Documents/API/openai-api-file.bin
This deviates from the suggestion shown [on Github](https://github.com/openai/openai-python/discussions/742)
. Because `os.environ` is used there:
from openai import OpenAI
client = OpenAI(
api_key=os.environ['OPENAI_API_KEY'],
)
**Tip**: You can create a binary file in Python using this code:
# initialize string
api_key = "API_KEY"
# open file as a binary file
f = open('openai-api-file', 'wb')
# convert string to bytes
strBytes = api_key.encode()
# write byte string to binary file
f.write(strBytes)
f.close()
## Operating System
* macOS
* Linux
* Windows (not tested, but should work too)
## Requirements
* Python >= 3.12
* openai >= 1.0.0
* OpenAI API Key
## Additional Notes
This repository contains a spec file that allows you to create an executable with [PyInstaller](https://pyinstaller.org/en/stable/). This requires `pyinstaller` to be installed:
```Bash
pip3 install pyinstaller
```