Skip to content

Commit

Permalink
fix azure_openai.py: some keys do not exists (#24158)
Browse files Browse the repository at this point in the history
In some lines its trying to read a key that do not exists yet. In this
cases I changed the direct access to dict.get() method

Thank you for contributing to LangChain!

- [x] **Lint and test**: Run `make format`, `make lint` and `make test`
from the root of the package(s) you've modified. See contribution
guidelines for more: https://python.langchain.com/docs/contributing/
  • Loading branch information
antunsz authored Jul 15, 2024
1 parent d895614 commit 2015138
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions libs/community/langchain_community/embeddings/azure_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def validate_environment(cls, values: Dict) -> Dict:
# TODO: Remove OPENAI_API_KEY support to avoid possible conflict when using
# other forms of azure credentials.
values["openai_api_key"] = (
values["openai_api_key"]
values.get("openai_api_key")
or os.getenv("AZURE_OPENAI_API_KEY")
or os.getenv("OPENAI_API_KEY")
)
Expand All @@ -75,7 +75,7 @@ def validate_environment(cls, values: Dict) -> Dict:
values, "openai_api_type", "OPENAI_API_TYPE", default="azure"
)
values["openai_organization"] = (
values["openai_organization"]
values.get("openai_organization")
or os.getenv("OPENAI_ORG_ID")
or os.getenv("OPENAI_ORGANIZATION")
)
Expand All @@ -85,10 +85,10 @@ def validate_environment(cls, values: Dict) -> Dict:
"OPENAI_PROXY",
default="",
)
values["azure_endpoint"] = values["azure_endpoint"] or os.getenv(
values["azure_endpoint"] = values.get("azure_endpoint") or os.getenv(
"AZURE_OPENAI_ENDPOINT"
)
values["azure_ad_token"] = values["azure_ad_token"] or os.getenv(
values["azure_ad_token"] = values.get("azure_ad_token") or os.getenv(
"AZURE_OPENAI_AD_TOKEN"
)
# Azure OpenAI embedding models allow a maximum of 16 texts
Expand Down

0 comments on commit 2015138

Please sign in to comment.