Skip to content

Commit 42cbde8

Browse files
committed
started integrating fireworks
1 parent 287ca44 commit 42cbde8

7 files changed

Lines changed: 266 additions & 4 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]

packages/uipath_langchain_client/src/uipath_langchain_client/base_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ class UiPathBaseLLMClient(BaseModel):
100100
default=None,
101101
description="Client-side request timeout in seconds",
102102
)
103-
max_retries: int = Field(
104-
default=1,
103+
max_retries: int | None = Field(
104+
default=None,
105105
description="Maximum number of retries for failed requests",
106106
)
107107
retry_config: RetryConfig | None = Field(
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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 import AsyncFireworks, Fireworks
11+
from fireworks.client.api_client import FireworksClient as FireworksClientV1
12+
except ImportError as e:
13+
raise ImportError(
14+
"The 'fireworks' extra is required to use UiPathChatFireworks. "
15+
"Install it with: uv add uipath-langchain-client[fireworks]"
16+
) from e
17+
18+
19+
class UiPathChatFireworks(UiPathBaseLLMClient, ChatFireworks):
20+
api_config: UiPathAPIConfig = UiPathAPIConfig(
21+
api_type="completions",
22+
client_type="passthrough",
23+
freeze_base_url=True,
24+
)
25+
26+
# Override fields to avoid errors when instantiating the class
27+
fireworks_api_base: str | None = Field(alias="base_url", default="PLACEHOLDER")
28+
fireworks_api_key: SecretStr = Field(default=SecretStr("PLACEHOLDER"), alias="api_key")
29+
30+
@model_validator(mode="after")
31+
def setup_uipath_client(self) -> Self:
32+
fireworks_client_v1 = FireworksClientV1(
33+
api_key=self.fireworks_api_key.get_secret_value(),
34+
base_url=self.fireworks_api_base,
35+
)
36+
fireworks_client_v1._client = self.uipath_sync_client
37+
fireworks_client_v1._async_client = self.uipath_async_client
38+
self.client = Fireworks(client=fireworks_client_v1)
39+
40+
return self
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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="fireworks",
22+
freeze_base_url=True,
23+
)
24+
25+
@model_validator(mode="after")
26+
def setup_uipath_client(self) -> Self:
27+
self.client = OpenAI(
28+
api_key="PLACEHOLDER",
29+
timeout=None, # handled by the UiPath client
30+
max_retries=1, # handled by the UiPath client
31+
http_client=self.uipath_sync_client,
32+
)
33+
self.async_client = AsyncOpenAI(
34+
api_key="PLACEHOLDER",
35+
timeout=None, # handled by the UiPath client
36+
max_retries=1, # handled by the UiPath client
37+
http_client=self.uipath_async_client,
38+
)
39+
return self
40+
41+
def embed_documents(self, texts: list[str]) -> list[list[float]]:
42+
"""Embed search docs."""
43+
return [
44+
i.embedding for i in self.client.embeddings.create(input=texts, model=self.model).data
45+
]
46+
47+
def embed_query(self, text: str) -> list[float]:
48+
"""Embed query text."""
49+
return self.embed_documents([text])[0]
50+
51+
async def aembed_documents(self, texts: list[str]) -> list[list[float]]:
52+
"""Embed search docs asynchronously."""
53+
return [
54+
i.embedding
55+
for i in (await self.async_client.embeddings.create(input=texts, model=self.model)).data
56+
]
57+
58+
async def aembed_query(self, text: str) -> list[float]:
59+
"""Embed query text asynchronously."""
60+
return (await self.aembed_documents([text]))[0]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from fireworks.client import Fireworks, AsyncFireworks
2+
from fireworks.client.api_client import FireworksClient as FireworksClientV1
3+
4+
from httpx import Client, AsyncClient
5+
6+
class UiPathFireworksClient(FireworksClientV1):
7+
def __init__(self, *args, http_client: Client | None = None, async_http_client: AsyncClient | None = None, **kwargs):
8+
super().__init__(*args, **kwargs)
9+
if http_client is not None:
10+
self._client = http_client
11+
if async_http_client is not None:
12+
self._async_client = async_http_client
13+
14+
class UiPathFireworks(Fireworks):
15+

0 commit comments

Comments
 (0)