|
1 | 1 | from typing import List, Dict
|
| 2 | + |
| 3 | +from botocore.config import Config |
2 | 4 | from langchain_community.chat_models import BedrockChat
|
3 | 5 | from setting.models_provider.base_model_provider import MaxKBBaseModel
|
4 | 6 |
|
@@ -33,19 +35,34 @@ def is_cache_model():
|
33 | 35 | return False
|
34 | 36 |
|
35 | 37 | 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): |
37 | 39 | 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) |
39 | 42 |
|
40 | 43 | @classmethod
|
41 | 44 | def new_instance(cls, model_type: str, model_name: str, model_credential: Dict[str, str],
|
42 | 45 | **model_kwargs) -> 'BedrockModel':
|
43 | 46 | optional_params = MaxKBBaseModel.filter_optional_params(model_kwargs)
|
44 | 47 |
|
| 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 | + |
45 | 61 | return cls(
|
46 | 62 | model_id=model_name,
|
47 | 63 | region_name=model_credential['region_name'],
|
48 | 64 | credentials_profile_name=model_credential['credentials_profile_name'],
|
49 | 65 | streaming=model_kwargs.pop('streaming', True),
|
50 |
| - model_kwargs=optional_params |
| 66 | + model_kwargs=optional_params, |
| 67 | + config=config |
51 | 68 | )
|
0 commit comments