-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbase.py
More file actions
149 lines (121 loc) · 4.73 KB
/
Copy pathbase.py
File metadata and controls
149 lines (121 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"""
Base Settings Module for UiPath LLM Client
This module defines the abstract base classes and data models for UiPath API settings.
Concrete implementations are provided in the `agenthub` and `llmgateway` submodules.
"""
from abc import ABC, abstractmethod
from collections.abc import Mapping
from typing import Any, Literal, Self
from httpx import Auth
from pydantic import BaseModel, model_validator
from pydantic_settings import BaseSettings, SettingsConfigDict
class UiPathAPIConfig(BaseModel):
"""Configuration for UiPath API request routing.
This model defines how requests are routed to the appropriate API endpoint.
Attributes:
api_type: The type of API call - "completions" for chat or "embeddings".
client_type: API mode - "passthrough" for vendor-specific APIs or
"normalized" for UiPath's provider-agnostic API.
vendor_type: The LLM vendor (e.g., "openai", "vertexai", "awsbedrock").
Required when client_type is "passthrough".
api_flavor: Vendor-specific API flavor (e.g., "chat-completions", "responses").
api_version: Vendor-specific API version (e.g., "2025-03-01-preview").
freeze_base_url: If True, prevents httpx from modifying the base URL.
Used when the URL must remain exactly as configured.
Example:
>>> # For OpenAI passthrough
>>> settings = UiPathAPIConfig(
... api_type="completions",
... client_type="passthrough",
... vendor_type="openai",
... )
>>>
>>> # For normalized API
>>> settings = UiPathAPIConfig(
... api_type="completions",
... client_type="normalized",
... )
"""
api_type: Literal["completions", "embeddings"] | None = None
client_type: Literal["passthrough", "normalized"] | None = None
vendor_type: str | None = None
api_flavor: str | None = None
api_version: str | None = None
freeze_base_url: bool = False
@model_validator(mode="after")
def validate_api_config(self) -> Self:
"""Validate that vendor_type is provided for passthrough mode."""
if self.client_type == "passthrough":
if self.vendor_type is None:
raise ValueError("vendor_type required when client_type='passthrough'")
return self
class UiPathBaseSettings(BaseSettings, ABC):
"""Abstract base class for UiPath client settings.
This class defines the interface that all backend-specific settings must implement.
Subclasses (AgentHubSettings, LLMGatewaySettings) provide
concrete implementations for their respective backends.
The settings are loaded from environment variables using pydantic-settings,
with validation aliases allowing flexible naming conventions.
"""
model_config = SettingsConfigDict(
validate_by_alias=True,
populate_by_name=True,
extra="allow",
)
@abstractmethod
def build_base_url(
self,
*,
model_name: str | None = None,
api_config: UiPathAPIConfig | None = None,
) -> str:
"""Build the base URL for API requests.
Args:
model_name: The name of the model being accessed.
api_config: API routing configuration.
Returns:
The fully-qualified base URL for the API endpoint.
"""
...
@abstractmethod
def build_auth_headers(
self,
*,
model_name: str | None = None,
api_config: UiPathAPIConfig | None = None,
) -> Mapping[str, str]:
"""Build authentication and routing headers for API requests.
Args:
model_name: The name of the model being accessed.
api_config: API routing configuration.
Returns:
A mapping of header names to values.
"""
...
@abstractmethod
def build_auth_pipeline(
self,
) -> Auth:
"""Build an httpx Auth pipeline for request authentication.
Subclasses must implement this method to provide backend-specific
authentication handling.
Returns:
An httpx.Auth instance that handles authentication flow,
including automatic token refresh on 401 responses.
"""
...
@abstractmethod
def get_available_models(
self,
) -> list[dict[str, Any]]:
"""Get the list of available models from the backend.
Subclasses must implement this method to query the backend's
model discovery endpoint.
Returns:
A list of dictionaries containing model information.
"""
...
@abstractmethod
def validate_byo_model(self, model_info: dict[str, Any]) -> None:
"""Validate that the model is a BYOM model."""
...