agenta 0.48.10__py3-none-any.whl → 0.49.0__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 agenta might be problematic. Click here for more details.
|
@@ -3,6 +3,8 @@ from asyncio import sleep
|
|
|
3
3
|
|
|
4
4
|
from pydantic import BaseModel
|
|
5
5
|
|
|
6
|
+
import agenta as ag
|
|
7
|
+
|
|
6
8
|
|
|
7
9
|
class MockMessageModel(BaseModel):
|
|
8
10
|
content: str
|
|
@@ -16,6 +18,7 @@ class MockResponseModel(BaseModel):
|
|
|
16
18
|
choices: list[MockChoiceModel]
|
|
17
19
|
|
|
18
20
|
|
|
21
|
+
@ag.instrument()
|
|
19
22
|
def hello_mock_response(*args, **kwargs) -> MockResponseModel:
|
|
20
23
|
return MockResponseModel(
|
|
21
24
|
choices=[
|
|
@@ -28,6 +31,7 @@ def hello_mock_response(*args, **kwargs) -> MockResponseModel:
|
|
|
28
31
|
)
|
|
29
32
|
|
|
30
33
|
|
|
34
|
+
@ag.instrument()
|
|
31
35
|
def chat_mock_response(*args, **kwargs) -> MockResponseModel:
|
|
32
36
|
return MockResponseModel(
|
|
33
37
|
choices=[
|
|
@@ -41,6 +45,7 @@ def chat_mock_response(*args, **kwargs) -> MockResponseModel:
|
|
|
41
45
|
)
|
|
42
46
|
|
|
43
47
|
|
|
48
|
+
@ag.instrument()
|
|
44
49
|
def delay_mock_response(*args, **kwargs) -> MockResponseModel:
|
|
45
50
|
sleep(2)
|
|
46
51
|
|
|
@@ -55,8 +60,147 @@ def delay_mock_response(*args, **kwargs) -> MockResponseModel:
|
|
|
55
60
|
)
|
|
56
61
|
|
|
57
62
|
|
|
63
|
+
@ag.instrument()
|
|
64
|
+
def capital_mock_response(*args, **kwargs) -> MockResponseModel:
|
|
65
|
+
country = kwargs.get("messages", [{}, {}])[1].get(
|
|
66
|
+
"content", "What is the capital of _____?"
|
|
67
|
+
)[len("What is the capital of ") :][:-1]
|
|
68
|
+
|
|
69
|
+
capital = CAPITALS.get(country, "Unknown")
|
|
70
|
+
return MockResponseModel(
|
|
71
|
+
choices=[
|
|
72
|
+
MockChoiceModel(
|
|
73
|
+
message=MockMessageModel(
|
|
74
|
+
content=f"The capital of {country} is {capital}.",
|
|
75
|
+
)
|
|
76
|
+
)
|
|
77
|
+
],
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
58
81
|
MOCKS: dict[str, Callable[..., MockResponseModel]] = {
|
|
59
82
|
"hello": hello_mock_response,
|
|
60
83
|
"chat": chat_mock_response,
|
|
61
84
|
"delay": delay_mock_response,
|
|
85
|
+
"capital": capital_mock_response,
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
CAPITALS = {
|
|
89
|
+
"Afghanistan": "Kabul",
|
|
90
|
+
"Albania": "Tirana",
|
|
91
|
+
"Algeria": "Algiers",
|
|
92
|
+
"Andorra": "Andorra la Vella",
|
|
93
|
+
"Angola": "Luanda",
|
|
94
|
+
"Antigua and Barbuda": "St. John's",
|
|
95
|
+
"Argentina": "Buenos Aires",
|
|
96
|
+
"Armenia": "Yerevan",
|
|
97
|
+
"Australia": "Canberra",
|
|
98
|
+
"Austria": "Vienna",
|
|
99
|
+
"Azerbaijan": "Baku",
|
|
100
|
+
"Bahamas": "Nassau",
|
|
101
|
+
"Bahrain": "Manama",
|
|
102
|
+
"Bangladesh": "Dhaka",
|
|
103
|
+
"Barbados": "Bridgetown",
|
|
104
|
+
"Belarus": "Minsk",
|
|
105
|
+
"Belgium": "Brussels",
|
|
106
|
+
"Belize": "Belmopan",
|
|
107
|
+
"Benin": "Porto-Novo",
|
|
108
|
+
"Bhutan": "Thimphu",
|
|
109
|
+
"Bolivia": "Sucre",
|
|
110
|
+
"Bosnia and Herzegovina": "Sarajevo",
|
|
111
|
+
"Botswana": "Gaborone",
|
|
112
|
+
"Brazil": "Bras\u00edlia",
|
|
113
|
+
"Brunei": "Bandar Seri Begawan",
|
|
114
|
+
"Bulgaria": "Sofia",
|
|
115
|
+
"Burkina Faso": "Ouagadougou",
|
|
116
|
+
"Burundi": "Gitega",
|
|
117
|
+
"Cabo Verde": "Praia",
|
|
118
|
+
"Cambodia": "Phnom Penh",
|
|
119
|
+
"Cameroon": "Yaound\u00e9",
|
|
120
|
+
"Canada": "Ottawa",
|
|
121
|
+
"Central African Republic": "Bangui",
|
|
122
|
+
"Chad": "N'Djamena",
|
|
123
|
+
"Chile": "Santiago",
|
|
124
|
+
"China": "Beijing",
|
|
125
|
+
"Colombia": "Bogot\u00e1",
|
|
126
|
+
"Comoros": "Moroni",
|
|
127
|
+
"Congo (Brazzaville)": "Brazzaville",
|
|
128
|
+
"Congo (Kinshasa)": "Kinshasa",
|
|
129
|
+
"Costa Rica": "San Jos\u00e9",
|
|
130
|
+
"Croatia": "Zagreb",
|
|
131
|
+
"Cuba": "Havana",
|
|
132
|
+
"Cyprus": "Nicosia",
|
|
133
|
+
"Czech Republic": "Prague",
|
|
134
|
+
"Denmark": "Copenhagen",
|
|
135
|
+
"Djibouti": "Djibouti",
|
|
136
|
+
"Dominica": "Roseau",
|
|
137
|
+
"Dominican Republic": "Santo Domingo",
|
|
138
|
+
"East Timor": "Dili",
|
|
139
|
+
"Ecuador": "Quito",
|
|
140
|
+
"Egypt": "Cairo",
|
|
141
|
+
"El Salvador": "San Salvador",
|
|
142
|
+
"Equatorial Guinea": "Malabo",
|
|
143
|
+
"Eritrea": "Asmara",
|
|
144
|
+
"Estonia": "Tallinn",
|
|
145
|
+
"Eswatini": "Mbabane",
|
|
146
|
+
"Ethiopia": "Addis Ababa",
|
|
147
|
+
"Fiji": "Suva",
|
|
148
|
+
"Finland": "Helsinki",
|
|
149
|
+
"France": "Paris",
|
|
150
|
+
"Gabon": "Libreville",
|
|
151
|
+
"Gambia": "Banjul",
|
|
152
|
+
"Georgia": "Tbilisi",
|
|
153
|
+
"Germany": "Berlin",
|
|
154
|
+
"Ghana": "Accra",
|
|
155
|
+
"Greece": "Athens",
|
|
156
|
+
"Grenada": "St. George's",
|
|
157
|
+
"Guatemala": "Guatemala City",
|
|
158
|
+
"Guinea": "Conakry",
|
|
159
|
+
"Guinea-Bissau": "Bissau",
|
|
160
|
+
"Guyana": "Georgetown",
|
|
161
|
+
"Haiti": "Port-au-Prince",
|
|
162
|
+
"Honduras": "Tegucigalpa",
|
|
163
|
+
"Hungary": "Budapest",
|
|
164
|
+
"Iceland": "Reykjavik",
|
|
165
|
+
"India": "New Delhi",
|
|
166
|
+
"Indonesia": "Jakarta",
|
|
167
|
+
"Iran": "Tehran",
|
|
168
|
+
"Iraq": "Baghdad",
|
|
169
|
+
"Ireland": "Dublin",
|
|
170
|
+
"Israel": "Jerusalem",
|
|
171
|
+
"Italy": "Rome",
|
|
172
|
+
"Ivory Coast": "Yamoussoukro",
|
|
173
|
+
"Jamaica": "Kingston",
|
|
174
|
+
"Japan": "Tokyo",
|
|
175
|
+
"Jordan": "Amman",
|
|
176
|
+
"Kazakhstan": "Astana",
|
|
177
|
+
"Kenya": "Nairobi",
|
|
178
|
+
"Kiribati": "South Tarawa",
|
|
179
|
+
"North Korea": "Pyongyang",
|
|
180
|
+
"South Korea": "Seoul",
|
|
181
|
+
"Kosovo": "Pristina",
|
|
182
|
+
"Kuwait": "Kuwait City",
|
|
183
|
+
"Kyrgyzstan": "Bishkek",
|
|
184
|
+
"Laos": "Vientiane",
|
|
185
|
+
"Latvia": "Riga",
|
|
186
|
+
"Lebanon": "Beirut",
|
|
187
|
+
"Lesotho": "Maseru",
|
|
188
|
+
"Liberia": "Monrovia",
|
|
189
|
+
"Libya": "Tripoli",
|
|
190
|
+
"Liechtenstein": "Vaduz",
|
|
191
|
+
"Lithuania": "Vilnius",
|
|
192
|
+
"Luxembourg": "Luxembourg",
|
|
193
|
+
"Madagascar": "Antananarivo",
|
|
194
|
+
"Malawi": "Lilongwe",
|
|
195
|
+
"Malaysia": "Kuala Lumpur",
|
|
196
|
+
"Maldives": "Mal\u00e9",
|
|
197
|
+
"Mali": "Bamako",
|
|
198
|
+
"Malta": "Valletta",
|
|
199
|
+
"Marshall Islands": "Majuro",
|
|
200
|
+
"Mauritania": "Nouakchott",
|
|
201
|
+
"Mauritius": "Port Louis",
|
|
202
|
+
"Mexico": "Mexico City",
|
|
203
|
+
"Micronesia": "Palikir",
|
|
204
|
+
"Moldova": "Chi\u0219in\u0103u",
|
|
205
|
+
"Monaco": "Monaco",
|
|
62
206
|
}
|
agenta/sdk/middleware/auth.py
CHANGED
|
@@ -100,8 +100,8 @@ class AuthMiddleware(BaseHTTPMiddleware):
|
|
|
100
100
|
access_token = request.cookies.get("sAccessToken", None)
|
|
101
101
|
cookies = {"sAccessToken": access_token} if access_token else None
|
|
102
102
|
|
|
103
|
-
if not headers and not cookies:
|
|
104
|
-
|
|
103
|
+
# if not headers and not cookies:
|
|
104
|
+
# log.debug("No auth header nor auth cookie found in the request")
|
|
105
105
|
|
|
106
106
|
# PARAMS
|
|
107
107
|
params = {}
|
|
@@ -112,8 +112,9 @@ class AuthMiddleware(BaseHTTPMiddleware):
|
|
|
112
112
|
# ALTERNATIVE
|
|
113
113
|
or request.query_params.get("project_id")
|
|
114
114
|
)
|
|
115
|
-
if not project_id:
|
|
116
|
-
|
|
115
|
+
# if not project_id:
|
|
116
|
+
# log.debug("No project ID found in request")
|
|
117
|
+
|
|
117
118
|
if project_id:
|
|
118
119
|
params["project_id"] = project_id
|
|
119
120
|
## SCOPE
|
|
@@ -139,7 +140,7 @@ class AuthMiddleware(BaseHTTPMiddleware):
|
|
|
139
140
|
credentials = _cache.get(_hash)
|
|
140
141
|
|
|
141
142
|
if credentials:
|
|
142
|
-
log.debug("Using cached credentials")
|
|
143
|
+
# log.debug("Using cached credentials")
|
|
143
144
|
return credentials
|
|
144
145
|
|
|
145
146
|
try:
|
|
@@ -153,46 +154,46 @@ class AuthMiddleware(BaseHTTPMiddleware):
|
|
|
153
154
|
timeout=30.0,
|
|
154
155
|
)
|
|
155
156
|
except httpx.TimeoutException as exc:
|
|
156
|
-
log.debug(f"Timeout error while verify credentials: {exc}")
|
|
157
|
+
# log.debug(f"Timeout error while verify credentials: {exc}")
|
|
157
158
|
raise DenyException(
|
|
158
159
|
status_code=504,
|
|
159
160
|
content="Could not verify credentials: connection to {self.host} timed out. Please check your network connection.",
|
|
160
161
|
) from exc
|
|
161
162
|
except httpx.ConnectError as exc:
|
|
162
|
-
log.debug(f"Connection error while verify credentials: {exc}")
|
|
163
|
+
# log.debug(f"Connection error while verify credentials: {exc}")
|
|
163
164
|
raise DenyException(
|
|
164
165
|
status_code=503,
|
|
165
166
|
content=f"Could not verify credentials: connection to {self.host} failed. Please check if agenta is available.",
|
|
166
167
|
) from exc
|
|
167
168
|
except httpx.NetworkError as exc:
|
|
168
|
-
log.debug(f"Network error while verify credentials: {exc}")
|
|
169
|
+
# log.debug(f"Network error while verify credentials: {exc}")
|
|
169
170
|
raise DenyException(
|
|
170
171
|
status_code=503,
|
|
171
172
|
content="Could not verify credentials: connection to {self.host} failed. Please check your network connection.",
|
|
172
173
|
) from exc
|
|
173
174
|
except httpx.HTTPError as exc:
|
|
174
|
-
log.debug(f"HTTP error while verify credentials: {exc}")
|
|
175
|
+
# log.debug(f"HTTP error while verify credentials: {exc}")
|
|
175
176
|
raise DenyException(
|
|
176
177
|
status_code=502,
|
|
177
178
|
content=f"Could not verify credentials: connection to {self.host} failed. Please check if agenta is available.",
|
|
178
179
|
) from exc
|
|
179
180
|
|
|
180
181
|
if response.status_code == 401:
|
|
181
|
-
log.debug("Agenta returned 401 - Invalid credentials")
|
|
182
|
+
# log.debug("Agenta returned 401 - Invalid credentials")
|
|
182
183
|
raise DenyException(
|
|
183
184
|
status_code=401,
|
|
184
185
|
content="Invalid credentials. Please check your credentials or login again.",
|
|
185
186
|
)
|
|
186
187
|
elif response.status_code == 403:
|
|
187
|
-
log.debug("Agenta returned 403 - Permission denied")
|
|
188
|
+
# log.debug("Agenta returned 403 - Permission denied")
|
|
188
189
|
raise DenyException(
|
|
189
190
|
status_code=403,
|
|
190
191
|
content="Permission denied. Please check your permissions or contact your administrator.",
|
|
191
192
|
)
|
|
192
193
|
elif response.status_code != 200:
|
|
193
|
-
log.debug(
|
|
194
|
-
|
|
195
|
-
)
|
|
194
|
+
# log.debug(
|
|
195
|
+
# f"Agenta returned {response.status_code} - Unexpected status code"
|
|
196
|
+
# )
|
|
196
197
|
raise DenyException(
|
|
197
198
|
status_code=500,
|
|
198
199
|
content=f"Could not verify credentials: {self.host} returned unexpected status code {response.status_code}. Please try again later or contact support if the issue persists.",
|
|
@@ -201,16 +202,16 @@ class AuthMiddleware(BaseHTTPMiddleware):
|
|
|
201
202
|
try:
|
|
202
203
|
auth = response.json()
|
|
203
204
|
except ValueError as exc:
|
|
204
|
-
log.debug(f"Agenta returned invalid JSON response: {exc}")
|
|
205
|
+
# log.debug(f"Agenta returned invalid JSON response: {exc}")
|
|
205
206
|
raise DenyException(
|
|
206
207
|
status_code=500,
|
|
207
208
|
content=f"Could not verify credentials: {self.host} returned unexpected invalid JSON response. Please try again later or contact support if the issue persists.",
|
|
208
209
|
) from exc
|
|
209
210
|
|
|
210
211
|
if not isinstance(auth, dict):
|
|
211
|
-
log.debug(
|
|
212
|
-
|
|
213
|
-
)
|
|
212
|
+
# log.debug(
|
|
213
|
+
# f"Agenta returned invalid response format: {type(auth)}"
|
|
214
|
+
# )
|
|
214
215
|
raise DenyException(
|
|
215
216
|
status_code=500,
|
|
216
217
|
content=f"Could not verify credentials: {self.host} returned unexpected invalid response format. Please try again later or contact support if the issue persists.",
|
|
@@ -218,7 +219,7 @@ class AuthMiddleware(BaseHTTPMiddleware):
|
|
|
218
219
|
|
|
219
220
|
effect = auth.get("effect")
|
|
220
221
|
if effect != "allow":
|
|
221
|
-
log.debug("Access denied by Agenta - effect: {effect}")
|
|
222
|
+
# log.debug("Access denied by Agenta - effect: {effect}")
|
|
222
223
|
raise DenyException(
|
|
223
224
|
status_code=403,
|
|
224
225
|
content="Permission denied. Please check your permissions or contact your administrator.",
|
|
@@ -226,8 +227,8 @@ class AuthMiddleware(BaseHTTPMiddleware):
|
|
|
226
227
|
|
|
227
228
|
credentials = auth.get("credentials")
|
|
228
229
|
|
|
229
|
-
if not credentials:
|
|
230
|
-
|
|
230
|
+
# if not credentials:
|
|
231
|
+
# log.debug("No credentials found in the response")
|
|
231
232
|
|
|
232
233
|
_cache.put(_hash, credentials)
|
|
233
234
|
|
|
@@ -236,9 +237,9 @@ class AuthMiddleware(BaseHTTPMiddleware):
|
|
|
236
237
|
except DenyException as deny:
|
|
237
238
|
raise deny
|
|
238
239
|
except Exception as exc: # pylint: disable=bare-except
|
|
239
|
-
log.debug(
|
|
240
|
-
|
|
241
|
-
)
|
|
240
|
+
# log.debug(
|
|
241
|
+
# f"Unexpected error while verifying credentials (remote): {exc}"
|
|
242
|
+
# )
|
|
242
243
|
raise DenyException(
|
|
243
244
|
status_code=500,
|
|
244
245
|
content=f"Could not verify credentials: unexpected error - {str(exc)}. Please try again later or contact support if the issue persists.",
|
|
@@ -247,7 +248,7 @@ class AuthMiddleware(BaseHTTPMiddleware):
|
|
|
247
248
|
except DenyException as deny:
|
|
248
249
|
raise deny
|
|
249
250
|
except Exception as exc:
|
|
250
|
-
log.debug(f"Unexpected error while verifying credentials (local): {exc}")
|
|
251
|
+
# log.debug(f"Unexpected error while verifying credentials (local): {exc}")
|
|
251
252
|
raise DenyException(
|
|
252
253
|
status_code=500,
|
|
253
254
|
content=f"Could not verify credentials: unexpected error - {str(exc)}. Please try again later or contact support if the issue persists.",
|
|
@@ -318,7 +318,7 @@ agenta/sdk/decorators/tracing.py,sha256=6xwN9AomDND_5wL21NXFoZsdwTBuITw2I39GNqNG
|
|
|
318
318
|
agenta/sdk/litellm/__init__.py,sha256=Bpz1gfHQc0MN1yolWcjifLWznv6GjHggvRGQSpxpihM,37
|
|
319
319
|
agenta/sdk/litellm/litellm.py,sha256=dCjw0H_jD3L3UQ3l9SbLm5dfeIGnel6dPtQYJ78beYM,10202
|
|
320
320
|
agenta/sdk/litellm/mockllm.py,sha256=PG3DF2ZjWHOtCt8WIU3qcSyXBOZspUX1FIyFMA9HuZM,902
|
|
321
|
-
agenta/sdk/litellm/mocks/__init__.py,sha256=
|
|
321
|
+
agenta/sdk/litellm/mocks/__init__.py,sha256=d-aAj-uzee1BVGHMB2oJocpxGQeWr6QLrYV4oNdSqzY,5241
|
|
322
322
|
agenta/sdk/managers/__init__.py,sha256=SN-LRwG0pRRDV3u2Q4JiiSTigN3-mYpzGNM35RzT4mc,238
|
|
323
323
|
agenta/sdk/managers/apps.py,sha256=BeAlTJlOOM0Wh_XWgjve65Mt-LwFgib_swu-1wvGQi4,2250
|
|
324
324
|
agenta/sdk/managers/config.py,sha256=Dl1L4KGvj3h_temzJzn7FVHacABRuB2Q7_x98EpZJQo,7494
|
|
@@ -328,7 +328,7 @@ agenta/sdk/managers/shared.py,sha256=kI3w74E4rS3YDORG2e-_r0Pz5KslTRzRBK7vgyOeaJA
|
|
|
328
328
|
agenta/sdk/managers/variant.py,sha256=A5ga3mq3b0weUTXa9HO72MGaspthGcu1uK9K5OnP738,4172
|
|
329
329
|
agenta/sdk/managers/vault.py,sha256=054ce9X_xKa2M4NtQWz-GugO6q_pYVWCP3IxbAJJcRw,337
|
|
330
330
|
agenta/sdk/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
331
|
-
agenta/sdk/middleware/auth.py,sha256=
|
|
331
|
+
agenta/sdk/middleware/auth.py,sha256=m7Ga6JpQ5CBCNA7nZYPw8NgS4Nihzkg-ptmvlLCV8TI,10227
|
|
332
332
|
agenta/sdk/middleware/config.py,sha256=zd57kxaeYheZMG8nD5VOYgHXw8j9zRlFacuzCGHWeEA,7978
|
|
333
333
|
agenta/sdk/middleware/cors.py,sha256=q3r7lGkrIdMcT_vuhsburMcjG7pyl7w0ycxrIrGJ2e8,921
|
|
334
334
|
agenta/sdk/middleware/inline.py,sha256=ee8E4XBGcRSrHTvblqX1yRXuTN_sxLm7lY1jnywrBG8,901
|
|
@@ -357,6 +357,6 @@ agenta/sdk/utils/logging.py,sha256=j4NzpFk2ilOM10sRBOxCjmansDHSx6HwMV8IAEreRb8,8
|
|
|
357
357
|
agenta/sdk/utils/preinit.py,sha256=1TAAHhYyYnLLwvzwnf33Qwkou7tI3iITlVt-1kcyGaM,1186
|
|
358
358
|
agenta/sdk/utils/singleton.py,sha256=17Ph7LGnnV8HkPjImruKita2ni03Ari5jr0jqm__4sc,312
|
|
359
359
|
agenta/sdk/utils/timing.py,sha256=nZR-kudVUtKFlHuBhztgSGxj7FVnCB4Uv6sfg-1dkrQ,1556
|
|
360
|
-
agenta-0.
|
|
361
|
-
agenta-0.
|
|
362
|
-
agenta-0.
|
|
360
|
+
agenta-0.49.0.dist-info/METADATA,sha256=i7oQJ0JGViTh2jXxvjsaQRJEd1IywFvDFvC7TBmQ3Kw,31456
|
|
361
|
+
agenta-0.49.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
362
|
+
agenta-0.49.0.dist-info/RECORD,,
|
|
File without changes
|