Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community[patch]: Make cohere_api_key a SecretStr #12188

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions libs/langchain/langchain/llms/cohere.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from langchain.llms.base import LLM
from langchain.llms.utils import enforce_stop_tokens
from langchain.load.serializable import Serializable
from langchain.pydantic_v1 import Extra, Field, root_validator
from langchain.pydantic_v1 import Extra, Field, SecretStr, root_validator
from langchain.utils import get_from_dict_or_env

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -73,7 +73,7 @@ class BaseCohere(Serializable):
temperature: float = 0.75
"""A non-negative float that tunes the degree of randomness in generation."""

cohere_api_key: Optional[str] = None
cohere_api_key: Optional[SecretStr] = None

stop: Optional[List[str]] = None

Expand All @@ -91,8 +91,8 @@ def validate_environment(cls, values: Dict) -> Dict:
"Please install it with `pip install cohere`."
)
else:
cohere_api_key = get_from_dict_or_env(
values, "cohere_api_key", "COHERE_API_KEY"
cohere_api_key = SecretStr(
get_from_dict_or_env(values, "cohere_api_key", "COHERE_API_KEY")
)
values["client"] = cohere.Client(cohere_api_key)
values["async_client"] = cohere.AsyncClient(cohere_api_key)
Expand Down Expand Up @@ -155,8 +155,8 @@ def _default_params(self) -> Dict[str, Any]:
}

@property
def lc_secrets(self) -> Dict[str, str]:
return {"cohere_api_key": "COHERE_API_KEY"}
def lc_secrets(self) -> Dict[str, SecretStr]:
return {"cohere_api_key": SecretStr("COHERE_API_KEY")}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should stay the same -- the COHERE_API_KEY is not a secret, but a standard variable name used during serialization. (Don't worry about this for now)


@property
def _identifying_params(self) -> Dict[str, Any]:
Expand Down
Loading