File tree Expand file tree Collapse file tree 1 file changed +2
-35
lines changed
Expand file tree Collapse file tree 1 file changed +2
-35
lines changed Original file line number Diff line number Diff line change @@ -569,21 +569,9 @@ Next, install the latest openai package:
569569pip 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
623590Making 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.
You can’t perform that action at this time.
0 commit comments