From 94ebf027197e5bf8faa58e83c6ce1f0a65441bfd Mon Sep 17 00:00:00 2001 From: mindspawn Date: Mon, 3 Jun 2024 20:41:59 -0700 Subject: [PATCH 1/2] Enable http_proxy use for openai calls. --- backend/apps/openai/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/apps/openai/main.py b/backend/apps/openai/main.py index 7429d94ed..472699f1d 100644 --- a/backend/apps/openai/main.py +++ b/backend/apps/openai/main.py @@ -186,7 +186,7 @@ async def fetch_url(url, key): timeout = aiohttp.ClientTimeout(total=5) try: headers = {"Authorization": f"Bearer {key}"} - async with aiohttp.ClientSession(timeout=timeout) as session: + async with aiohttp.ClientSession(timeout=timeout, trust_env=True) as session: async with session.get(url, headers=headers) as response: return await response.json() except Exception as e: @@ -462,7 +462,7 @@ async def proxy(path: str, request: Request, user=Depends(get_verified_user)): streaming = False try: - session = aiohttp.ClientSession() + session = aiohttp.ClientSession(trust_env=True) r = await session.request( method=request.method, url=target_url, From 74ed74f1a4ec30b6ea6fc2124395d9033451edf2 Mon Sep 17 00:00:00 2001 From: mindspawn Date: Mon, 3 Jun 2024 20:43:25 -0700 Subject: [PATCH 2/2] Enable http_proxy use for ollama calls. --- backend/apps/ollama/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/apps/ollama/main.py b/backend/apps/ollama/main.py index 9fa932fe2..35564f0c1 100644 --- a/backend/apps/ollama/main.py +++ b/backend/apps/ollama/main.py @@ -134,7 +134,7 @@ async def update_ollama_api_url(form_data: UrlUpdateForm, user=Depends(get_admin async def fetch_url(url): timeout = aiohttp.ClientTimeout(total=5) try: - async with aiohttp.ClientSession(timeout=timeout) as session: + async with aiohttp.ClientSession(timeout=timeout, trust_env=True) as session: async with session.get(url) as response: return await response.json() except Exception as e: @@ -156,7 +156,7 @@ async def cleanup_response( async def post_streaming_url(url: str, payload: str): r = None try: - session = aiohttp.ClientSession() + session = aiohttp.ClientSession(trust_env=True) r = await session.post(url, data=payload) r.raise_for_status() @@ -1045,7 +1045,7 @@ async def download_file_stream( timeout = aiohttp.ClientTimeout(total=600) # Set the timeout - async with aiohttp.ClientSession(timeout=timeout) as session: + async with aiohttp.ClientSession(timeout=timeout, trust_env=True) as session: async with session.get(file_url, headers=headers) as response: total_size = int(response.headers.get("content-length", 0)) + current_size