Skip to content

Commit

Permalink
update: add connection close settings to avoid connection pool cause …
Browse files Browse the repository at this point in the history
…error 'event loop is closed'
  • Loading branch information
Maplemx committed May 30, 2024
1 parent b731e34 commit 81242f4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
13 changes: 12 additions & 1 deletion Agently/plugins/request/AzureOpenAI.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ def _create_client(self):

proxy = self.request.settings.get_trace_back("proxy")
if proxy:
client_params.update({ "http_client": httpx.AsyncClient( proxies = proxy ) })
client_params.update({
"http_client": httpx.AsyncClient(
proxies = proxy,
headers = [("Connection", "close")],
)
})
else:
client_params.update({
"http_client": httpx.AsyncClient(
headers = [("Connection", "close")],
)
})

api_key = self.model_settings.get_trace_back("auth.api_key")
api_version = self.model_settings.get_trace_back("auth.api_version")
Expand Down
13 changes: 12 additions & 1 deletion Agently/plugins/request/OAIClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,18 @@ async def request_model(self, request_data: dict):
client_params.update({ "base_url": base_url })
proxy = self.request.settings.get_trace_back("proxy")
if proxy:
client_params.update({ "http_client": httpx.AsyncClient( proxies = proxy ) })
client_params.update({
"http_client": httpx.AsyncClient(
proxies = proxy,
headers = [("Connection", "close")],
)
})
else:
client_params.update({
"http_client": httpx.AsyncClient(
headers = [("Connection", "close")],
)
})
api_key = self.model_settings.get_trace_back("auth.api_key")
if api_key:
client_params.update({ "api_key": api_key })
Expand Down
13 changes: 12 additions & 1 deletion Agently/plugins/request/OpenAI.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,18 @@ def _create_client(self):
client_params.update({ "base_url": base_url })
proxy = self.request.settings.get_trace_back("proxy")
if proxy:
client_params.update({ "http_client": httpx.AsyncClient( proxies = proxy ) })
client_params.update({
"http_client": httpx.AsyncClient(
proxies = proxy,
headers = [("Connection", "close")],
)
})
else:
client_params.update({
"http_client": httpx.AsyncClient(
headers = [("Connection", "close")],
)
})
api_key = self.model_settings.get_trace_back("auth.api_key")
if api_key:
client_params.update({ "api_key": api_key })
Expand Down

0 comments on commit 81242f4

Please sign in to comment.