Skip to content

Commit

Permalink
more elegance
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenliang123 committed Nov 21, 2024
1 parent 8bbdafd commit 6b08cbe
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/crewai/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,27 +159,28 @@ def post_init_setup(self):
if provider == set_provider:
for env_var in env_vars:
# Check if the environment variable is set
if "key_name" in env_var:
if env_var["key_name"] in unnacepted_attributes:
key_name = env_var.get("key_name")
if key_name:
if key_name in unnacepted_attributes:
continue
env_value = os.environ.get(env_var["key_name"])
env_value = os.environ.get(key_name)
if env_value:
# Map key names containing "API_KEY" to "api_key"
key_name = (
"api_key"
if "API_KEY" in env_var["key_name"]
else env_var["key_name"]
if "API_KEY" in key_name
else key_name
)
# Map key names containing "API_BASE" to "api_base"
key_name = (
"api_base"
if "API_BASE" in env_var["key_name"]
if "API_BASE" in key_name
else key_name
)
# Map key names containing "API_VERSION" to "api_version"
key_name = (
"api_version"
if "API_VERSION" in env_var["key_name"]
if "API_VERSION" in key_name
else key_name
)
llm_params[key_name] = env_value
Expand Down Expand Up @@ -277,7 +278,7 @@ def execute_task(
if self.crew and self.crew.knowledge:
knowledge_snippets = self.crew.knowledge.query([task.prompt()])
valid_snippets = [
result["context"]
result["context"]
for result in knowledge_snippets
if result and result.get("context")
]
Expand Down

0 comments on commit 6b08cbe

Please sign in to comment.