-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates loading of config variables and litellm variables
- Loading branch information
Showing
3 changed files
with
60 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
from .models import Config | ||
import yaml | ||
|
||
|
||
configs= {} | ||
|
||
def load_config_from_db(): | ||
config_objs = Config.objects.all() | ||
|
||
for config in config_objs: | ||
configs[config.key] = config.value | ||
|
||
return configs | ||
|
||
def rewrite_config_yaml(): | ||
yaml_config = {} | ||
|
||
with open("litellm.yaml", "r") as file: | ||
yaml_config = yaml.safe_load(file) | ||
|
||
for model in yaml_config['model_list']: | ||
for key, value in model['litellm_params']: | ||
model['litellm_params'][key] = get_variable(value) | ||
|
||
with open("tmp_litellm.yaml", "w") as file: | ||
yaml.dump(yaml_config, file) | ||
|
||
def get_variable(value): | ||
if 'os.environ/' in value: | ||
env_name = value.split('/')[1] | ||
return configs[env_name] | ||
else: | ||
return value | ||
|
||
@receiver(post_save, sender=Config) | ||
def update_api_keys(sender, instance, **kwargs): | ||
global configs | ||
configs = load_config_from_db() | ||
rewrite_config_yaml() | ||
print(f"Configuration reloaded.") | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.core.management.base import BaseCommand | ||
from config.models import Config | ||
from config.lite_llm_database_config import load_config_from_db, rewrite_config_yaml | ||
|
||
class Command(BaseCommand): | ||
help = 'Reload API Keys for lite llm from the database' |