From 1c81f72ede549d3dbf54000c567d723013615df2 Mon Sep 17 00:00:00 2001 From: senthil-securelytix Date: Mon, 9 Mar 2026 13:13:02 +0530 Subject: [PATCH] Rename CHATGPT_API_KEY to OPENAI_API_KEY This PR renames the environment variable and internal constant CHATGPT_API_KEY to OPENAI_API_KEY across the codebase. This change aligns the project with standard OpenAI naming conventions and improves consistency in API key management. --- README.md | 2 +- pageindex/utils.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7180efd5a..f9e82a237 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,7 @@ pip3 install --upgrade -r requirements.txt Create a `.env` file in the root directory and add your API key: ```bash -CHATGPT_API_KEY=your_openai_key_here +OPENAI_API_KEY=your_openai_key_here ``` ### 3. Run PageIndex on your PDF diff --git a/pageindex/utils.py b/pageindex/utils.py index dc7acd888..45a321339 100644 --- a/pageindex/utils.py +++ b/pageindex/utils.py @@ -17,7 +17,7 @@ from pathlib import Path from types import SimpleNamespace as config -CHATGPT_API_KEY = os.getenv("CHATGPT_API_KEY") +OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") def count_tokens(text, model=None): if not text: @@ -26,7 +26,7 @@ def count_tokens(text, model=None): tokens = enc.encode(text) return len(tokens) -def ChatGPT_API_with_finish_reason(model, prompt, api_key=CHATGPT_API_KEY, chat_history=None): +def ChatGPT_API_with_finish_reason(model, prompt, api_key=OPENAI_API_KEY, chat_history=None): max_retries = 10 client = openai.OpenAI(api_key=api_key) for i in range(max_retries): @@ -58,7 +58,7 @@ def ChatGPT_API_with_finish_reason(model, prompt, api_key=CHATGPT_API_KEY, chat_ -def ChatGPT_API(model, prompt, api_key=CHATGPT_API_KEY, chat_history=None): +def ChatGPT_API(model, prompt, api_key=OPENAI_API_KEY, chat_history=None): max_retries = 10 client = openai.OpenAI(api_key=api_key) for i in range(max_retries): @@ -86,7 +86,7 @@ def ChatGPT_API(model, prompt, api_key=CHATGPT_API_KEY, chat_history=None): return "Error" -async def ChatGPT_API_async(model, prompt, api_key=CHATGPT_API_KEY): +async def ChatGPT_API_async(model, prompt, api_key=OPENAI_API_KEY): max_retries = 10 messages = [{"role": "user", "content": prompt}] for i in range(max_retries):