Salmanap/fix config generator (#124)

* fixed environment variables issue with build. Now llm provider access keys are being written correctly

* fixed and verified that keys are being properly set when archgw is booted up

* removing leaf reference to a staged config file. not needed anymore

* minor fixes to get the build in more stable state

* minor fixes based on feedback

---------

Co-authored-by: Salman Paracha <salmanparacha@MacBook-Pro-261.local>
This commit is contained in:
Salman Paracha 2024-10-05 10:49:47 -07:00 committed by GitHub
parent 5ba7db21d0
commit 0e5ea3d6db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 127 additions and 52 deletions

View file

@ -1,11 +1,12 @@
import click
from core import start_arch, stop_arch
import targets
import os
import config_generator
import pkg_resources
import sys
import subprocess
from core import start_arch, stop_arch
from utils import get_llm_provider_access_keys, load_env_file_to_dict
logo = r"""
_ _
@ -75,10 +76,8 @@ def up(file, path):
print(f"Error: {arch_config_file} does not exist.")
return
print(f"Processing config file: {arch_config_file}")
arch_schema_config = pkg_resources.resource_filename(__name__, "config/arch_config_schema.yaml")
print(f"Validating {arch_config_file}")
arch_schema_config = pkg_resources.resource_filename(__name__, "config/arch_config_schema.yaml")
try:
config_generator.validate_prompt_config(arch_config_file=arch_config_file, arch_config_schema_file=arch_schema_config)
@ -87,7 +86,41 @@ def up(file, path):
sys.exit(1)
print("Starting Arch gateway and Arch model server services via docker ")
start_arch(arch_config_file)
# Set the ARCH_CONFIG_FILE environment variable
env_stage = {}
#check if access_keys are preesnt in the config file
access_keys = get_llm_provider_access_keys(arch_config_file=arch_config_file)
if access_keys:
if file:
app_env_file = os.path.join(os.path.dirname(os.path.abspath(file)), ".env") #check the .env file in the path
else:
app_env_file = os.path.abspath(os.path.join(path, ".env"))
if not os.path.exists(app_env_file): #check to see if the environment variables in the current environment or not
for access_key in access_keys:
if env.get(access_key) is None:
print (f"Access Key: {access_key} not found. Exiting Start")
sys.exit(1)
else:
env_stage[access_key] = env.get(access_key)
else: #.env file exists, use that to send parameters to Arch
env_file_dict = load_env_file_to_dict(app_env_file)
for access_key in access_keys:
if env_file_dict.get(access_key) is None:
print (f"Access Key: {access_key} not found. Exiting Start")
sys.exit(1)
else:
env_stage[access_key] = env_file_dict[access_key]
with open(pkg_resources.resource_filename(__name__, "config/stage.env"), 'w') as file:
for key, value in env_stage.items():
file.write(f"{key}={value}\n")
env = os.environ.copy()
env.update(env_stage)
env['ARCH_CONFIG_FILE'] = arch_config_file
start_arch(arch_config_file, env)
@click.command()
def down():