Skip to content

Commit 0cae0c8

Browse files
committed
feat: support aws proxy_url
1 parent f1cca66 commit 0cae0c8

File tree

2 files changed

+21
-3
lines changed
  • apps/setting/models_provider/impl/aws_bedrock_model_provider

2 files changed

+21
-3
lines changed

apps/setting/models_provider/impl/aws_bedrock_model_provider/credential/llm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def encryption_dict(self, model: Dict[str, object]):
7979
region_name = forms.TextInputField('Region Name', required=True)
8080
access_key_id = forms.TextInputField('Access Key ID', required=True)
8181
secret_access_key = forms.PasswordInputField('Secret Access Key', required=True)
82+
base_url = forms.TextInputField('Proxy URL', required=False)
8283

8384
def get_model_params_setting_form(self, model_name):
8485
return BedrockLLMModelParams()

apps/setting/models_provider/impl/aws_bedrock_model_provider/model/llm.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from typing import List, Dict
2+
3+
from botocore.config import Config
24
from langchain_community.chat_models import BedrockChat
35
from setting.models_provider.base_model_provider import MaxKBBaseModel
46

@@ -33,19 +35,34 @@ def is_cache_model():
3335
return False
3436

3537
def __init__(self, model_id: str, region_name: str, credentials_profile_name: str,
36-
streaming: bool = False, **kwargs):
38+
streaming: bool = False, config: Config = None, **kwargs):
3739
super().__init__(model_id=model_id, region_name=region_name,
38-
credentials_profile_name=credentials_profile_name, streaming=streaming, **kwargs)
40+
credentials_profile_name=credentials_profile_name, streaming=streaming, config=config,
41+
**kwargs)
3942

4043
@classmethod
4144
def new_instance(cls, model_type: str, model_name: str, model_credential: Dict[str, str],
4245
**model_kwargs) -> 'BedrockModel':
4346
optional_params = MaxKBBaseModel.filter_optional_params(model_kwargs)
4447

48+
config = {}
49+
# 判断model_kwargs是否包含 base_url 且不为空
50+
if 'base_url' in model_credential and model_credential['base_url']:
51+
proxy_url = model_credential['base_url']
52+
config = Config(
53+
proxies={
54+
'http': proxy_url,
55+
'https': proxy_url
56+
},
57+
connect_timeout=60,
58+
read_timeout=60
59+
)
60+
4561
return cls(
4662
model_id=model_name,
4763
region_name=model_credential['region_name'],
4864
credentials_profile_name=model_credential['credentials_profile_name'],
4965
streaming=model_kwargs.pop('streaming', True),
50-
model_kwargs=optional_params
66+
model_kwargs=optional_params,
67+
config=config
5168
)

0 commit comments

Comments
 (0)