agenta 0.27.5__py3-none-any.whl → 0.27.6__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.
- agenta/sdk/decorators/routing.py +3 -27
- agenta/sdk/tracing/exporters.py +1 -1
- agenta/sdk/tracing/processors.py +1 -1
- {agenta-0.27.5.dist-info → agenta-0.27.6.dist-info}/METADATA +2 -3
- {agenta-0.27.5.dist-info → agenta-0.27.6.dist-info}/RECORD +7 -10
- {agenta-0.27.5.dist-info → agenta-0.27.6.dist-info}/WHEEL +1 -1
- agenta/sdk/middleware/__init__.py +0 -0
- agenta/sdk/middleware/auth.py +0 -136
- agenta/sdk/middleware/cache.py +0 -43
- {agenta-0.27.5.dist-info → agenta-0.27.6.dist-info}/entry_points.txt +0 -0
agenta/sdk/decorators/routing.py
CHANGED
|
@@ -14,10 +14,9 @@ from os import environ
|
|
|
14
14
|
from fastapi.middleware.cors import CORSMiddleware
|
|
15
15
|
from fastapi import Body, FastAPI, UploadFile, HTTPException
|
|
16
16
|
|
|
17
|
-
from agenta.sdk.middleware.auth import AuthorizationMiddleware
|
|
18
17
|
from agenta.sdk.context.routing import routing_context_manager, routing_context
|
|
19
18
|
from agenta.sdk.context.tracing import tracing_context
|
|
20
|
-
from agenta.sdk.router import router
|
|
19
|
+
from agenta.sdk.router import router as router
|
|
21
20
|
from agenta.sdk.utils.exceptions import suppress
|
|
22
21
|
from agenta.sdk.utils.logging import log
|
|
23
22
|
from agenta.sdk.types import (
|
|
@@ -51,9 +50,6 @@ app.add_middleware(
|
|
|
51
50
|
allow_headers=["*"],
|
|
52
51
|
)
|
|
53
52
|
|
|
54
|
-
_MIDDLEWARES = True
|
|
55
|
-
|
|
56
|
-
|
|
57
53
|
app.include_router(router, prefix="")
|
|
58
54
|
|
|
59
55
|
|
|
@@ -125,26 +121,6 @@ class entrypoint:
|
|
|
125
121
|
route_path="",
|
|
126
122
|
config_schema: Optional[BaseModel] = None,
|
|
127
123
|
):
|
|
128
|
-
### --- Update Middleware --- #
|
|
129
|
-
try:
|
|
130
|
-
global _MIDDLEWARES # pylint: disable=global-statement
|
|
131
|
-
|
|
132
|
-
if _MIDDLEWARES:
|
|
133
|
-
app.add_middleware(
|
|
134
|
-
AuthorizationMiddleware,
|
|
135
|
-
host=ag.DEFAULT_AGENTA_SINGLETON_INSTANCE.host,
|
|
136
|
-
resource_id=ag.DEFAULT_AGENTA_SINGLETON_INSTANCE.app_id,
|
|
137
|
-
resource_type="application",
|
|
138
|
-
)
|
|
139
|
-
|
|
140
|
-
_MIDDLEWARES = False
|
|
141
|
-
|
|
142
|
-
except: # pylint: disable=bare-except
|
|
143
|
-
log.error("------------------------------------")
|
|
144
|
-
log.error("Agenta SDK - failed to secure route: %s", route_path)
|
|
145
|
-
log.error("------------------------------------")
|
|
146
|
-
### --- Update Middleware --- #
|
|
147
|
-
|
|
148
124
|
DEFAULT_PATH = "generate"
|
|
149
125
|
PLAYGROUND_PATH = "/playground"
|
|
150
126
|
RUN_PATH = "/run"
|
|
@@ -354,9 +330,9 @@ class entrypoint:
|
|
|
354
330
|
*args,
|
|
355
331
|
**func_params,
|
|
356
332
|
):
|
|
357
|
-
log.info("---------------------------")
|
|
333
|
+
log.info(f"---------------------------")
|
|
358
334
|
log.info(f"Agenta SDK - running route: {repr(self.route_path or '/')}")
|
|
359
|
-
log.info("---------------------------")
|
|
335
|
+
log.info(f"---------------------------")
|
|
360
336
|
|
|
361
337
|
tracing_context.set(routing_context.get())
|
|
362
338
|
|
agenta/sdk/tracing/exporters.py
CHANGED
|
@@ -58,7 +58,7 @@ class InlineTraceExporter(SpanExporter):
|
|
|
58
58
|
return trace
|
|
59
59
|
|
|
60
60
|
|
|
61
|
-
OTLPSpanExporter._MAX_RETRY_TIMEOUT = 2
|
|
61
|
+
OTLPSpanExporter._MAX_RETRY_TIMEOUT = 2
|
|
62
62
|
|
|
63
63
|
ConsoleExporter = ConsoleSpanExporter
|
|
64
64
|
InlineExporter = InlineTraceExporter
|
agenta/sdk/tracing/processors.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: agenta
|
|
3
|
-
Version: 0.27.
|
|
3
|
+
Version: 0.27.6
|
|
4
4
|
Summary: The SDK for agenta is an open-source LLMOps platform.
|
|
5
5
|
Home-page: https://agenta.ai
|
|
6
6
|
Keywords: LLMOps,LLM,evaluation,prompt engineering
|
|
@@ -13,8 +13,7 @@ Classifier: Programming Language :: Python :: 3
|
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.9
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.10
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
17
|
Classifier: Topic :: Software Development :: Libraries
|
|
19
18
|
Requires-Dist: cachetools (>=5.3.3,<6.0.0)
|
|
20
19
|
Requires-Dist: click (>=8.1.3,<9.0.0)
|
|
@@ -147,7 +147,7 @@ agenta/sdk/context/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
|
|
|
147
147
|
agenta/sdk/context/routing.py,sha256=ycUgmJZyWhL4bHjKtUSAsTlt_0Fujr_6OpoaEH1lAN0,683
|
|
148
148
|
agenta/sdk/context/tracing.py,sha256=UmmW15UFFsvxS0myS6aD9wBk5iNepNlQi4tEQ_ejfYM,96
|
|
149
149
|
agenta/sdk/decorators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
150
|
-
agenta/sdk/decorators/routing.py,sha256=
|
|
150
|
+
agenta/sdk/decorators/routing.py,sha256=qwvXBAlRHH9W94L93OK2h_sCm06NGFtjRkdz3Qy5xRs,36142
|
|
151
151
|
agenta/sdk/decorators/tracing.py,sha256=rwxbxsDb6B0VaJf4qLPgyTMYNkJMFLsCiX2ZQ6W-zOw,7713
|
|
152
152
|
agenta/sdk/litellm/__init__.py,sha256=Bpz1gfHQc0MN1yolWcjifLWznv6GjHggvRGQSpxpihM,37
|
|
153
153
|
agenta/sdk/litellm/litellm.py,sha256=J9NefQ2yvfWQy9e0zmPZiRQDz5GM2ThWAw5XM8gCaqw,8461
|
|
@@ -156,17 +156,14 @@ agenta/sdk/managers/config.py,sha256=AuFfHYOkmilDdcAJt2nlw_WlA3ho4Htjf29FKTZGElM
|
|
|
156
156
|
agenta/sdk/managers/deployment.py,sha256=SEokjZeh6n7HRKZ92Y0WncdG49hIFx-Z3B3HAl2kmUg,1174
|
|
157
157
|
agenta/sdk/managers/shared.py,sha256=e53jckQq5PIMpjdxADOonUj7o8aGfzmSvdeH5f43rGs,21497
|
|
158
158
|
agenta/sdk/managers/variant.py,sha256=A5ga3mq3b0weUTXa9HO72MGaspthGcu1uK9K5OnP738,4172
|
|
159
|
-
agenta/sdk/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
160
|
-
agenta/sdk/middleware/auth.py,sha256=olVQ9Mm5E3dYDtjRkMXWGzJe_WkMTkYw7Yf5v9uKC0U,3999
|
|
161
|
-
agenta/sdk/middleware/cache.py,sha256=C_LEzFbulbCBIKtcut2T4qJzh90q4369WCsApDg3Vm0,902
|
|
162
159
|
agenta/sdk/router.py,sha256=mOguvtOwl2wmyAgOuWTsf98pQwpNiUILKIo67W_hR3A,119
|
|
163
160
|
agenta/sdk/tracing/__init__.py,sha256=rQNe5-zT5Kt7_CDhq-lnUIi1EYTBVzVf_MbfcIxVD98,41
|
|
164
161
|
agenta/sdk/tracing/attributes.py,sha256=zh8JQZSeYCLBeIRSopKJx6QQ-WEgw08Cr64DS_WOcT8,3833
|
|
165
162
|
agenta/sdk/tracing/context.py,sha256=PSJdhcaOXSMAuGUBySpLKPKyx8duF3TJzhUEk2ufqPc,777
|
|
166
163
|
agenta/sdk/tracing/conventions.py,sha256=JBtznBXZ3aRkGKkLl7cPwdMNh3w1G-H2Ta2YrAxbr38,950
|
|
167
|
-
agenta/sdk/tracing/exporters.py,sha256=
|
|
164
|
+
agenta/sdk/tracing/exporters.py,sha256=mFK5vrL7X-pQmyH-c9vrmGtsjSkCBOR31q2M4ZsOo80,1568
|
|
168
165
|
agenta/sdk/tracing/inline.py,sha256=jVIlmDIFSzXr-ofMbGlO8VFnNeiUL4C4yA8soED4AHI,34611
|
|
169
|
-
agenta/sdk/tracing/processors.py,sha256=
|
|
166
|
+
agenta/sdk/tracing/processors.py,sha256=8hgwC44qtPDmQ5yurKA4T6rEVx5y927w2sDHdU5GoUA,3115
|
|
170
167
|
agenta/sdk/tracing/spans.py,sha256=nqUOjjirBxB8Eacv8Qj4Ra_6rknGi3lbJdNyKmk5ODQ,3707
|
|
171
168
|
agenta/sdk/tracing/tracing.py,sha256=50669Lr6XwRoIEWDqEFj-K4HRcYSaL9i5vqwARvP7bk,6778
|
|
172
169
|
agenta/sdk/types.py,sha256=oEeSUQn4tMzV7dkSuucBC2YlAaxS-7qgkdlT763YfLM,7076
|
|
@@ -193,7 +190,7 @@ agenta/templates/simple_prompt/app.py,sha256=kODgF6lhzsaJPdgL5b21bUki6jkvqjWZzWR
|
|
|
193
190
|
agenta/templates/simple_prompt/env.example,sha256=g9AE5bYcGPpxawXMJ96gh8oenEPCHTabsiOnfQo3c5k,70
|
|
194
191
|
agenta/templates/simple_prompt/requirements.txt,sha256=ywRglRy7pPkw8bljmMEJJ4aOOQKrt9FGKULZ-DGkoBU,23
|
|
195
192
|
agenta/templates/simple_prompt/template.toml,sha256=DQBtRrF4GU8LBEXOZ-GGuINXMQDKGTEG5y37tnvIUIE,60
|
|
196
|
-
agenta-0.27.
|
|
197
|
-
agenta-0.27.
|
|
198
|
-
agenta-0.27.
|
|
199
|
-
agenta-0.27.
|
|
193
|
+
agenta-0.27.6.dist-info/METADATA,sha256=P-PQ-0d6zRsQIF0CI38iSPozq41cpfP1hv5SU6KiMSc,31684
|
|
194
|
+
agenta-0.27.6.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
|
|
195
|
+
agenta-0.27.6.dist-info/entry_points.txt,sha256=PDiu8_8AsL7ibU9v4iNoOKR1S7F2rdxjlEprjM9QOgo,46
|
|
196
|
+
agenta-0.27.6.dist-info/RECORD,,
|
|
File without changes
|
agenta/sdk/middleware/auth.py
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
from typing import Callable, Optional
|
|
2
|
-
from os import environ
|
|
3
|
-
from uuid import UUID
|
|
4
|
-
from json import dumps
|
|
5
|
-
from traceback import format_exc
|
|
6
|
-
|
|
7
|
-
import httpx
|
|
8
|
-
from starlette.middleware.base import BaseHTTPMiddleware
|
|
9
|
-
from fastapi import FastAPI, Request, Response
|
|
10
|
-
|
|
11
|
-
from agenta.sdk.utils.logging import log
|
|
12
|
-
from agenta.sdk.middleware.cache import TTLLRUCache
|
|
13
|
-
|
|
14
|
-
AGENTA_SDK_AUTH_CACHE_CAPACITY = environ.get(
|
|
15
|
-
"AGENTA_SDK_AUTH_CACHE_CAPACITY",
|
|
16
|
-
512,
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
AGENTA_SDK_AUTH_CACHE_TTL = environ.get(
|
|
20
|
-
"AGENTA_SDK_AUTH_CACHE_TTL",
|
|
21
|
-
15 * 60, # 15 minutes
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
AGENTA_UNAUTHORIZED_EXECUTION_ALLOWED = str(
|
|
25
|
-
environ.get("AGENTA_UNAUTHORIZED_EXECUTION_ALLOWED", False)
|
|
26
|
-
).lower() in ("true", "1", "t")
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class Deny(Response):
|
|
30
|
-
def __init__(self) -> None:
|
|
31
|
-
super().__init__(status_code=401, content="Unauthorized")
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
cache = TTLLRUCache(
|
|
35
|
-
capacity=AGENTA_SDK_AUTH_CACHE_CAPACITY,
|
|
36
|
-
ttl=AGENTA_SDK_AUTH_CACHE_TTL,
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class AuthorizationMiddleware(BaseHTTPMiddleware):
|
|
41
|
-
def __init__(
|
|
42
|
-
self,
|
|
43
|
-
app: FastAPI,
|
|
44
|
-
host: str,
|
|
45
|
-
resource_id: UUID,
|
|
46
|
-
resource_type: str,
|
|
47
|
-
):
|
|
48
|
-
super().__init__(app)
|
|
49
|
-
|
|
50
|
-
self.host = host
|
|
51
|
-
self.resource_id = resource_id
|
|
52
|
-
self.resource_type = resource_type
|
|
53
|
-
|
|
54
|
-
async def dispatch(
|
|
55
|
-
self,
|
|
56
|
-
request: Request,
|
|
57
|
-
call_next: Callable,
|
|
58
|
-
project_id: Optional[UUID] = None,
|
|
59
|
-
):
|
|
60
|
-
if AGENTA_UNAUTHORIZED_EXECUTION_ALLOWED:
|
|
61
|
-
return await call_next(request)
|
|
62
|
-
|
|
63
|
-
try:
|
|
64
|
-
authorization = (
|
|
65
|
-
request.headers.get("Authorization")
|
|
66
|
-
or request.headers.get("authorization")
|
|
67
|
-
or None
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
headers = {"Authorization": authorization} if authorization else None
|
|
71
|
-
|
|
72
|
-
cookies = {"sAccessToken": request.cookies.get("sAccessToken")}
|
|
73
|
-
|
|
74
|
-
params = {
|
|
75
|
-
"action": "run_service",
|
|
76
|
-
"resource_type": self.resource_type,
|
|
77
|
-
"resource_id": self.resource_id,
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if project_id:
|
|
81
|
-
params["project_id"] = project_id
|
|
82
|
-
|
|
83
|
-
_hash = dumps(
|
|
84
|
-
{
|
|
85
|
-
"headers": headers,
|
|
86
|
-
"cookies": cookies,
|
|
87
|
-
"params": params,
|
|
88
|
-
},
|
|
89
|
-
sort_keys=True,
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
cached_policy = cache.get(_hash)
|
|
93
|
-
|
|
94
|
-
if not cached_policy:
|
|
95
|
-
async with httpx.AsyncClient() as client:
|
|
96
|
-
response = await client.get(
|
|
97
|
-
f"{self.host}/api/permissions/verify",
|
|
98
|
-
headers=headers,
|
|
99
|
-
cookies=cookies,
|
|
100
|
-
params=params,
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
if response.status_code != 200:
|
|
104
|
-
cache.put(_hash, {"effect": "deny"})
|
|
105
|
-
return Deny()
|
|
106
|
-
|
|
107
|
-
auth = response.json()
|
|
108
|
-
|
|
109
|
-
if auth.get("effect") != "allow":
|
|
110
|
-
cache.put(_hash, {"effect": "deny"})
|
|
111
|
-
return Deny()
|
|
112
|
-
|
|
113
|
-
cached_policy = {
|
|
114
|
-
"effect": "allow",
|
|
115
|
-
"credentials": auth.get("credentials"),
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
cache.put(_hash, cached_policy)
|
|
119
|
-
|
|
120
|
-
if cached_policy.get("effect") == "deny":
|
|
121
|
-
return Deny()
|
|
122
|
-
|
|
123
|
-
request.state.credentials = cached_policy.get("credentials")
|
|
124
|
-
|
|
125
|
-
print(f"credentials: {request.state.credentials}")
|
|
126
|
-
|
|
127
|
-
return await call_next(request)
|
|
128
|
-
|
|
129
|
-
except: # pylint: disable=bare-except
|
|
130
|
-
log.error("------------------------------------------------------")
|
|
131
|
-
log.error("Agenta SDK - handling auth middleware exception below:")
|
|
132
|
-
log.error("------------------------------------------------------")
|
|
133
|
-
log.error(format_exc().strip("\n"))
|
|
134
|
-
log.error("------------------------------------------------------")
|
|
135
|
-
|
|
136
|
-
return Deny()
|
agenta/sdk/middleware/cache.py
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
from time import time
|
|
2
|
-
from collections import OrderedDict
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class TTLLRUCache:
|
|
6
|
-
def __init__(self, capacity: int, ttl: int):
|
|
7
|
-
self.cache = OrderedDict()
|
|
8
|
-
self.capacity = capacity
|
|
9
|
-
self.ttl = ttl
|
|
10
|
-
|
|
11
|
-
def get(self, key):
|
|
12
|
-
# CACHE
|
|
13
|
-
if key not in self.cache:
|
|
14
|
-
return None
|
|
15
|
-
|
|
16
|
-
value, expiry = self.cache[key]
|
|
17
|
-
# -----
|
|
18
|
-
|
|
19
|
-
# TTL
|
|
20
|
-
if time() > expiry:
|
|
21
|
-
del self.cache[key]
|
|
22
|
-
|
|
23
|
-
return None
|
|
24
|
-
# ---
|
|
25
|
-
|
|
26
|
-
# LRU
|
|
27
|
-
self.cache.move_to_end(key)
|
|
28
|
-
# ---
|
|
29
|
-
|
|
30
|
-
return value
|
|
31
|
-
|
|
32
|
-
def put(self, key, value):
|
|
33
|
-
# CACHE
|
|
34
|
-
if key in self.cache:
|
|
35
|
-
del self.cache[key]
|
|
36
|
-
# CACHE & LRU
|
|
37
|
-
elif len(self.cache) >= self.capacity:
|
|
38
|
-
self.cache.popitem(last=False)
|
|
39
|
-
# -----------
|
|
40
|
-
|
|
41
|
-
# TTL
|
|
42
|
-
self.cache[key] = (value, time() + self.ttl)
|
|
43
|
-
# ---
|
|
File without changes
|