Skip to content

Add OpenAI API key env config and interactive ChatGPT client#2

Merged
boci11 merged 2 commits into
mainfrom
copilot/dodaj-plik-ze-zmienna-srodowiskowa
Jul 2, 2026
Merged

Add OpenAI API key env config and interactive ChatGPT client#2
boci11 merged 2 commits into
mainfrom
copilot/dodaj-plik-ze-zmienna-srodowiskowa

Conversation

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

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 .env to prevent accidental key commits
  • .env.example — template with OPENAI_API_KEY placeholder; copy to .env and fill in key from platform.openai.com/api-keys
  • requirements.txt — pins openai>=1.0.0 and python-dotenv>=1.0.0
  • chat.py — interactive REPL connecting to gpt-4o-mini; loads key via dotenv, validates API response, handles per-turn API errors without crashing the loop
  • Dockerfile — adds COPY requirements.txt + pip install layer so the image ships with dependencies pre-installed

Usage

cp .env.example .env       # add real key
pip install -r requirements.txt
python chat.py
# or in Docker:
docker build -t codex-workspace .
docker run --rm -it --env-file .env -v "$(pwd):/workspace" codex-workspace

@boci11 boci11 marked this pull request as ready for review July 2, 2026 02:58
Copilot AI review requested due to automatic review settings July 2, 2026 02:58
@boci11 boci11 merged commit 547ad73 into main Jul 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py interactive client that calls the Chat Completions API (gpt-4o-mini) using OPENAI_API_KEY.
  • Document .env setup and usage in README, and ignore .env in 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 thread README.md
Comment on lines +8 to +9
- `requirements.txt` z zależnościami (`openai`, `python-dotenv`).
- `chat.py` — prosty klient ChatGPT w trybie konwersacji.
Comment thread chat.py
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
Comment thread chat.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants