Skip to content

Commit 5b138ea

Browse files
committed
started integrating fireworks
1 parent 5390289 commit 5b138ea

5 files changed

Lines changed: 249 additions & 2 deletions

File tree

packages/uipath_langchain_client/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ azure = [
2929
vertexai = [
3030
"langchain-google-vertexai>=3.2.1",
3131
]
32+
fireworks = [
33+
"langchain-fireworks>=1.1.0",
34+
]
3235
all = [
33-
"uipath-langchain-client[openai,aws,google,anthropic,azure,vertexai]"
36+
"uipath-langchain-client[openai,aws,google,anthropic,azure,vertexai,fireworks]"
3437
]
3538

3639
[build-system]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from uipath_langchain_client.clients.fireworks.chat_models import UiPathChatFireworks
2+
from uipath_langchain_client.clients.fireworks.embeddings import UiPathFireworksEmbeddings
3+
4+
__all__ = ["UiPathChatFireworks", "UiPathFireworksEmbeddings"]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from typing import Self
2+
3+
from pydantic import Field, SecretStr, model_validator
4+
from uipath_langchain_client.base_client import UiPathBaseLLMClient
5+
from uipath_langchain_client.settings import UiPathAPIConfig
6+
7+
try:
8+
from langchain_fireworks.chat_models import ChatFireworks
9+
10+
from fireworks.client.api_client import FireworksClient as FireworksClientV1
11+
except ImportError as e:
12+
raise ImportError(
13+
"The 'fireworks' extra is required to use UiPathChatFireworks. "
14+
'Install it with: uv add "uipath-langchain-client[fireworks]"'
15+
) from e
16+
17+
18+
class UiPathChatFireworks(UiPathBaseLLMClient, ChatFireworks): # type: ignore[override]
19+
api_config: UiPathAPIConfig = UiPathAPIConfig(
20+
api_type="completions",
21+
client_type="passthrough",
22+
freeze_base_url=True,
23+
)
24+
25+
# Override fields to avoid errors when instantiating the class
26+
fireworks_api_base: str | None = Field(alias="base_url", default="PLACEHOLDER")
27+
fireworks_api_key: SecretStr = Field(default=SecretStr("PLACEHOLDER"), alias="api_key")
28+
29+
@model_validator(mode="after")
30+
def setup_uipath_client(self) -> Self:
31+
fireworks_client_v1 = FireworksClientV1(
32+
api_key=self.fireworks_api_key.get_secret_value(),
33+
base_url=self.fireworks_api_base,
34+
)
35+
fireworks_client_v1._client = self.uipath_sync_client
36+
fireworks_client_v1._async_client = self.uipath_async_client
37+
self.client._client_v1 = fireworks_client_v1
38+
return self
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from typing import Self
2+
3+
from pydantic import model_validator
4+
from uipath_langchain_client.base_client import UiPathBaseLLMClient
5+
from uipath_langchain_client.settings import UiPathAPIConfig
6+
7+
try:
8+
from langchain_fireworks.embeddings import FireworksEmbeddings
9+
from openai import AsyncOpenAI, OpenAI
10+
except ImportError as e:
11+
raise ImportError(
12+
"The 'fireworks' extra is required to use UiPathFireworksEmbeddings. "
13+
'Install it with: uv add "uipath-langchain-client[fireworks]"'
14+
) from e
15+
16+
17+
class UiPathFireworksEmbeddings(UiPathBaseLLMClient, FireworksEmbeddings):
18+
api_config: UiPathAPIConfig = UiPathAPIConfig(
19+
api_type="embeddings",
20+
client_type="passthrough",
21+
vendor_type="openai",
22+
api_flavor="chat-completions",
23+
api_version="2025-03-01-preview",
24+
freeze_base_url=True,
25+
)
26+
27+
@model_validator(mode="after")
28+
def setup_uipath_client(self) -> Self:
29+
self.client = OpenAI(
30+
api_key="PLACEHOLDER",
31+
timeout=None, # handled by the UiPath client
32+
max_retries=0, # handled by the UiPath client
33+
http_client=self.uipath_sync_client,
34+
)
35+
self.async_client = AsyncOpenAI(
36+
api_key="PLACEHOLDER",
37+
timeout=None, # handled by the UiPath client
38+
max_retries=0, # handled by the UiPath client
39+
http_client=self.uipath_async_client,
40+
)
41+
return self
42+
43+
def embed_documents(self, texts: list[str]) -> list[list[float]]:
44+
"""Embed search docs."""
45+
return [
46+
i.embedding for i in self.client.embeddings.create(input=texts, model=self.model).data
47+
]
48+
49+
def embed_query(self, text: str) -> list[float]:
50+
"""Embed query text."""
51+
return self.embed_documents([text])[0]
52+
53+
async def aembed_documents(self, texts: list[str]) -> list[list[float]]:
54+
"""Embed search docs asynchronously."""
55+
return [
56+
i.embedding
57+
for i in (await self.async_client.embeddings.create(input=texts, model=self.model)).data
58+
]
59+
60+
async def aembed_query(self, text: str) -> list[float]:
61+
"""Embed query text asynchronously."""
62+
return (await self.aembed_documents([text]))[0]

0 commit comments

Comments
 (0)