Skip to content

Commit

Permalink
move env vars to json file
Browse files Browse the repository at this point in the history
  • Loading branch information
grischperl committed Nov 27, 2024
1 parent bbc6e3f commit 95e7354
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ ENV/
env.bak/
venv.bak/

# Configuration
config/config.json

# Spyder project settings
.spyderproject
.spyproject
Expand Down
51 changes: 51 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"AICORE_AUTH_URL": "https://kyma-companion-0ovnrk86.authentication.sap.hana.ondemand.com/oauth/token",
"AICORE_BASE_URL": "https://api.ai.internalprod.eu-central-1.aws.ml.hana.ondemand.com/v2",
"AICORE_CLIENT_ID": "sb-8bd2476c-6428-44ef-be07-26caf642512e!b137635|xsuaa_std!b77089",
"AICORE_CLIENT_SECRET": "5545d480-0ae3-40e6-98a3-cfb72098f09f$68S9Upfzl7DP8ZDazxnQPcagEeKGDgNUgt9tkROrhTE=",
"AICORE_CONFIGURATION_ID_EMBEDDINGS_ADA": "f5c41bc9-a5fd-4f6c-9527-abdb7166eb19",
"AICORE_CONFIGURATION_ID_GEMINI_PRO": "e44b5905-3163-4205-9f72-bae8fc526f7d",
"AICORE_CONFIGURATION_ID_GPT35": "da6ff8ee-c7c6-46aa-a3b6-92c729d012f5",
"AICORE_CONFIGURATION_ID_GPT35_16K": "0f59b518-c128-4f8b-bcac-b6a0ae8347e1",
"AICORE_CONFIGURATION_ID_GPT4": "b5ebcea1-d35a-4831-97b4-be0a3c2f2c1f",
"AICORE_CONFIGURATION_ID_GPT4_32K": "0b142345-3bee-404b-9291-c08da5da4ca1",
"AICORE_DEPLOYMENT_ID_EMBEDDINGS_ADA": "d7029be0616fd7ee",
"AICORE_DEPLOYMENT_ID_GEMINI_PRO": "db839a2dbbfd311f",
"AICORE_DEPLOYMENT_ID_GPT35": "d7f200bc2d5586db",
"AICORE_DEPLOYMENT_ID_GPT35_16K": "d575345d0e413530",
"AICORE_DEPLOYMENT_ID_GPT4": "d8cc02e45ca77234",
"AICORE_DEPLOYMENT_ID_GPT4_32K": "da13b98b1870b839",
"AICORE_RESOURCE_GROUP": "default",

"REDIS_URL": "redis://localhost:6379",
"REDIS_HOST": "localhost",
"REDIS_PORT": "6379",

"TEST_CLUSTER_URL": "https://api.comp-tests-0.kymatunas.shoot.canary.k8s-hana.ondemand.com",
"TEST_CLUSTER_CA_DATA": "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUQ1akNDQWs2Z0F3SUJBZ0lRZkg0SktqeVZlS2RGejl0Slk4YVRLVEFOQmdrcWhraUc5dzBCQVFzRkFEQU4KTVFzd0NRWURWUVFERXdKallUQWVGdzB5TkRBNE1ESXhNVFEwTUROYUZ3MHpOREE0TURJeE1UUTBNRE5hTUEweApDekFKQmdOVkJBTVRBbU5oTUlJQm9qQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FZOEFNSUlCaWdLQ0FZRUF1TGVxCjhDSDlibkFiaEVaY2FtZVRyckQyOFRYTU1MMWJIbVdXeXk5bGpwTnVRSXpjUkpFZWVQYWs5QzRuYmNHcUtwMUQKdWRUN3Z6bWZQRzJ1Qk9LZS8yemtaajlHcDFvZTI1OVVGUE5MalNpWG5nRm9wTUNHTFF5aWFEdGJiaUtaR3ZScApqbDcvSjRHbnFURUs3aElZSmg2dmJBc1BkL2wycVhhZ1p6QUxhR1k2VmwzQnNicG5OemJUZEpJM2RRbWRrWjJDCkRveGFLN0V0TG9PbGUxMlA4UjVNQzNGeTY3bDdudDIrTTRqSTFLRlNpaEIyRUpSalVWb0QveXhKVEN6dlBpZXgKZVlOVE9reXM5OWp4UzFpT1UxU3lqMkZQSVdWRWMxZGN4VUdMWjk1Tmx5ekJvcDJiaTVRVWhVWDM4UlFrTUtiSQpSWExsL0JBNk1qMDIzblRuVW5Zc2NqS2NUdXpOYUJJLzJtVEpEd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zw9pd3A6vDmPEGQNm7GONubvWzWMsN9b0x6BgY-9Ht9u3PBElCws3giMjYOLgIOuvYyDXa5UtAP9bwAe0A5l1Ko3gAlbe2U-Zp0BHM7EZ4RyDf-tFJQGrgdFHPbfeN8ewVQB43gJDyX1fq-a24K9GmSJo1BLXCRY4J8L2Cnq7Uen7ngpo4mN2PlZxqc0H7mh-rmzNdrN-akJdPGa0mKfD9tUIc0LSQwjK9x-mzLvEdSK11lVs3cTK3izZ6iCWYtbpGOHAaljb9r-DiDRBNNghygU",
"MODELS_CONFIG_FILE_PATH": "/Users/I540130/go/kyma-companion/config/config.json",

"LANGFUSE_HOST": "https://langfuse.mur-nats.kymatunas.shoot.canary.k8s-hana.ondemand.com",
"LANGFUSE_SECRET_KEY": "sk-lf-5db4a607-33cd-4032-bad1-4b73e648fb12",
"LANGFUSE_PUBLIC_KEY": "pk-lf-531cae1b-ee40-4792-a6f8-fc8b0d5a25e1",

"DATABASE_URL": "75fd286d-e18a-466c-b815-6ea6df0a73db.hana.canary-eu10.hanacloud.ondemand.com",
"DATABASE_USER": "AIFORCE",
"DATABASE_PASSWORD": "-6<B8~#tXluLvzwzDa*7FtX&",
"DATABASE_PORT": "443",
"DOCS_TABLE_NAME": "kyma_docs",

"models": [
{
"name": "gpt-4o",
"deployment_id": "d92ed4e1d4bafffc",
"temperature": 0
},
{
"name": "gpt-4o-mini",
"deployment_id": "d3da334def2bb9c8",
"temperature": 0
}
]
}
7 changes: 0 additions & 7 deletions config/config.yml

This file was deleted.

10 changes: 5 additions & 5 deletions scripts/k8s/companion-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,21 @@ spec:
- name: REDIS_PORT
value: "6379"
- name: CONFIG_PATH
value: "/mnt/config/models-config.yml"
value: "/mnt/config/config.json"
envFrom:
- configMapRef:
name: ai-backend-config
volumeMounts:
- name: models-config
mountPath: /mnt/config/models-config.yml
subPath: models-config.yml
mountPath: /mnt/config/config.json
subPath: config.json
volumes:
- name: models-config
configMap:
name: ai-backend-config
items:
- key: models-config.yml
path: models-config.yml
- key: config.json
path: config.json

---
apiVersion: v1
Expand Down
17 changes: 12 additions & 5 deletions src/utils/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os
from pathlib import Path

Expand Down Expand Up @@ -56,12 +57,18 @@ def get_config() -> Config:
# Get the absolute path of the current file
current_file_path = Path(__file__).resolve()

target_config_file = os.environ.get("CONFIG_PATH", "config/config.yml")
target_config_file = os.environ.get("CONFIG_PATH", "config/config.json")
# Find the config file by searching upwards
config_file = find_config_file(current_file_path.parent, target_config_file)

logger.info(f"Loading models config from: {config_file}")
with config_file.open() as f:
data = yaml.safe_load(f)
config = Config(**data)
return config
try:
with config_file.open() as file:
data = json.load(file)
# Extract only the "models" part of the configuration
models_data = data.get("models", [])
config = Config(models=models_data)
return config
except Exception as e:
logger.error(f"Error loading config from {config_file}: {e}")
raise
35 changes: 30 additions & 5 deletions src/utils/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Load all variables from .env into the environment
# necessary to implicitly import AI Core Env Vars
import json
import logging
import os
import sys
Expand All @@ -15,19 +16,43 @@ def is_running_pytest() -> bool:
return "pytest" in sys.modules


project_root = os.path.dirname(os.path.abspath(__file__))
def load_env_from_json():
"""Load the configuration from the config.json file."""
config_path = os.getenv(
"AICORE_HOME",
os.path.abspath("../../go/src/github.com/kyma-project/kyma-companion/config/config.json")
) # Default to root config.json.

if os.path.exists(config_path):
try:
# Load the configuration from the given path and set the environment variables.
with open(config_path, "r") as file:
config_file = json.load(file)

# Set environment variables for all keys except "models"
for key, value in config_file.items():
if key != "models": # Skip models
os.environ[key] = str(value)
except Exception as e:
logging.error(f"Error loading config from {config_path}: {e}")
else:
logging.error(f"Config file not found at {config_path}.")


if is_running_pytest():
# Use .test.env for tests
# For tests use .env.test if available
env_path = find_dotenv(".env.test")
if env_path and os.path.exists(env_path):
config = Config(RepositoryEnv(env_path))
load_dotenv(env_path)
else:
logging.warning("No .test.env file found. Using .env file.")
load_dotenv()
# Load the config.json if no .env.test file is found
logging.warning("No .test.env file found. Using config.json.")
load_env_from_json()

else:
load_dotenv()
# For production load the env variables needed dynamically from the config.json.
load_env_from_json()

LOG_LEVEL = config("LOG_LEVEL", default="INFO")
# Redis
Expand Down

0 comments on commit 95e7354

Please sign in to comment.