Skip to content

Commit 5c68943

Browse files
Added some documentation
1 parent fdf279c commit 5c68943

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
OPENAI_API_KEY=
1+
OPENAI_API_KEY=
22
ASSISTANT_ID=

README.md

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,21 @@ git clone https://github.com/Promptly-Technologies-LLC/openai-assistants-python-
1313
cd openai-assistants-python-quickstart
1414
```
1515

16-
### 2. Set your [OpenAI API key](https://platform.openai.com/api-keys)
17-
18-
```shell
19-
cp .env.example .env
20-
```
21-
22-
### 3. Install dependencies
16+
### 2. Install dependencies
2317

2418
```shell
2519
uv venv
2620
uv pip install -r pyproject.toml
2721
```
2822

29-
### 4. Create an assistant
23+
### 3. Run the FastAPI server
3024

3125
```shell
32-
uv run create_assistant.py
26+
uv run uvicorn main:app --host 0.0.0.0 --port 8000 --reload
3327
```
3428

35-
### 5. Run the FastAPI server
29+
### 4. Navigate to [http://localhost:8000](http://localhost:8000).
3630

37-
```shell
38-
uv run uvicorn main:app --host 0.0.0.0 --port 8000 --reload
39-
```
31+
### 5. Set your OpenAI API key and create an assistant in the GUI
4032

41-
### 6. Navigate to [http://localhost:8000](http://localhost:8000).
33+
If your OPENAI_API_KEY or ASSISTANT_ID are not set, you will be redirected to the setup page where you can set them. (The values will be saved in a .env file in the root of the project.) Once set, you will be redirected to the home page and can begin a chat session.

utils/create_assistant.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,23 @@ def update_env_file(var_name: str, var_value: str, logger: logging.Logger):
5252
var_value: The value to set for the environment variable
5353
logger: Logger instance for output
5454
"""
55+
lines = []
56+
# Read existing contents if file exists
5557
if os.path.exists('.env'):
5658
with open('.env', 'r') as env_file:
5759
lines = env_file.readlines()
5860

5961
# Remove any existing line with this variable
6062
lines = [line for line in lines if not line.startswith(f"{var_name}=")]
63+
else:
64+
# Log when we're creating a new .env file
65+
logger.info("Creating new .env file")
6166

62-
# Write back the modified lines
63-
with open('.env', 'w') as env_file:
64-
env_file.writelines(lines)
65-
66-
# Write the new variable to the .env file
67-
with open('.env', 'a') as env_file:
67+
# Write back all lines including the new variable
68+
with open('.env', 'w') as env_file:
69+
env_file.writelines(lines)
6870
env_file.write(f"{var_name}={var_value}\n")
71+
6972
logger.debug(f"Environment variable {var_name} written to .env: {var_value}")
7073

7174

0 commit comments

Comments
 (0)