Skip to content

Commit b399ee7

Browse files
committed
api key check upon execution
1 parent f672d82 commit b399ee7

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

main.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
BLUE = "\033[94m"
1414
RESET = "\033[0m"
1515

16-
openai.api_key = os.getenv("OPENAI_API_KEY", "YOUR-OPENAI-KEY-HERE")
16+
API_KEY = os.getenv("OPENAI_API_KEY", "")
1717

18-
if not openai.api_key:
18+
if not API_KEY:
1919
# in order to use application, you need to set OPENAI_API_KEY
2020
# provide example usage
2121
print(f"{RED}In order to use this application, you need to set OPENAI_API_KEY environment variable.{RESET}"
@@ -34,7 +34,6 @@ def call_openai_for_command(user_message, chat_history=None):
3434
if chat_history is None:
3535
chat_history = []
3636

37-
# We add a system message to instruct the model to return only valid shell commands, etc.
3837
system_msg = {
3938
"role": "system",
4039
"content": (
@@ -44,14 +43,11 @@ def call_openai_for_command(user_message, chat_history=None):
4443
"No explanations, just the command."
4544
)
4645
}
47-
# Then we add the user prompt
4846
user_msg = {"role": "user", "content": user_message}
4947

50-
# Construct the full message set
5148
messages = [system_msg] + chat_history + [user_msg]
5249

53-
# Call OpenAI API
54-
client = openai.OpenAI()
50+
client = openai.OpenAI(api_key=API_KEY)
5551

5652
try:
5753
response = client.chat.completions.create(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "ghost-in-the-shell"
3-
version = "0.1.4"
3+
version = "0.1.5"
44
description = "CLI with OpenAI integration"
55
readme = "README.md"
66
requires-python = ">=3.11"

0 commit comments

Comments
 (0)