-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.py
42 lines (28 loc) · 955 Bytes
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import json
import os
import yaml
from dotenv import load_dotenv
load_dotenv()
def has_environment_variable(name):
value = os.getenv(name)
return value is not None and value.strip() != ""
def get_environment_variable(name):
value = os.getenv(name)
if value is None or value.strip() == "":
raise EnvironmentError(
f"{name} environment variable not set! Check your .env file."
)
return value
def parse_json(input_string):
try:
return json.loads(input_string)
except json.JSONDecodeError:
return None
def load_actions(agent_type):
with open("action_definitions.yaml", "r") as file:
all_actions = yaml.safe_load(file)
agent_type = agent_type.split("-")[0]
actions = all_actions["common_actions"]
if agent_type in all_actions["agent_specific_actions"]:
actions.extend(all_actions["agent_specific_actions"][agent_type])
return actions