Skip to content

Commit d248509

Browse files
authored
Merge pull request #96 from UiPath/chore/update-openai-passthrough-endpoint
chore: update passthrough endpoint for openai
2 parents 216fae1 + 9ff9e44 commit d248509

5 files changed

Lines changed: 80 additions & 27 deletions

File tree

.github/workflows/integration_tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
integration-tests:
3737
needs: [discover-testcases]
3838
runs-on: ubuntu-latest
39+
timeout-minutes: 10
3940
container:
4041
image: ghcr.io/astral-sh/uv:python3.12-bookworm
4142
env:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath-llamaindex"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
description = "UiPath LlamaIndex SDK"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"

src/uipath_llamaindex/llms/_openai.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,46 @@
11
import os
22
from typing import Any
33

4+
import httpx
45
from llama_index.llms.azure_openai import AzureOpenAI # type: ignore
6+
from uipath._utils._ssl_context import get_httpx_client_kwargs
57
from uipath.utils import EndpointManager
68

79
from .supported_models import OpenAIModel
810

911

12+
class _UiPathSyncURLRewriteTransport(httpx.HTTPTransport):
13+
def handle_request(self, request: httpx.Request) -> httpx.Response:
14+
original_url = str(request.url)
15+
16+
if "/openai/deployments/" in original_url:
17+
base_url = original_url.split("/openai/deployments/")[0]
18+
query_string = request.url.params
19+
new_url_str = f"{base_url}/completions"
20+
if query_string:
21+
request.url = httpx.URL(new_url_str, params=query_string)
22+
else:
23+
request.url = httpx.URL(new_url_str)
24+
25+
return super().handle_request(request)
26+
27+
28+
class _UiPathAsyncURLRewriteTransport(httpx.AsyncHTTPTransport):
29+
async def handle_async_request(self, request: httpx.Request) -> httpx.Response:
30+
original_url = str(request.url)
31+
32+
if "/openai/deployments/" in original_url:
33+
base_url = original_url.split("/openai/deployments/")[0]
34+
query_string = request.url.params
35+
new_url_str = f"{base_url}/completions"
36+
if query_string:
37+
request.url = httpx.URL(new_url_str, params=query_string)
38+
else:
39+
request.url = httpx.URL(new_url_str)
40+
41+
return await super().handle_async_request(request)
42+
43+
1044
class UiPathOpenAI(AzureOpenAI):
1145
def __init__(
1246
self,
@@ -28,14 +62,28 @@ def __init__(
2862
"UIPATH_URL environment variable is not set. Please run uipath auth."
2963
)
3064

65+
vendor_endpoint = (
66+
EndpointManager.get_vendor_endpoint()
67+
.format(vendor="openai", model=model_value)
68+
.replace("/completions", "")
69+
)
70+
3171
defaults = {
3272
"model": model_value,
3373
"deployment_name": model_value,
34-
"azure_endpoint": f"{base_url}/{EndpointManager.get_passthrough_endpoint().format(model=model_value, api_version=api_version)}",
74+
"azure_endpoint": f"{base_url}/{vendor_endpoint}",
3575
"api_key": os.environ.get("UIPATH_ACCESS_TOKEN"),
3676
"api_version": api_version,
3777
"is_chat_model": True,
3878
"default_headers": default_headers_dict,
79+
"http_client": httpx.Client(
80+
transport=_UiPathSyncURLRewriteTransport(),
81+
**get_httpx_client_kwargs(),
82+
),
83+
"async_http_client": httpx.AsyncClient(
84+
transport=_UiPathAsyncURLRewriteTransport(),
85+
**get_httpx_client_kwargs(),
86+
),
3987
}
4088
final_kwargs = {**defaults, **kwargs}
4189
super().__init__(**final_kwargs)

src/uipath_llamaindex/llms/vertex.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import httpx
66
from llama_index.core.callbacks import CallbackManager
77
from llama_index.core.constants import DEFAULT_NUM_OUTPUTS, DEFAULT_TEMPERATURE
8+
from uipath._utils._ssl_context import get_httpx_client_kwargs
89
from uipath.utils import EndpointManager
910

1011
from .supported_models import GeminiModel
@@ -178,12 +179,12 @@ def __init__(
178179
httpx_client=httpx.Client(
179180
transport=_UrlRewriteTransport(uipath_url),
180181
headers=headers,
181-
follow_redirects=True,
182+
**get_httpx_client_kwargs(),
182183
),
183184
httpx_async_client=httpx.AsyncClient(
184185
transport=_AsyncUrlRewriteTransport(uipath_url),
185186
headers=headers,
186-
follow_redirects=True,
187+
**get_httpx_client_kwargs(),
187188
),
188189
)
189190

@@ -330,7 +331,7 @@ def _create_sync_client(self) -> google.genai.Client:
330331
httpx_client=httpx.Client(
331332
transport=_UrlRewriteTransport(uipath_url),
332333
headers=headers,
333-
follow_redirects=True,
334+
**get_httpx_client_kwargs(),
334335
),
335336
)
336337

uv.lock

Lines changed: 25 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)