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

feat: add options of ignoring SSL verification while the SSL certificate is self-signed. #981

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class BaseHostChatLLM(BaseChatModel):
model_kwargs: Optional[Dict[str, Any]] = Field(default_factory=dict)
"""Holds any model parameters valid for `create` call not explicitly specified."""
host_base_url: Optional[str] = None
is_ssl: Optional[bool] = False

headers: Optional[Dict[str, str]] = Field(default_factory=dict)

Expand Down Expand Up @@ -170,7 +171,13 @@ def validate_environment(cls, values: Dict) -> Dict:
headers = values['headers']
else:
headers = {'Content-Type': 'application/json'}
values['client'] = Requests(headers=headers, request_timeout=values['request_timeout'])
if cls.is_ssl and "https" in values['host_base_url']:
import aiohttp
values['client'] = Requests(headers=headers,
aiosession=aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False)),
request_timeout=values['request_timeout'])
else:
values['client'] = Requests(headers=headers, request_timeout=values['request_timeout'])
except AttributeError:
raise ValueError('Try upgrading it with `pip install --upgrade requests`.')
return values
Expand Down
13 changes: 7 additions & 6 deletions src/bisheng-langchain/bisheng_langchain/utils/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ async def _arequest(self, method: str, url: str,
**kwargs) as response:
yield response
else:
async with self.aiosession.request(method,
url,
headers=self.headers,
auth=self.auth,
**kwargs) as response:
yield response
async with self.aiosession:
async with self.aiosession.request(method,
url,
headers=self.headers,
auth=self.auth,
**kwargs) as response:
yield response

@asynccontextmanager
async def aget(self, url: str, **kwargs: Any) -> AsyncGenerator[aiohttp.ClientResponse, None]:
Expand Down