Skip to content

Commit 1a14a4c

Browse files
committed
trim sections
1 parent 4f1ed1d commit 1a14a4c

File tree

1 file changed

+2
-35
lines changed

1 file changed

+2
-35
lines changed

docs/getting_started/chatapp_tutorial.md

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -569,21 +569,9 @@ Next, install the latest openai package:
569569
pip install --upgrade openai
570570
```
571571

572+
Direct Configuration of API in Code
572573

573-
There are two ways to configure your OpenAI API key:
574-
575-
Option 1: Environment Variable (Recommended)
576-
577-
Set your API key as an environment variable named OPENAI_API_KEY:
578-
579-
```bash
580-
export OPENAI_API_KEY="your-api-key-here"
581-
```
582-
583-
584-
Option 2: Direct Configuration in Code
585-
586-
If you prefer to set it in code, you can update the state.py file to include your API key directly:
574+
Update the state.py file to include your API key directly:
587575

588576
```python
589577
# state.py
@@ -597,27 +585,6 @@ client = AsyncOpenAI(api_key="YOUR_OPENAI_API_KEY") # Replace with your actual
597585

598586
```
599587

600-
Alternative Setup with Environment Variables
601-
602-
For better security practice, you can modify your state.py to check for environment variables first:
603-
604-
```python
605-
# state.py
606-
import os
607-
from openai import AsyncOpenAI
608-
609-
import reflex as rx
610-
611-
# Initialize the OpenAI client with API key from environment or use default
612-
api_key = os.environ.get("OPENAI_API_KEY", "YOUR_OPENAI_API_KEY")
613-
client = AsyncOpenAI(api_key=api_key)
614-
615-
class State(rx.State):
616-
# Code continues as above...
617-
```
618-
619-
620-
621588
### Using the API
622589

623590
Making your chatbot intelligent requires connecting to a language model API. This section explains how to integrate with OpenAI's API to power your chatbot's responses.

0 commit comments

Comments
 (0)