beamlit 0.0.28rc24__py3-none-any.whl → 0.0.29__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- beamlit/agents/chain.py +93 -0
- beamlit/agents/decorator.py +14 -4
- beamlit/api/agents/get_agent_trace_ids.py +171 -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 +171 -0
- beamlit/api/models/get_model_trace_ids.py +171 -0
- beamlit/authentication/authentication.py +16 -13
- beamlit/authentication/clientcredentials.py +1 -1
- beamlit/client.py +14 -2
- beamlit/common/settings.py +15 -9
- beamlit/deploy/deploy.py +5 -5
- beamlit/functions/mcp/mcp.py +26 -18
- beamlit/functions/remote/remote.py +58 -39
- beamlit/models/__init__.py +8 -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/models/trace_ids_response.py +63 -0
- {beamlit-0.0.28rc24.dist-info → beamlit-0.0.29.dist-info}/METADATA +1 -1
- {beamlit-0.0.28rc24.dist-info → beamlit-0.0.29.dist-info}/RECORD +24 -12
- {beamlit-0.0.28rc24.dist-info → beamlit-0.0.29.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,171 @@
|
|
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.trace_ids_response import TraceIdsResponse
|
9
|
+
from ...types import UNSET, Response, Unset
|
10
|
+
|
11
|
+
|
12
|
+
def _get_kwargs(
|
13
|
+
function_name: str,
|
14
|
+
*,
|
15
|
+
environment: Union[Unset, str] = UNSET,
|
16
|
+
) -> dict[str, Any]:
|
17
|
+
params: dict[str, Any] = {}
|
18
|
+
|
19
|
+
params["environment"] = environment
|
20
|
+
|
21
|
+
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
|
22
|
+
|
23
|
+
_kwargs: dict[str, Any] = {
|
24
|
+
"method": "get",
|
25
|
+
"url": f"/functions/{function_name}/traces",
|
26
|
+
"params": params,
|
27
|
+
}
|
28
|
+
|
29
|
+
return _kwargs
|
30
|
+
|
31
|
+
|
32
|
+
def _parse_response(
|
33
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
34
|
+
) -> Optional[TraceIdsResponse]:
|
35
|
+
if response.status_code == 200:
|
36
|
+
response_200 = TraceIdsResponse.from_dict(response.json())
|
37
|
+
|
38
|
+
return response_200
|
39
|
+
if client.raise_on_unexpected_status:
|
40
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
41
|
+
else:
|
42
|
+
return None
|
43
|
+
|
44
|
+
|
45
|
+
def _build_response(
|
46
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
47
|
+
) -> Response[TraceIdsResponse]:
|
48
|
+
return Response(
|
49
|
+
status_code=HTTPStatus(response.status_code),
|
50
|
+
content=response.content,
|
51
|
+
headers=response.headers,
|
52
|
+
parsed=_parse_response(client=client, response=response),
|
53
|
+
)
|
54
|
+
|
55
|
+
|
56
|
+
def sync_detailed(
|
57
|
+
function_name: str,
|
58
|
+
*,
|
59
|
+
client: AuthenticatedClient,
|
60
|
+
environment: Union[Unset, str] = UNSET,
|
61
|
+
) -> Response[TraceIdsResponse]:
|
62
|
+
"""Get function trace IDs
|
63
|
+
|
64
|
+
Args:
|
65
|
+
function_name (str):
|
66
|
+
environment (Union[Unset, str]):
|
67
|
+
|
68
|
+
Raises:
|
69
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
70
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
71
|
+
|
72
|
+
Returns:
|
73
|
+
Response[TraceIdsResponse]
|
74
|
+
"""
|
75
|
+
|
76
|
+
kwargs = _get_kwargs(
|
77
|
+
function_name=function_name,
|
78
|
+
environment=environment,
|
79
|
+
)
|
80
|
+
|
81
|
+
response = client.get_httpx_client().request(
|
82
|
+
**kwargs,
|
83
|
+
)
|
84
|
+
|
85
|
+
return _build_response(client=client, response=response)
|
86
|
+
|
87
|
+
|
88
|
+
def sync(
|
89
|
+
function_name: str,
|
90
|
+
*,
|
91
|
+
client: AuthenticatedClient,
|
92
|
+
environment: Union[Unset, str] = UNSET,
|
93
|
+
) -> Optional[TraceIdsResponse]:
|
94
|
+
"""Get function trace IDs
|
95
|
+
|
96
|
+
Args:
|
97
|
+
function_name (str):
|
98
|
+
environment (Union[Unset, str]):
|
99
|
+
|
100
|
+
Raises:
|
101
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
102
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
103
|
+
|
104
|
+
Returns:
|
105
|
+
TraceIdsResponse
|
106
|
+
"""
|
107
|
+
|
108
|
+
return sync_detailed(
|
109
|
+
function_name=function_name,
|
110
|
+
client=client,
|
111
|
+
environment=environment,
|
112
|
+
).parsed
|
113
|
+
|
114
|
+
|
115
|
+
async def asyncio_detailed(
|
116
|
+
function_name: str,
|
117
|
+
*,
|
118
|
+
client: AuthenticatedClient,
|
119
|
+
environment: Union[Unset, str] = UNSET,
|
120
|
+
) -> Response[TraceIdsResponse]:
|
121
|
+
"""Get function trace IDs
|
122
|
+
|
123
|
+
Args:
|
124
|
+
function_name (str):
|
125
|
+
environment (Union[Unset, str]):
|
126
|
+
|
127
|
+
Raises:
|
128
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
129
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
130
|
+
|
131
|
+
Returns:
|
132
|
+
Response[TraceIdsResponse]
|
133
|
+
"""
|
134
|
+
|
135
|
+
kwargs = _get_kwargs(
|
136
|
+
function_name=function_name,
|
137
|
+
environment=environment,
|
138
|
+
)
|
139
|
+
|
140
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
141
|
+
|
142
|
+
return _build_response(client=client, response=response)
|
143
|
+
|
144
|
+
|
145
|
+
async def asyncio(
|
146
|
+
function_name: str,
|
147
|
+
*,
|
148
|
+
client: AuthenticatedClient,
|
149
|
+
environment: Union[Unset, str] = UNSET,
|
150
|
+
) -> Optional[TraceIdsResponse]:
|
151
|
+
"""Get function trace IDs
|
152
|
+
|
153
|
+
Args:
|
154
|
+
function_name (str):
|
155
|
+
environment (Union[Unset, str]):
|
156
|
+
|
157
|
+
Raises:
|
158
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
159
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
160
|
+
|
161
|
+
Returns:
|
162
|
+
TraceIdsResponse
|
163
|
+
"""
|
164
|
+
|
165
|
+
return (
|
166
|
+
await asyncio_detailed(
|
167
|
+
function_name=function_name,
|
168
|
+
client=client,
|
169
|
+
environment=environment,
|
170
|
+
)
|
171
|
+
).parsed
|
@@ -0,0 +1,171 @@
|
|
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.trace_ids_response import TraceIdsResponse
|
9
|
+
from ...types import UNSET, Response, Unset
|
10
|
+
|
11
|
+
|
12
|
+
def _get_kwargs(
|
13
|
+
model_name: str,
|
14
|
+
*,
|
15
|
+
environment: Union[Unset, str] = UNSET,
|
16
|
+
) -> dict[str, Any]:
|
17
|
+
params: dict[str, Any] = {}
|
18
|
+
|
19
|
+
params["environment"] = environment
|
20
|
+
|
21
|
+
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
|
22
|
+
|
23
|
+
_kwargs: dict[str, Any] = {
|
24
|
+
"method": "get",
|
25
|
+
"url": f"/models/{model_name}/traces",
|
26
|
+
"params": params,
|
27
|
+
}
|
28
|
+
|
29
|
+
return _kwargs
|
30
|
+
|
31
|
+
|
32
|
+
def _parse_response(
|
33
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
34
|
+
) -> Optional[TraceIdsResponse]:
|
35
|
+
if response.status_code == 200:
|
36
|
+
response_200 = TraceIdsResponse.from_dict(response.json())
|
37
|
+
|
38
|
+
return response_200
|
39
|
+
if client.raise_on_unexpected_status:
|
40
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
41
|
+
else:
|
42
|
+
return None
|
43
|
+
|
44
|
+
|
45
|
+
def _build_response(
|
46
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
47
|
+
) -> Response[TraceIdsResponse]:
|
48
|
+
return Response(
|
49
|
+
status_code=HTTPStatus(response.status_code),
|
50
|
+
content=response.content,
|
51
|
+
headers=response.headers,
|
52
|
+
parsed=_parse_response(client=client, response=response),
|
53
|
+
)
|
54
|
+
|
55
|
+
|
56
|
+
def sync_detailed(
|
57
|
+
model_name: str,
|
58
|
+
*,
|
59
|
+
client: AuthenticatedClient,
|
60
|
+
environment: Union[Unset, str] = UNSET,
|
61
|
+
) -> Response[TraceIdsResponse]:
|
62
|
+
"""Get model trace IDs
|
63
|
+
|
64
|
+
Args:
|
65
|
+
model_name (str):
|
66
|
+
environment (Union[Unset, str]):
|
67
|
+
|
68
|
+
Raises:
|
69
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
70
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
71
|
+
|
72
|
+
Returns:
|
73
|
+
Response[TraceIdsResponse]
|
74
|
+
"""
|
75
|
+
|
76
|
+
kwargs = _get_kwargs(
|
77
|
+
model_name=model_name,
|
78
|
+
environment=environment,
|
79
|
+
)
|
80
|
+
|
81
|
+
response = client.get_httpx_client().request(
|
82
|
+
**kwargs,
|
83
|
+
)
|
84
|
+
|
85
|
+
return _build_response(client=client, response=response)
|
86
|
+
|
87
|
+
|
88
|
+
def sync(
|
89
|
+
model_name: str,
|
90
|
+
*,
|
91
|
+
client: AuthenticatedClient,
|
92
|
+
environment: Union[Unset, str] = UNSET,
|
93
|
+
) -> Optional[TraceIdsResponse]:
|
94
|
+
"""Get model trace IDs
|
95
|
+
|
96
|
+
Args:
|
97
|
+
model_name (str):
|
98
|
+
environment (Union[Unset, str]):
|
99
|
+
|
100
|
+
Raises:
|
101
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
102
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
103
|
+
|
104
|
+
Returns:
|
105
|
+
TraceIdsResponse
|
106
|
+
"""
|
107
|
+
|
108
|
+
return sync_detailed(
|
109
|
+
model_name=model_name,
|
110
|
+
client=client,
|
111
|
+
environment=environment,
|
112
|
+
).parsed
|
113
|
+
|
114
|
+
|
115
|
+
async def asyncio_detailed(
|
116
|
+
model_name: str,
|
117
|
+
*,
|
118
|
+
client: AuthenticatedClient,
|
119
|
+
environment: Union[Unset, str] = UNSET,
|
120
|
+
) -> Response[TraceIdsResponse]:
|
121
|
+
"""Get model trace IDs
|
122
|
+
|
123
|
+
Args:
|
124
|
+
model_name (str):
|
125
|
+
environment (Union[Unset, str]):
|
126
|
+
|
127
|
+
Raises:
|
128
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
129
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
130
|
+
|
131
|
+
Returns:
|
132
|
+
Response[TraceIdsResponse]
|
133
|
+
"""
|
134
|
+
|
135
|
+
kwargs = _get_kwargs(
|
136
|
+
model_name=model_name,
|
137
|
+
environment=environment,
|
138
|
+
)
|
139
|
+
|
140
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
141
|
+
|
142
|
+
return _build_response(client=client, response=response)
|
143
|
+
|
144
|
+
|
145
|
+
async def asyncio(
|
146
|
+
model_name: str,
|
147
|
+
*,
|
148
|
+
client: AuthenticatedClient,
|
149
|
+
environment: Union[Unset, str] = UNSET,
|
150
|
+
) -> Optional[TraceIdsResponse]:
|
151
|
+
"""Get model trace IDs
|
152
|
+
|
153
|
+
Args:
|
154
|
+
model_name (str):
|
155
|
+
environment (Union[Unset, str]):
|
156
|
+
|
157
|
+
Raises:
|
158
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
159
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
160
|
+
|
161
|
+
Returns:
|
162
|
+
TraceIdsResponse
|
163
|
+
"""
|
164
|
+
|
165
|
+
return (
|
166
|
+
await asyncio_detailed(
|
167
|
+
model_name=model_name,
|
168
|
+
client=client,
|
169
|
+
environment=environment,
|
170
|
+
)
|
171
|
+
).parsed
|
@@ -1,19 +1,15 @@
|
|
1
|
+
import os
|
1
2
|
from dataclasses import dataclass
|
2
3
|
from typing import Dict, Generator
|
3
4
|
|
4
|
-
from httpx import Auth, Request, Response
|
5
|
-
|
6
5
|
from beamlit.common.settings import Settings, get_settings
|
6
|
+
from httpx import Auth, Request, Response
|
7
7
|
|
8
8
|
from ..client import AuthenticatedClient
|
9
9
|
from .apikey import ApiKeyProvider
|
10
10
|
from .clientcredentials import ClientCredentials
|
11
|
-
from .credentials import (
|
12
|
-
|
13
|
-
current_context,
|
14
|
-
load_credentials,
|
15
|
-
load_credentials_from_settings,
|
16
|
-
)
|
11
|
+
from .credentials import (Credentials, current_context, load_credentials,
|
12
|
+
load_credentials_from_settings)
|
17
13
|
from .device_mode import BearerToken
|
18
14
|
|
19
15
|
|
@@ -26,8 +22,15 @@ class PublicProvider(Auth):
|
|
26
22
|
class RunClientWithCredentials:
|
27
23
|
credentials: Credentials
|
28
24
|
workspace: str
|
29
|
-
api_url: str = "
|
30
|
-
run_url: str = "
|
25
|
+
api_url: str = ""
|
26
|
+
run_url: str = ""
|
27
|
+
|
28
|
+
def __post_init__(self):
|
29
|
+
from ..common.settings import get_settings
|
30
|
+
|
31
|
+
settings = get_settings()
|
32
|
+
self.api_url = settings.base_url
|
33
|
+
self.run_url = settings.run_url
|
31
34
|
|
32
35
|
|
33
36
|
def new_client_from_settings(settings: Settings):
|
@@ -41,15 +44,15 @@ def new_client_from_settings(settings: Settings):
|
|
41
44
|
|
42
45
|
|
43
46
|
def new_client():
|
47
|
+
settings = get_settings()
|
44
48
|
context = current_context()
|
45
|
-
if context.workspace:
|
49
|
+
if context.workspace and not settings.authentication.client.credentials:
|
46
50
|
credentials = load_credentials(context.workspace)
|
47
51
|
client_config = RunClientWithCredentials(
|
48
52
|
credentials=credentials,
|
49
53
|
workspace=context.workspace,
|
50
54
|
)
|
51
55
|
else:
|
52
|
-
settings = get_settings()
|
53
56
|
credentials = load_credentials_from_settings(settings)
|
54
57
|
client_config = RunClientWithCredentials(
|
55
58
|
credentials=credentials,
|
@@ -74,7 +77,7 @@ def new_client_with_credentials(config: RunClientWithCredentials):
|
|
74
77
|
|
75
78
|
def get_authentication_headers(settings: Settings) -> Dict[str, str]:
|
76
79
|
context = current_context()
|
77
|
-
if context.workspace:
|
80
|
+
if context.workspace and not settings.authentication.client.credentials:
|
78
81
|
credentials = load_credentials(context.workspace)
|
79
82
|
else:
|
80
83
|
settings = get_settings()
|
@@ -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
@@ -38,7 +38,7 @@ class Client:
|
|
38
38
|
"""
|
39
39
|
|
40
40
|
raise_on_unexpected_status: bool = field(default=True, kw_only=True)
|
41
|
-
_base_url: str = field(alias="base_url", default="
|
41
|
+
_base_url: str = field(alias="base_url", default="")
|
42
42
|
_cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
|
43
43
|
_headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
|
44
44
|
_provider: httpx.Auth = field(default=None, alias="provider")
|
@@ -49,6 +49,12 @@ class Client:
|
|
49
49
|
_client: Optional[httpx.Client] = field(default=None, init=False)
|
50
50
|
_async_client: Optional[httpx.AsyncClient] = field(default=None, init=False)
|
51
51
|
|
52
|
+
def __post_init__(self):
|
53
|
+
from .common.settings import get_settings
|
54
|
+
|
55
|
+
settings = get_settings()
|
56
|
+
self._base_url = settings.base_url
|
57
|
+
|
52
58
|
def with_headers(self, headers: dict[str, str]) -> "Client":
|
53
59
|
"""Get a new client matching this one with additional headers"""
|
54
60
|
if self._client is not None:
|
@@ -170,7 +176,7 @@ class AuthenticatedClient:
|
|
170
176
|
"""
|
171
177
|
|
172
178
|
raise_on_unexpected_status: bool = field(default=True, kw_only=True)
|
173
|
-
_base_url: str = field(alias="base_url", default="
|
179
|
+
_base_url: str = field(alias="base_url", default="")
|
174
180
|
_cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
|
175
181
|
_headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
|
176
182
|
_provider: httpx.Auth = field(default=None, alias="provider")
|
@@ -181,6 +187,12 @@ class AuthenticatedClient:
|
|
181
187
|
_client: Optional[httpx.Client] = field(default=None, init=False)
|
182
188
|
_async_client: Optional[httpx.AsyncClient] = field(default=None, init=False)
|
183
189
|
|
190
|
+
def __post_init__(self):
|
191
|
+
from .common.settings import get_settings
|
192
|
+
|
193
|
+
settings = get_settings()
|
194
|
+
self._base_url = settings.base_url
|
195
|
+
|
184
196
|
def with_headers(self, headers: dict[str, str]) -> "AuthenticatedClient":
|
185
197
|
"""Get a new client matching this one with additional headers"""
|
186
198
|
if self._client is not None:
|
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://
|
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://us.registry.beamlit.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 = os.getenv('BL_BASE_URL') or "https://api.beamlit.dev/v0"
|
73
|
+
self.run_url = os.getenv('BL_RUN_URL') or "https://run.beamlit.dev"
|
74
|
+
self.mcp_hub_url = os.getenv('BL_MCP_HUB_URL') or "https://mcp-hub-server.beamlit.workers.dev"
|
75
|
+
self.registry_url = os.getenv('BL_REGISTRY_URL') or "https://eu.registry.beamlit.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,
|