arize-phoenix 4.12.0rc1__py3-none-any.whl → 4.12.1rc1__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.

Potentially problematic release.


This version of arize-phoenix might be problematic. Click here for more details.

@@ -1,221 +0,0 @@
1
- import json
2
- from typing import Any, Dict, Optional
3
-
4
- from starlette.responses import HTMLResponse
5
-
6
- swagger_ui_default_parameters: Dict[str, Any] = {
7
- "dom_id": "#swagger-ui",
8
- "layout": "BaseLayout",
9
- "deepLinking": True,
10
- "showExtensions": True,
11
- "showCommonExtensions": True,
12
- }
13
-
14
-
15
- def get_swagger_ui_html(
16
- *,
17
- openapi_url: str = "/schema",
18
- title: str,
19
- swagger_js_url: str = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.9.0/swagger-ui-bundle.js",
20
- swagger_css_url: str = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.9.0/swagger-ui.css",
21
- swagger_favicon_url: str = "/favicon.ico",
22
- oauth2_redirect_url: Optional[str] = None,
23
- init_oauth: Optional[str] = None,
24
- swagger_ui_parameters: Optional[Dict[str, Any]] = None,
25
- ) -> HTMLResponse:
26
- """
27
- Generate and return the HTML that loads Swagger UI for the interactive API
28
- docs (normally served at `/docs`).
29
- """
30
- current_swagger_ui_parameters = swagger_ui_default_parameters.copy()
31
- if swagger_ui_parameters:
32
- current_swagger_ui_parameters.update(swagger_ui_parameters)
33
-
34
- html = f"""
35
- <!DOCTYPE html>
36
- <html>
37
- <head>
38
- <link type="text/css" rel="stylesheet" href="{swagger_css_url}">
39
- <link rel="shortcut icon" href="{swagger_favicon_url}">
40
- <title>{title}</title>
41
- </head>
42
- <body>
43
- <div id="swagger-ui">
44
- </div>
45
- <script src="{swagger_js_url}"></script>
46
- <style type="text/css">
47
- div[id^="operations-private"]{{display:none}} #operations-tag-private{{display:none}}
48
- </style>
49
- <!-- `SwaggerUIBundle` is now available on the page -->
50
- <script>
51
- const ui = SwaggerUIBundle({{
52
- url: '{openapi_url}',
53
- """
54
-
55
- for key, value in current_swagger_ui_parameters.items():
56
- html += f"{json.dumps(key)}: {json.dumps(value)},\n"
57
-
58
- if oauth2_redirect_url:
59
- html += f"oauth2RedirectUrl: window.location.origin + '{oauth2_redirect_url}',"
60
-
61
- html += """
62
- presets: [
63
- SwaggerUIBundle.presets.apis,
64
- SwaggerUIBundle.SwaggerUIStandalonePreset
65
- ],
66
- })"""
67
-
68
- if init_oauth:
69
- html += f"""
70
- ui.initOAuth({json.dumps(init_oauth)})
71
- """
72
-
73
- html += """
74
- </script>
75
- </body>
76
- </html>
77
- """
78
- return HTMLResponse(html)
79
-
80
-
81
- def get_redoc_html(
82
- *,
83
- openapi_url: str,
84
- title: str,
85
- redoc_js_url: str = "https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js",
86
- redoc_favicon_url: str = "/favicon.ico",
87
- with_google_fonts: bool = True,
88
- ) -> HTMLResponse:
89
- """
90
- Generate and return the HTML response that loads ReDoc for the alternative
91
- API docs (normally served at `/redoc`).
92
-
93
-
94
- """
95
- html = f"""
96
- <!DOCTYPE html>
97
- <html>
98
- <head>
99
- <title>{title}</title>
100
- <!-- needed for adaptive design -->
101
- <meta charset="utf-8"/>
102
- <meta name="viewport" content="width=device-width, initial-scale=1">
103
- """
104
- if with_google_fonts:
105
- html += """
106
- <link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
107
- """ # noqa: E501
108
- html += f"""
109
- <link rel="shortcut icon" href="{redoc_favicon_url}">
110
- <!--
111
- ReDoc doesn't change outer page styles
112
- -->
113
- <style>
114
- body {{
115
- margin: 0;
116
- padding: 0;
117
- }}
118
- </style>
119
- </head>
120
- <body>
121
- <noscript>
122
- ReDoc requires Javascript to function. Please enable it to browse the documentation.
123
- </noscript>
124
- <redoc spec-url="{openapi_url}"></redoc>
125
- <script src="{redoc_js_url}"> </script>
126
- </body>
127
- </html>
128
- """
129
- return HTMLResponse(html)
130
-
131
-
132
- # Not needed now but copy-pasting for future reference
133
- def get_swagger_ui_oauth2_redirect_html() -> HTMLResponse:
134
- """
135
- Generate the HTML response with the OAuth2 redirection for Swagger UI.
136
-
137
- You normally don't need to use or change this.
138
- """
139
- # copied from https://github.com/swagger-api/swagger-ui/blob/v4.14.0/dist/oauth2-redirect.html
140
- html = """
141
- <!doctype html>
142
- <html lang="en-US">
143
- <head>
144
- <title>Swagger UI: OAuth2 Redirect</title>
145
- </head>
146
- <body>
147
- <script>
148
- 'use strict';
149
- function run () {
150
- var oauth2 = window.opener.swaggerUIRedirectOauth2;
151
- var sentState = oauth2.state;
152
- var redirectUrl = oauth2.redirectUrl;
153
- var isValid, qp, arr;
154
-
155
- if (/code|token|error/.test(window.location.hash)) {
156
- qp = window.location.hash.substring(1).replace('?', '&');
157
- } else {
158
- qp = location.search.substring(1);
159
- }
160
-
161
- arr = qp.split("&");
162
- arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';});
163
- qp = qp ? JSON.parse('{' + arr.join() + '}',
164
- function (key, value) {
165
- return key === "" ? value : decodeURIComponent(value);
166
- }
167
- ) : {};
168
-
169
- isValid = qp.state === sentState;
170
-
171
- if ((
172
- oauth2.auth.schema.get("flow") === "accessCode" ||
173
- oauth2.auth.schema.get("flow") === "authorizationCode" ||
174
- oauth2.auth.schema.get("flow") === "authorization_code"
175
- ) && !oauth2.auth.code) {
176
- if (!isValid) {
177
- oauth2.errCb({
178
- authId: oauth2.auth.name,
179
- source: "auth",
180
- level: "warning",
181
- message: "Authorization may be unsafe, passed state was changed in server. The passed state wasn't returned from auth server."
182
- });
183
- }
184
-
185
- if (qp.code) {
186
- delete oauth2.state;
187
- oauth2.auth.code = qp.code;
188
- oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
189
- } else {
190
- let oauthErrorMsg;
191
- if (qp.error) {
192
- oauthErrorMsg = "["+qp.error+"]: " +
193
- (qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
194
- (qp.error_uri ? "More info: "+qp.error_uri : "");
195
- }
196
-
197
- oauth2.errCb({
198
- authId: oauth2.auth.name,
199
- source: "auth",
200
- level: "error",
201
- message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server."
202
- });
203
- }
204
- } else {
205
- oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
206
- }
207
- window.close();
208
- }
209
-
210
- if (document.readyState !== 'loading') {
211
- run();
212
- } else {
213
- document.addEventListener('DOMContentLoaded', function () {
214
- run();
215
- });
216
- }
217
- </script>
218
- </body>
219
- </html>
220
- """ # noqa: E501
221
- return HTMLResponse(content=html)