From 5d5298087f5e58a0ed8cc9a26ad72f385af163c6 Mon Sep 17 00:00:00 2001 From: zengbo Date: Sun, 18 Jun 2023 02:01:29 +0800 Subject: [PATCH] Custom Anthropic API URL (#6221) [Feature] User can custom the Anthropic API URL #### Who can review? Tag maintainers/contributors who might be interested: Models - @hwchase17 - @agola11 --- langchain/llms/anthropic.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/langchain/llms/anthropic.py b/langchain/llms/anthropic.py index 83522b06..9554fd90 100644 --- a/langchain/llms/anthropic.py +++ b/langchain/llms/anthropic.py @@ -36,6 +36,8 @@ class _AnthropicCommon(BaseModel): default_request_timeout: Optional[Union[float, Tuple[float, float]]] = None """Timeout for requests to Anthropic Completion API. Default is 600 seconds.""" + anthropic_api_url: str = "https://api.anthropic.com" + anthropic_api_key: Optional[str] = None HUMAN_PROMPT: Optional[str] = None @@ -48,10 +50,16 @@ class _AnthropicCommon(BaseModel): anthropic_api_key = get_from_dict_or_env( values, "anthropic_api_key", "ANTHROPIC_API_KEY" ) + """Get custom api url from environment.""" + anthropic_api_url = get_from_dict_or_env( + values, "anthropic_api_url", "ANTHROPIC_API_URL" + ) + try: import anthropic values["client"] = anthropic.Client( + api_url=anthropic_api_url, api_key=anthropic_api_key, default_request_timeout=values["default_request_timeout"], )