beamlit 0.0.28rc24__py3-none-any.whl → 0.0.29rc26__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- beamlit/agents/chain.py +93 -0
- beamlit/agents/decorator.py +6 -2
- beamlit/api/agents/get_agent_trace_ids.py +106 -0
- beamlit/api/default/__init__.py +0 -0
- beamlit/api/default/get_trace.py +150 -0
- beamlit/api/default/get_trace_ids.py +233 -0
- beamlit/api/default/get_trace_logs.py +186 -0
- beamlit/api/functions/get_function_trace_ids.py +106 -0
- beamlit/api/models/get_model_trace_ids.py +106 -0
- beamlit/authentication/authentication.py +10 -4
- beamlit/authentication/clientcredentials.py +1 -1
- beamlit/client.py +13 -2
- beamlit/common/settings.py +15 -9
- beamlit/functions/remote/remote.py +37 -20
- beamlit/models/__init__.py +6 -0
- beamlit/models/get_trace_ids_response_200.py +45 -0
- beamlit/models/get_trace_logs_response_200.py +45 -0
- beamlit/models/get_trace_response_200.py +45 -0
- {beamlit-0.0.28rc24.dist-info → beamlit-0.0.29rc26.dist-info}/METADATA +1 -1
- {beamlit-0.0.28rc24.dist-info → beamlit-0.0.29rc26.dist-info}/RECORD +21 -10
- {beamlit-0.0.28rc24.dist-info → beamlit-0.0.29rc26.dist-info}/WHEEL +0 -0
@@ -0,0 +1,186 @@
|
|
1
|
+
from http import HTTPStatus
|
2
|
+
from typing import Any, Optional, Union
|
3
|
+
|
4
|
+
import httpx
|
5
|
+
|
6
|
+
from ... import errors
|
7
|
+
from ...client import AuthenticatedClient, Client
|
8
|
+
from ...models.get_trace_logs_response_200 import GetTraceLogsResponse200
|
9
|
+
from ...types import UNSET, Response, Unset
|
10
|
+
|
11
|
+
|
12
|
+
def _get_kwargs(
|
13
|
+
trace_id: str,
|
14
|
+
*,
|
15
|
+
span_id: Union[Unset, str] = UNSET,
|
16
|
+
limit: Union[Unset, str] = UNSET,
|
17
|
+
) -> dict[str, Any]:
|
18
|
+
params: dict[str, Any] = {}
|
19
|
+
|
20
|
+
params["spanId"] = span_id
|
21
|
+
|
22
|
+
params["limit"] = limit
|
23
|
+
|
24
|
+
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
|
25
|
+
|
26
|
+
_kwargs: dict[str, Any] = {
|
27
|
+
"method": "get",
|
28
|
+
"url": f"/traces/{trace_id}/logs",
|
29
|
+
"params": params,
|
30
|
+
}
|
31
|
+
|
32
|
+
return _kwargs
|
33
|
+
|
34
|
+
|
35
|
+
def _parse_response(
|
36
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
37
|
+
) -> Optional[GetTraceLogsResponse200]:
|
38
|
+
if response.status_code == 200:
|
39
|
+
response_200 = GetTraceLogsResponse200.from_dict(response.json())
|
40
|
+
|
41
|
+
return response_200
|
42
|
+
if client.raise_on_unexpected_status:
|
43
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
44
|
+
else:
|
45
|
+
return None
|
46
|
+
|
47
|
+
|
48
|
+
def _build_response(
|
49
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
50
|
+
) -> Response[GetTraceLogsResponse200]:
|
51
|
+
return Response(
|
52
|
+
status_code=HTTPStatus(response.status_code),
|
53
|
+
content=response.content,
|
54
|
+
headers=response.headers,
|
55
|
+
parsed=_parse_response(client=client, response=response),
|
56
|
+
)
|
57
|
+
|
58
|
+
|
59
|
+
def sync_detailed(
|
60
|
+
trace_id: str,
|
61
|
+
*,
|
62
|
+
client: AuthenticatedClient,
|
63
|
+
span_id: Union[Unset, str] = UNSET,
|
64
|
+
limit: Union[Unset, str] = UNSET,
|
65
|
+
) -> Response[GetTraceLogsResponse200]:
|
66
|
+
"""Get trace logs
|
67
|
+
|
68
|
+
Args:
|
69
|
+
trace_id (str):
|
70
|
+
span_id (Union[Unset, str]):
|
71
|
+
limit (Union[Unset, str]):
|
72
|
+
|
73
|
+
Raises:
|
74
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
75
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
76
|
+
|
77
|
+
Returns:
|
78
|
+
Response[GetTraceLogsResponse200]
|
79
|
+
"""
|
80
|
+
|
81
|
+
kwargs = _get_kwargs(
|
82
|
+
trace_id=trace_id,
|
83
|
+
span_id=span_id,
|
84
|
+
limit=limit,
|
85
|
+
)
|
86
|
+
|
87
|
+
response = client.get_httpx_client().request(
|
88
|
+
**kwargs,
|
89
|
+
)
|
90
|
+
|
91
|
+
return _build_response(client=client, response=response)
|
92
|
+
|
93
|
+
|
94
|
+
def sync(
|
95
|
+
trace_id: str,
|
96
|
+
*,
|
97
|
+
client: AuthenticatedClient,
|
98
|
+
span_id: Union[Unset, str] = UNSET,
|
99
|
+
limit: Union[Unset, str] = UNSET,
|
100
|
+
) -> Optional[GetTraceLogsResponse200]:
|
101
|
+
"""Get trace logs
|
102
|
+
|
103
|
+
Args:
|
104
|
+
trace_id (str):
|
105
|
+
span_id (Union[Unset, str]):
|
106
|
+
limit (Union[Unset, str]):
|
107
|
+
|
108
|
+
Raises:
|
109
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
110
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
111
|
+
|
112
|
+
Returns:
|
113
|
+
GetTraceLogsResponse200
|
114
|
+
"""
|
115
|
+
|
116
|
+
return sync_detailed(
|
117
|
+
trace_id=trace_id,
|
118
|
+
client=client,
|
119
|
+
span_id=span_id,
|
120
|
+
limit=limit,
|
121
|
+
).parsed
|
122
|
+
|
123
|
+
|
124
|
+
async def asyncio_detailed(
|
125
|
+
trace_id: str,
|
126
|
+
*,
|
127
|
+
client: AuthenticatedClient,
|
128
|
+
span_id: Union[Unset, str] = UNSET,
|
129
|
+
limit: Union[Unset, str] = UNSET,
|
130
|
+
) -> Response[GetTraceLogsResponse200]:
|
131
|
+
"""Get trace logs
|
132
|
+
|
133
|
+
Args:
|
134
|
+
trace_id (str):
|
135
|
+
span_id (Union[Unset, str]):
|
136
|
+
limit (Union[Unset, str]):
|
137
|
+
|
138
|
+
Raises:
|
139
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
140
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
141
|
+
|
142
|
+
Returns:
|
143
|
+
Response[GetTraceLogsResponse200]
|
144
|
+
"""
|
145
|
+
|
146
|
+
kwargs = _get_kwargs(
|
147
|
+
trace_id=trace_id,
|
148
|
+
span_id=span_id,
|
149
|
+
limit=limit,
|
150
|
+
)
|
151
|
+
|
152
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
153
|
+
|
154
|
+
return _build_response(client=client, response=response)
|
155
|
+
|
156
|
+
|
157
|
+
async def asyncio(
|
158
|
+
trace_id: str,
|
159
|
+
*,
|
160
|
+
client: AuthenticatedClient,
|
161
|
+
span_id: Union[Unset, str] = UNSET,
|
162
|
+
limit: Union[Unset, str] = UNSET,
|
163
|
+
) -> Optional[GetTraceLogsResponse200]:
|
164
|
+
"""Get trace logs
|
165
|
+
|
166
|
+
Args:
|
167
|
+
trace_id (str):
|
168
|
+
span_id (Union[Unset, str]):
|
169
|
+
limit (Union[Unset, str]):
|
170
|
+
|
171
|
+
Raises:
|
172
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
173
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
174
|
+
|
175
|
+
Returns:
|
176
|
+
GetTraceLogsResponse200
|
177
|
+
"""
|
178
|
+
|
179
|
+
return (
|
180
|
+
await asyncio_detailed(
|
181
|
+
trace_id=trace_id,
|
182
|
+
client=client,
|
183
|
+
span_id=span_id,
|
184
|
+
limit=limit,
|
185
|
+
)
|
186
|
+
).parsed
|
@@ -0,0 +1,106 @@
|
|
1
|
+
from http import HTTPStatus
|
2
|
+
from typing import Any, Optional, Union
|
3
|
+
|
4
|
+
import httpx
|
5
|
+
|
6
|
+
from ... import errors
|
7
|
+
from ...client import AuthenticatedClient, Client
|
8
|
+
from ...types import UNSET, Response, Unset
|
9
|
+
|
10
|
+
|
11
|
+
def _get_kwargs(
|
12
|
+
function_name: str,
|
13
|
+
*,
|
14
|
+
environment: Union[Unset, str] = UNSET,
|
15
|
+
) -> dict[str, Any]:
|
16
|
+
params: dict[str, Any] = {}
|
17
|
+
|
18
|
+
params["environment"] = environment
|
19
|
+
|
20
|
+
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
|
21
|
+
|
22
|
+
_kwargs: dict[str, Any] = {
|
23
|
+
"method": "get",
|
24
|
+
"url": f"/functions/{function_name}/traces",
|
25
|
+
"params": params,
|
26
|
+
}
|
27
|
+
|
28
|
+
return _kwargs
|
29
|
+
|
30
|
+
|
31
|
+
def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]:
|
32
|
+
if client.raise_on_unexpected_status:
|
33
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
34
|
+
else:
|
35
|
+
return None
|
36
|
+
|
37
|
+
|
38
|
+
def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]:
|
39
|
+
return Response(
|
40
|
+
status_code=HTTPStatus(response.status_code),
|
41
|
+
content=response.content,
|
42
|
+
headers=response.headers,
|
43
|
+
parsed=_parse_response(client=client, response=response),
|
44
|
+
)
|
45
|
+
|
46
|
+
|
47
|
+
def sync_detailed(
|
48
|
+
function_name: str,
|
49
|
+
*,
|
50
|
+
client: AuthenticatedClient,
|
51
|
+
environment: Union[Unset, str] = UNSET,
|
52
|
+
) -> Response[Any]:
|
53
|
+
"""Get function trace IDs
|
54
|
+
|
55
|
+
Args:
|
56
|
+
function_name (str):
|
57
|
+
environment (Union[Unset, str]):
|
58
|
+
|
59
|
+
Raises:
|
60
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
61
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
62
|
+
|
63
|
+
Returns:
|
64
|
+
Response[Any]
|
65
|
+
"""
|
66
|
+
|
67
|
+
kwargs = _get_kwargs(
|
68
|
+
function_name=function_name,
|
69
|
+
environment=environment,
|
70
|
+
)
|
71
|
+
|
72
|
+
response = client.get_httpx_client().request(
|
73
|
+
**kwargs,
|
74
|
+
)
|
75
|
+
|
76
|
+
return _build_response(client=client, response=response)
|
77
|
+
|
78
|
+
|
79
|
+
async def asyncio_detailed(
|
80
|
+
function_name: str,
|
81
|
+
*,
|
82
|
+
client: AuthenticatedClient,
|
83
|
+
environment: Union[Unset, str] = UNSET,
|
84
|
+
) -> Response[Any]:
|
85
|
+
"""Get function trace IDs
|
86
|
+
|
87
|
+
Args:
|
88
|
+
function_name (str):
|
89
|
+
environment (Union[Unset, str]):
|
90
|
+
|
91
|
+
Raises:
|
92
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
93
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
94
|
+
|
95
|
+
Returns:
|
96
|
+
Response[Any]
|
97
|
+
"""
|
98
|
+
|
99
|
+
kwargs = _get_kwargs(
|
100
|
+
function_name=function_name,
|
101
|
+
environment=environment,
|
102
|
+
)
|
103
|
+
|
104
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
105
|
+
|
106
|
+
return _build_response(client=client, response=response)
|
@@ -0,0 +1,106 @@
|
|
1
|
+
from http import HTTPStatus
|
2
|
+
from typing import Any, Optional, Union
|
3
|
+
|
4
|
+
import httpx
|
5
|
+
|
6
|
+
from ... import errors
|
7
|
+
from ...client import AuthenticatedClient, Client
|
8
|
+
from ...types import UNSET, Response, Unset
|
9
|
+
|
10
|
+
|
11
|
+
def _get_kwargs(
|
12
|
+
model_name: str,
|
13
|
+
*,
|
14
|
+
environment: Union[Unset, str] = UNSET,
|
15
|
+
) -> dict[str, Any]:
|
16
|
+
params: dict[str, Any] = {}
|
17
|
+
|
18
|
+
params["environment"] = environment
|
19
|
+
|
20
|
+
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
|
21
|
+
|
22
|
+
_kwargs: dict[str, Any] = {
|
23
|
+
"method": "get",
|
24
|
+
"url": f"/models/{model_name}/traces",
|
25
|
+
"params": params,
|
26
|
+
}
|
27
|
+
|
28
|
+
return _kwargs
|
29
|
+
|
30
|
+
|
31
|
+
def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]:
|
32
|
+
if client.raise_on_unexpected_status:
|
33
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
34
|
+
else:
|
35
|
+
return None
|
36
|
+
|
37
|
+
|
38
|
+
def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]:
|
39
|
+
return Response(
|
40
|
+
status_code=HTTPStatus(response.status_code),
|
41
|
+
content=response.content,
|
42
|
+
headers=response.headers,
|
43
|
+
parsed=_parse_response(client=client, response=response),
|
44
|
+
)
|
45
|
+
|
46
|
+
|
47
|
+
def sync_detailed(
|
48
|
+
model_name: str,
|
49
|
+
*,
|
50
|
+
client: AuthenticatedClient,
|
51
|
+
environment: Union[Unset, str] = UNSET,
|
52
|
+
) -> Response[Any]:
|
53
|
+
"""Get model trace IDs
|
54
|
+
|
55
|
+
Args:
|
56
|
+
model_name (str):
|
57
|
+
environment (Union[Unset, str]):
|
58
|
+
|
59
|
+
Raises:
|
60
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
61
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
62
|
+
|
63
|
+
Returns:
|
64
|
+
Response[Any]
|
65
|
+
"""
|
66
|
+
|
67
|
+
kwargs = _get_kwargs(
|
68
|
+
model_name=model_name,
|
69
|
+
environment=environment,
|
70
|
+
)
|
71
|
+
|
72
|
+
response = client.get_httpx_client().request(
|
73
|
+
**kwargs,
|
74
|
+
)
|
75
|
+
|
76
|
+
return _build_response(client=client, response=response)
|
77
|
+
|
78
|
+
|
79
|
+
async def asyncio_detailed(
|
80
|
+
model_name: str,
|
81
|
+
*,
|
82
|
+
client: AuthenticatedClient,
|
83
|
+
environment: Union[Unset, str] = UNSET,
|
84
|
+
) -> Response[Any]:
|
85
|
+
"""Get model trace IDs
|
86
|
+
|
87
|
+
Args:
|
88
|
+
model_name (str):
|
89
|
+
environment (Union[Unset, str]):
|
90
|
+
|
91
|
+
Raises:
|
92
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
93
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
94
|
+
|
95
|
+
Returns:
|
96
|
+
Response[Any]
|
97
|
+
"""
|
98
|
+
|
99
|
+
kwargs = _get_kwargs(
|
100
|
+
model_name=model_name,
|
101
|
+
environment=environment,
|
102
|
+
)
|
103
|
+
|
104
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
105
|
+
|
106
|
+
return _build_response(client=client, response=response)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
from dataclasses import dataclass
|
2
2
|
from typing import Dict, Generator
|
3
|
+
import os
|
3
4
|
|
4
5
|
from httpx import Auth, Request, Response
|
5
6
|
|
@@ -26,8 +27,13 @@ class PublicProvider(Auth):
|
|
26
27
|
class RunClientWithCredentials:
|
27
28
|
credentials: Credentials
|
28
29
|
workspace: str
|
29
|
-
api_url: str = "https://api.beamlit.
|
30
|
-
run_url: str = "https://run.beamlit.
|
30
|
+
api_url: str = "https://api.beamlit.com/v0"
|
31
|
+
run_url: str = "https://run.beamlit.com/v0"
|
32
|
+
|
33
|
+
def __post_init__(self):
|
34
|
+
if os.getenv('BL_ENV') == 'dev':
|
35
|
+
self.api_url = "https://api.beamlit.dev/v0"
|
36
|
+
self.run_url = "https://run.beamlit.dev/v0"
|
31
37
|
|
32
38
|
|
33
39
|
def new_client_from_settings(settings: Settings):
|
@@ -41,15 +47,15 @@ def new_client_from_settings(settings: Settings):
|
|
41
47
|
|
42
48
|
|
43
49
|
def new_client():
|
50
|
+
settings = get_settings()
|
44
51
|
context = current_context()
|
45
|
-
if context.workspace:
|
52
|
+
if context.workspace and not settings.authentication.client.credentials:
|
46
53
|
credentials = load_credentials(context.workspace)
|
47
54
|
client_config = RunClientWithCredentials(
|
48
55
|
credentials=credentials,
|
49
56
|
workspace=context.workspace,
|
50
57
|
)
|
51
58
|
else:
|
52
|
-
settings = get_settings()
|
53
59
|
credentials = load_credentials_from_settings(settings)
|
54
60
|
client_config = RunClientWithCredentials(
|
55
61
|
credentials=credentials,
|
@@ -37,7 +37,7 @@ class ClientCredentials(Auth):
|
|
37
37
|
def refresh_if_needed(self) -> Optional[Exception]:
|
38
38
|
settings = get_settings()
|
39
39
|
if self.credentials.client_credentials and not self.credentials.refresh_token:
|
40
|
-
headers = {"Authorization": f"Basic {self.credentials.client_credentials}"}
|
40
|
+
headers = {"Authorization": f"Basic {self.credentials.client_credentials}", "Content-Type": "application/json"}
|
41
41
|
body = {"grant_type": "client_credentials"}
|
42
42
|
response = requests.post(f"{settings.base_url}/oauth/token", headers=headers, json=body)
|
43
43
|
response.raise_for_status()
|
beamlit/client.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import os
|
1
2
|
import ssl
|
2
3
|
from typing import Any, Optional, Union
|
3
4
|
|
@@ -37,8 +38,13 @@ class Client:
|
|
37
38
|
|
38
39
|
"""
|
39
40
|
|
41
|
+
# Determine the base URL based on the environment
|
42
|
+
default_base_url = "https://api.beamlit.com/v0"
|
43
|
+
if os.getenv("BL_ENV") == "dev":
|
44
|
+
default_base_url = "https://api.beamlit.dev/v0"
|
45
|
+
|
40
46
|
raise_on_unexpected_status: bool = field(default=True, kw_only=True)
|
41
|
-
_base_url: str = field(alias="base_url", default=
|
47
|
+
_base_url: str = field(alias="base_url", default=default_base_url)
|
42
48
|
_cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
|
43
49
|
_headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
|
44
50
|
_provider: httpx.Auth = field(default=None, alias="provider")
|
@@ -169,8 +175,13 @@ class AuthenticatedClient:
|
|
169
175
|
provider: AuthProvider to use for authentication
|
170
176
|
"""
|
171
177
|
|
178
|
+
# Determine the base URL based on the environment
|
179
|
+
default_base_url = "https://api.beamlit.com/v0"
|
180
|
+
if os.getenv("BL_ENV") == "dev":
|
181
|
+
default_base_url = "https://api.beamlit.dev/v0"
|
182
|
+
|
172
183
|
raise_on_unexpected_status: bool = field(default=True, kw_only=True)
|
173
|
-
_base_url: str = field(alias="base_url", default=
|
184
|
+
_base_url: str = field(alias="base_url", default=default_base_url)
|
174
185
|
_cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
|
175
186
|
_headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
|
176
187
|
_provider: httpx.Auth = field(default=None, alias="provider")
|
beamlit/common/settings.py
CHANGED
@@ -18,11 +18,6 @@ from pydantic_settings import (BaseSettings, PydanticBaseSettingsSource,
|
|
18
18
|
global SETTINGS
|
19
19
|
SETTINGS = None
|
20
20
|
|
21
|
-
|
22
|
-
def get_settings():
|
23
|
-
return SETTINGS
|
24
|
-
|
25
|
-
|
26
21
|
class SettingsAgent(BaseSettings):
|
27
22
|
agent: Union[None, CompiledGraph, BaseChatModel] = None
|
28
23
|
chain: Union[Unset, list[Agent]] = UNSET
|
@@ -62,15 +57,23 @@ class Settings(BaseSettings):
|
|
62
57
|
remote: bool = Field(default=False)
|
63
58
|
type: str = Field(default="agent")
|
64
59
|
name: str = Field(default="beamlit-agent")
|
65
|
-
base_url: str = Field(default="https://api.beamlit.
|
66
|
-
run_url: str = Field(default="https://run.beamlit.
|
67
|
-
mcp_hub_url: str = Field(default="https://mcp-hub-server.beamlit.workers.
|
68
|
-
registry_url: str = Field(default="https://serverless-registry-production.beamlit.workers.
|
60
|
+
base_url: str = Field(default="https://api.beamlit.com/v0")
|
61
|
+
run_url: str = Field(default="https://run.beamlit.com")
|
62
|
+
mcp_hub_url: str = Field(default="https://mcp-hub-server.beamlit.workers.com")
|
63
|
+
registry_url: str = Field(default="https://serverless-registry-production.beamlit.workers.com")
|
69
64
|
log_level: str = Field(default="INFO")
|
70
65
|
agent: SettingsAgent = SettingsAgent()
|
71
66
|
server: SettingsServer = SettingsServer()
|
72
67
|
authentication: SettingsAuthentication = SettingsAuthentication()
|
73
68
|
|
69
|
+
def __init__(self, **data):
|
70
|
+
super().__init__(**data)
|
71
|
+
if os.getenv('BL_ENV') == 'dev':
|
72
|
+
self.base_url = "https://api.beamlit.dev/v0"
|
73
|
+
self.run_url = "https://run.beamlit.dev"
|
74
|
+
self.mcp_hub_url = "https://mcp-hub-server.beamlit.workers.dev"
|
75
|
+
self.registry_url = "https://serverless-registry-production.beamlit.workers.dev"
|
76
|
+
|
74
77
|
@classmethod
|
75
78
|
def settings_customise_sources(
|
76
79
|
cls,
|
@@ -88,6 +91,9 @@ class Settings(BaseSettings):
|
|
88
91
|
init_settings,
|
89
92
|
)
|
90
93
|
|
94
|
+
def get_settings() -> Settings:
|
95
|
+
return SETTINGS
|
96
|
+
|
91
97
|
|
92
98
|
def init_agent(
|
93
99
|
client: AuthenticatedClient,
|
@@ -1,20 +1,21 @@
|
|
1
1
|
import asyncio
|
2
|
-
import urllib.parse
|
3
2
|
import warnings
|
4
3
|
from typing import Any, Callable
|
5
4
|
|
6
5
|
import pydantic
|
7
|
-
import pydantic_core
|
8
6
|
import typing_extensions as t
|
7
|
+
from dataclasses import dataclass
|
9
8
|
from beamlit.api.functions import get_function
|
10
9
|
from beamlit.authentication.authentication import AuthenticatedClient
|
11
|
-
from beamlit.
|
12
|
-
from
|
10
|
+
from beamlit.run import RunClient
|
11
|
+
from beamlit.common.settings import get_settings
|
12
|
+
from beamlit.models import Function, StoreFunctionParameter
|
13
|
+
from langchain_core.tools.base import BaseTool, ToolException
|
13
14
|
from pydantic.json_schema import JsonSchemaValue
|
14
15
|
from pydantic_core import core_schema as cs
|
15
16
|
|
16
17
|
|
17
|
-
def create_schema_model(
|
18
|
+
def create_schema_model(parameters: list[StoreFunctionParameter]) -> type[pydantic.BaseModel]:
|
18
19
|
# Create a new model class that returns our JSON schema.
|
19
20
|
# LangChain requires a BaseModel class.
|
20
21
|
class Schema(pydantic.BaseModel):
|
@@ -25,6 +26,18 @@ def create_schema_model(schema: dict[str, t.Any]) -> type[pydantic.BaseModel]:
|
|
25
26
|
def __get_pydantic_json_schema__(
|
26
27
|
cls, core_schema: cs.CoreSchema, handler: pydantic.GetJsonSchemaHandler
|
27
28
|
) -> JsonSchemaValue:
|
29
|
+
schema = {
|
30
|
+
"type": "object",
|
31
|
+
"properties": {},
|
32
|
+
"required": [],
|
33
|
+
}
|
34
|
+
for parameter in parameters:
|
35
|
+
schema["properties"][parameter.name] = {
|
36
|
+
"type": parameter.type_,
|
37
|
+
"description": parameter.description,
|
38
|
+
}
|
39
|
+
if parameter.required:
|
40
|
+
schema["required"].append(parameter.name)
|
28
41
|
return schema
|
29
42
|
|
30
43
|
return Schema
|
@@ -35,7 +48,7 @@ class RemoteTool(BaseTool):
|
|
35
48
|
Remote tool
|
36
49
|
"""
|
37
50
|
|
38
|
-
client:
|
51
|
+
client: RunClient
|
39
52
|
handle_tool_error: bool | str | Callable[[ToolException], str] | None = True
|
40
53
|
|
41
54
|
@t.override
|
@@ -48,12 +61,15 @@ class RemoteTool(BaseTool):
|
|
48
61
|
|
49
62
|
@t.override
|
50
63
|
async def _arun(self, *args: t.Any, **kwargs: t.Any) -> t.Any:
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
64
|
+
settings = get_settings()
|
65
|
+
result = self.client.run(
|
66
|
+
"function",
|
67
|
+
self.name,
|
68
|
+
settings.environment,
|
69
|
+
"POST",
|
70
|
+
kwargs,
|
71
|
+
)
|
72
|
+
return result.text
|
57
73
|
|
58
74
|
@t.override
|
59
75
|
@property
|
@@ -61,7 +77,8 @@ class RemoteTool(BaseTool):
|
|
61
77
|
assert self.args_schema is not None # noqa: S101
|
62
78
|
return self.args_schema
|
63
79
|
|
64
|
-
|
80
|
+
@dataclass
|
81
|
+
class RemoteToolkit:
|
65
82
|
"""
|
66
83
|
Remote toolkit
|
67
84
|
"""
|
@@ -75,27 +92,27 @@ class RemoteToolkit(BaseToolkit):
|
|
75
92
|
def initialize(self) -> None:
|
76
93
|
"""Initialize the session and retrieve tools list"""
|
77
94
|
if self._function is None:
|
78
|
-
self._function = get_function(self.function, client=self.client)
|
95
|
+
self._function = get_function.sync_detailed(self.function, client=self.client).parsed
|
79
96
|
|
80
97
|
@t.override
|
81
98
|
def get_tools(self) -> list[BaseTool]:
|
82
|
-
if self.
|
99
|
+
if self._function is None:
|
83
100
|
raise RuntimeError("Must initialize the toolkit first")
|
84
101
|
|
85
102
|
if self._function.spec.kit:
|
86
103
|
return [
|
87
104
|
RemoteTool(
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
105
|
+
client=RunClient(self.client),
|
106
|
+
name=func.name,
|
107
|
+
description=func.description or "",
|
108
|
+
args_schema=create_schema_model(func.parameters),
|
92
109
|
)
|
93
110
|
for func in self._function.spec.kit
|
94
111
|
]
|
95
112
|
|
96
113
|
return [
|
97
114
|
RemoteTool(
|
98
|
-
client=self.client,
|
115
|
+
client=RunClient(self.client),
|
99
116
|
name=self._function.metadata.name,
|
100
117
|
description=self._function.spec.description or "",
|
101
118
|
args_schema=create_schema_model(self._function.spec.parameters),
|
beamlit/models/__init__.py
CHANGED
@@ -29,6 +29,9 @@ from .function_kit import FunctionKit
|
|
29
29
|
from .function_metadata import FunctionMetadata
|
30
30
|
from .function_release import FunctionRelease
|
31
31
|
from .function_spec import FunctionSpec
|
32
|
+
from .get_trace_ids_response_200 import GetTraceIdsResponse200
|
33
|
+
from .get_trace_logs_response_200 import GetTraceLogsResponse200
|
34
|
+
from .get_trace_response_200 import GetTraceResponse200
|
32
35
|
from .get_workspace_service_accounts_response_200_item import GetWorkspaceServiceAccountsResponse200Item
|
33
36
|
from .increase_and_rate_metric import IncreaseAndRateMetric
|
34
37
|
from .integration_config import IntegrationConfig
|
@@ -128,6 +131,9 @@ __all__ = (
|
|
128
131
|
"FunctionMetadata",
|
129
132
|
"FunctionRelease",
|
130
133
|
"FunctionSpec",
|
134
|
+
"GetTraceIdsResponse200",
|
135
|
+
"GetTraceLogsResponse200",
|
136
|
+
"GetTraceResponse200",
|
131
137
|
"GetWorkspaceServiceAccountsResponse200Item",
|
132
138
|
"IncreaseAndRateMetric",
|
133
139
|
"IntegrationConfig",
|