mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-26 00:28:13 +00:00
Use CREWAI_PROMPT_FILE environment variable.
CrewAI initializes several I18N instances deep within the library at package initialization time, using the default prompts. This makes overriding the defaults consistently throughout the package very difficult, requiring monkeypatching. This change will allow overriding the default prompt file location in the $CREWAI_PROMPT_FILE environment variable, allowing consistency throughout the library.
This commit is contained in:
@@ -42,3 +42,24 @@ def test_prompt_file():
|
||||
i18n.load_prompts()
|
||||
assert isinstance(i18n.retrieve("slices", "role_playing"), str)
|
||||
assert i18n.retrieve("slices", "role_playing") == "Lorem ipsum dolor sit amet"
|
||||
|
||||
|
||||
def test_prompt_file_env():
|
||||
import os
|
||||
|
||||
path = os.path.join(os.path.dirname(__file__), "prompts.json")
|
||||
old_env = os.environ.get("CREWAI_PROMPT_FILE")
|
||||
try:
|
||||
os.environ["CREWAI_PROMPT_FILE"] = path
|
||||
i18n = I18N()
|
||||
i18n.load_prompts()
|
||||
assert i18n.retrieve("slices", "role_playing") == "Lorem ipsum dolor sit amet"
|
||||
finally:
|
||||
if old_env:
|
||||
os.environ["CREWAI_PROMPT_FILE"] = old_env
|
||||
else:
|
||||
del os.environ["CREWAI_PROMPT_FILE"]
|
||||
|
||||
i18n = I18N()
|
||||
i18n.load_prompts()
|
||||
assert i18n.retrieve("slices", "role_playing") != "Lorem ipsum dolor sit amet"
|
||||
|
||||
Reference in New Issue
Block a user