Move API credentials to .env and set gpt-5.6-luna model
- Load OPENAI_API_KEY and OPENAI_BASE_URL from gitignored .env (repo-root, CWD-independent) - Fix command explanation to use the configured model instead of hardcoded gpt-4o-mini - Update default model and fallbacks to gpt-5.6-luna - Document .env-based configuration in READMEs
This commit is contained in:
@@ -11,6 +11,31 @@ from edison.utils import logging_utils
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def get_env_path():
|
||||
"""
|
||||
Get the path to the project's `.env` file, independent of the current working directory.
|
||||
|
||||
Returns:
|
||||
str: The absolute path to the `.env` file at the repository root.
|
||||
"""
|
||||
project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
return os.path.join(project_root, ".env")
|
||||
|
||||
def get_base_url(config):
|
||||
"""
|
||||
Get the API base URL from the environment or config.
|
||||
|
||||
Prefers the `OPENAI_BASE_URL` environment variable, falling back to the
|
||||
`base_url` value in the provided config dictionary.
|
||||
|
||||
Args:
|
||||
config (dict): A dictionary containing configuration values.
|
||||
|
||||
Returns:
|
||||
str or None: The API base URL, or None if not set.
|
||||
"""
|
||||
return os.getenv("OPENAI_BASE_URL") or config.get("base_url")
|
||||
|
||||
def get_api_key(config):
|
||||
"""
|
||||
Get the OpenAI API key from various sources.
|
||||
@@ -26,7 +51,7 @@ def get_api_key(config):
|
||||
Returns:
|
||||
str: The OpenAI API key
|
||||
"""
|
||||
dotenv.load_dotenv()
|
||||
dotenv.load_dotenv(get_env_path())
|
||||
|
||||
# Method 1: Read API key from environment variable
|
||||
# The user can set their OpenAI API key by creating a ".env" file in the same
|
||||
@@ -68,6 +93,9 @@ def create_client(config):
|
||||
OpenAI: An initialized OpenAI client.
|
||||
"""
|
||||
api_key = get_api_key(config)
|
||||
base_url = get_base_url(config)
|
||||
if base_url:
|
||||
return OpenAI(api_key=api_key, base_url=base_url)
|
||||
return OpenAI(api_key=api_key)
|
||||
|
||||
def call_api(client, config, query):
|
||||
@@ -95,7 +123,7 @@ def call_api(client, config, query):
|
||||
try:
|
||||
# Use the modern API pattern
|
||||
response = client.chat.completions.create(
|
||||
model=config.get("model", "gpt-4o-mini"),
|
||||
model=config.get("model", "gpt-5.6-luna"),
|
||||
messages=[
|
||||
{"role": "system", "content": system_prompt},
|
||||
{"role": "user", "content": prompt}
|
||||
@@ -137,7 +165,7 @@ def call_api_streaming(client, config, query, callback):
|
||||
try:
|
||||
# Use the streaming API pattern
|
||||
response = client.chat.completions.create(
|
||||
model=config.get("model", "gpt-4o-mini"),
|
||||
model=config.get("model", "gpt-5.6-luna"),
|
||||
messages=[
|
||||
{"role": "system", "content": system_prompt},
|
||||
{"role": "user", "content": prompt}
|
||||
|
||||
Reference in New Issue
Block a user