Add OpenAI API key env config and interactive ChatGPT client#2
Merged
Conversation
Copilot created this pull request from a session on behalf of
boci11
July 2, 2026 02:28
View session
There was a problem hiding this comment.
Pull request overview
This PR adds a minimal OpenAI ChatGPT integration to the repo: dependency management (requirements.txt), environment-variable setup via .env conventions, and an interactive Python chat client runnable locally or in Docker.
Changes:
- Add Python dependencies for OpenAI + dotenv and install them in the Docker image.
- Add
chat.pyinteractive client that calls the Chat Completions API (gpt-4o-mini) usingOPENAI_API_KEY. - Document
.envsetup and usage in README, and ignore.envin git.
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| requirements.txt | Adds Python deps needed for the OpenAI client and dotenv loading. |
| README.md | Documents OpenAI key setup + how to run the chat locally and in Docker. |
| Dockerfile | Installs Python requirements during image build. |
| chat.py | Implements an interactive REPL that calls the OpenAI API. |
| .gitignore | Prevents committing local .env secrets. |
| .env.example | Provides a template for OPENAI_API_KEY. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+8
to
+9
| - `requirements.txt` z zależnościami (`openai`, `python-dotenv`). | ||
| - `chat.py` — prosty klient ChatGPT w trybie konwersacji. |
Comment on lines
+16
to
+35
| load_dotenv() | ||
|
|
||
| api_key = os.getenv("OPENAI_API_KEY") | ||
| if not api_key: | ||
| raise EnvironmentError( | ||
| "Brak klucza API. Ustaw OPENAI_API_KEY w pliku .env (patrz .env.example)." | ||
| ) | ||
|
|
||
| client = OpenAI(api_key=api_key) | ||
|
|
||
|
|
||
| def chat(message: str, model: str = "gpt-4o-mini") -> str: | ||
| """Wyślij wiadomość do ChatGPT i zwróć odpowiedź.""" | ||
| response = client.chat.completions.create( | ||
| model=model, | ||
| messages=[{"role": "user", "content": message}], | ||
| ) | ||
| if not response.choices or response.choices[0].message.content is None: | ||
| raise ValueError("API zwróciło pustą odpowiedź.") | ||
| return response.choices[0].message.content |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wires up the repo to the OpenAI ChatGPT API: environment variable management via
.env, a dependency manifest, and an interactive Python chat client.Changes
.gitignore— adds.envto prevent accidental key commits.env.example— template withOPENAI_API_KEYplaceholder; copy to.envand fill in key from platform.openai.com/api-keysrequirements.txt— pinsopenai>=1.0.0andpython-dotenv>=1.0.0chat.py— interactive REPL connecting togpt-4o-mini; loads key viadotenv, validates API response, handles per-turn API errors without crashing the loopDockerfile— addsCOPY requirements.txt+pip installlayer so the image ships with dependencies pre-installedUsage