Skip to content

Commit 16c7b32

Browse files
committed
feat(llm): add uipath openai llm
1 parent 9f94e39 commit 16c7b32

6 files changed

Lines changed: 157 additions & 2 deletions

File tree

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
[project]
22
name = "uipath-llamaindex"
3-
version = "0.0.23"
3+
version = "0.0.24"
44
description = "UiPath LlamaIndex SDK"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.10"
77
dependencies = [
88
"llama-index>=0.12.38",
9+
"llama-index-embeddings-azure-openai>=0.3.8",
10+
"llama-index-llms-azure-openai>=0.3.2",
911
"openinference-instrumentation-llama-index>=4.3.0",
1012
"uipath>=2.0.64",
1113
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from ._openai_embeddings import (
2+
OpenAIEmbeddingModel,
3+
UiPathOpenAIEmbedding,
4+
)
5+
6+
__all__ = [
7+
"UiPathOpenAIEmbedding",
8+
"OpenAIEmbeddingModel",
9+
]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import os
2+
from enum import Enum
3+
from typing import Any, Union
4+
5+
from llama_index.embeddings.azure_openai import AzureOpenAIEmbedding
6+
7+
8+
class OpenAIEmbeddingModel(Enum):
9+
TEXT_EMBEDDING_3_LARGE = "text-embedding-3-large"
10+
TEXT_EMBEDDING_ADA_002 = "text-embedding-ada-002"
11+
12+
13+
class UiPathOpenAIEmbedding(AzureOpenAIEmbedding):
14+
def __init__(
15+
self,
16+
model: Union[
17+
str, OpenAIEmbeddingModel
18+
] = OpenAIEmbeddingModel.TEXT_EMBEDDING_ADA_002,
19+
api_version: str = "2024-10-21",
20+
**kwargs: Any,
21+
):
22+
default_headers_dict = {
23+
"X-UIPATH-STREAMING-ENABLED": "false",
24+
"X-UiPath-LlmGateway-RequestingProduct": "uipath-python-sdk",
25+
"X-UiPath-LlmGateway-RequestingFeature": "llama-index-agent",
26+
}
27+
28+
model_value = model.value if isinstance(model, OpenAIEmbeddingModel) else model
29+
30+
base_url = os.environ.get(
31+
"UIPATH_URL", "EMPTY"
32+
).rstrip("/")
33+
34+
if base_url == "EMPTY":
35+
raise ValueError(
36+
"UIPATH_URL environment variable is not set. Please run uipath auth."
37+
)
38+
39+
defaults = {
40+
"model": model_value,
41+
"deployment_name": model_value,
42+
"azure_endpoint": f"{base_url}/llmgateway_/",
43+
"api_key": os.environ.get("UIPATH_ACCESS_TOKEN"),
44+
"api_version": api_version,
45+
"default_headers": default_headers_dict,
46+
}
47+
final_kwargs = {**defaults, **kwargs}
48+
super().__init__(**final_kwargs)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from ._openai_llms import (
2+
OpenAIModel,
3+
UiPathOpenAI,
4+
)
5+
6+
__all__ = [
7+
"UiPathOpenAI",
8+
"OpenAIModel",
9+
]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import os
2+
from enum import Enum
3+
from typing import Any, Union
4+
5+
from llama_index.llms.azure_openai import AzureOpenAI
6+
7+
8+
class OpenAIModel(Enum):
9+
GPT_4_1_2025_04_14 = "gpt-4.1-2025-04-14"
10+
GPT_4_1_MINI_2025_04_14 = "gpt-4.1-mini-2025-04-14"
11+
GPT_4_1_NANO_2025_04_14 = "gpt-4.1-nano-2025-04-14"
12+
GPT_4O_2024_05_13 = "gpt-4o-2024-05-13"
13+
GPT_4O_2024_08_06 = "gpt-4o-2024-08-06"
14+
GPT_4O_2024_11_20 = "gpt-4o-2024-11-20"
15+
GPT_4O_MINI_2024_07_18 = "gpt-4o-mini-2024-07-18"
16+
O3_MINI_2025_01_31 = "o3-mini-2025-01-31"
17+
TEXT_DAVINCI_003 = "text-davinci-003"
18+
19+
20+
# Define your custom AzureOpenAI class with default settings
21+
class UiPathOpenAI(AzureOpenAI):
22+
def __init__(
23+
self,
24+
model: Union[str, OpenAIModel] = OpenAIModel.GPT_4O_MINI_2024_07_18,
25+
api_version: str = "2024-10-21",
26+
**kwargs: Any,
27+
):
28+
default_headers_dict = {
29+
"X-UIPATH-STREAMING-ENABLED": "false",
30+
"X-UiPath-LlmGateway-RequestingProduct": "uipath-python-sdk",
31+
"X-UiPath-LlmGateway-RequestingFeature": "llama-index-agent",
32+
}
33+
model_value = model.value if isinstance(model, OpenAIModel) else model
34+
35+
base_url = os.environ.get(
36+
"UIPATH_URL", "EMPTY"
37+
).rstrip("/")
38+
39+
if base_url == "EMPTY":
40+
raise ValueError(
41+
"UIPATH_URL environment variable is not set. Please run uipath auth."
42+
)
43+
44+
defaults = {
45+
"model": model_value,
46+
"deployment_name": model_value,
47+
"azure_endpoint": f"{base_url}/llmgateway_/",
48+
"api_key": os.environ.get("UIPATH_ACCESS_TOKEN"),
49+
"api_version": api_version,
50+
"is_chat_model": True,
51+
"default_headers": default_headers_dict,
52+
}
53+
final_kwargs = {**defaults, **kwargs}
54+
super().__init__(**final_kwargs)

uv.lock

Lines changed: 34 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)