agenta 0.27.0__py3-none-any.whl → 0.27.0a0__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/__init__.py +3 -23
- agenta/cli/helper.py +1 -5
- agenta/client/backend/__init__.py +0 -14
- agenta/client/backend/apps/client.py +20 -28
- agenta/client/backend/client.py +2 -25
- agenta/client/backend/containers/client.py +1 -5
- agenta/client/backend/core/__init__.py +1 -2
- agenta/client/backend/core/client_wrapper.py +6 -6
- agenta/client/backend/core/file.py +11 -33
- agenta/client/backend/core/http_client.py +18 -24
- agenta/client/backend/core/pydantic_utilities.py +29 -144
- agenta/client/backend/core/request_options.py +0 -3
- agenta/client/backend/core/serialization.py +42 -139
- agenta/client/backend/evaluations/client.py +2 -7
- agenta/client/backend/evaluators/client.py +1 -349
- agenta/client/backend/observability/client.py +2 -11
- agenta/client/backend/testsets/client.py +10 -10
- agenta/client/backend/types/__init__.py +0 -14
- agenta/client/backend/types/app.py +0 -1
- agenta/client/backend/types/app_variant_response.py +1 -3
- agenta/client/backend/types/create_span.py +2 -3
- agenta/client/backend/types/environment_output.py +0 -1
- agenta/client/backend/types/environment_output_extended.py +0 -1
- agenta/client/backend/types/evaluation.py +2 -1
- agenta/client/backend/types/evaluator.py +0 -2
- agenta/client/backend/types/evaluator_config.py +0 -1
- agenta/client/backend/types/human_evaluation.py +2 -1
- agenta/client/backend/types/llm_tokens.py +2 -2
- agenta/client/backend/types/span.py +0 -1
- agenta/client/backend/types/span_detail.py +1 -7
- agenta/client/backend/types/test_set_output_response.py +2 -5
- agenta/client/backend/types/trace_detail.py +1 -7
- agenta/client/backend/types/with_pagination.py +2 -4
- agenta/client/backend/variants/client.py +273 -1566
- agenta/docker/docker-assets/Dockerfile.cloud.template +1 -1
- agenta/sdk/__init__.py +5 -21
- agenta/sdk/agenta_init.py +29 -34
- agenta/sdk/config_manager.py +205 -0
- agenta/sdk/context/routing.py +5 -6
- agenta/sdk/decorators/routing.py +146 -158
- agenta/sdk/decorators/tracing.py +239 -206
- agenta/sdk/litellm/litellm.py +36 -47
- agenta/sdk/tracing/attributes.py +47 -7
- agenta/sdk/tracing/context.py +2 -5
- agenta/sdk/tracing/conventions.py +19 -25
- agenta/sdk/tracing/exporters.py +5 -17
- agenta/sdk/tracing/inline.py +146 -92
- agenta/sdk/tracing/processors.py +13 -65
- agenta/sdk/tracing/spans.py +4 -16
- agenta/sdk/tracing/tracing.py +65 -124
- agenta/sdk/types.py +2 -61
- agenta/sdk/utils/exceptions.py +5 -38
- {agenta-0.27.0.dist-info → agenta-0.27.0a0.dist-info}/METADATA +1 -1
- {agenta-0.27.0.dist-info → agenta-0.27.0a0.dist-info}/RECORD +56 -67
- agenta/client/backend/types/config_dto.py +0 -32
- agenta/client/backend/types/config_response_model.py +0 -32
- agenta/client/backend/types/evaluator_mapping_output_interface.py +0 -21
- agenta/client/backend/types/evaluator_output_interface.py +0 -21
- agenta/client/backend/types/lifecycle_dto.py +0 -24
- agenta/client/backend/types/reference_dto.py +0 -23
- agenta/client/backend/types/reference_request_model.py +0 -23
- agenta/sdk/managers/__init__.py +0 -6
- agenta/sdk/managers/config.py +0 -318
- agenta/sdk/managers/deployment.py +0 -45
- agenta/sdk/managers/shared.py +0 -639
- agenta/sdk/managers/variant.py +0 -182
- {agenta-0.27.0.dist-info → agenta-0.27.0a0.dist-info}/WHEEL +0 -0
- {agenta-0.27.0.dist-info → agenta-0.27.0a0.dist-info}/entry_points.txt +0 -0
agenta/sdk/tracing/processors.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Optional,
|
|
1
|
+
from typing import Optional, Any, Dict
|
|
2
2
|
|
|
3
3
|
from opentelemetry.context import Context
|
|
4
4
|
from opentelemetry.sdk.trace import Span
|
|
@@ -6,12 +6,10 @@ from opentelemetry.sdk.trace.export import (
|
|
|
6
6
|
SpanExporter,
|
|
7
7
|
ReadableSpan,
|
|
8
8
|
BatchSpanProcessor,
|
|
9
|
+
_DEFAULT_EXPORT_TIMEOUT_MILLIS,
|
|
9
10
|
_DEFAULT_MAX_QUEUE_SIZE,
|
|
10
|
-
_DEFAULT_MAX_EXPORT_BATCH_SIZE,
|
|
11
11
|
)
|
|
12
12
|
|
|
13
|
-
from agenta.sdk.utils.logging import log
|
|
14
|
-
|
|
15
13
|
# LOAD CONTEXT, HERE
|
|
16
14
|
|
|
17
15
|
|
|
@@ -28,21 +26,16 @@ class TraceProcessor(BatchSpanProcessor):
|
|
|
28
26
|
super().__init__(
|
|
29
27
|
span_exporter,
|
|
30
28
|
_DEFAULT_MAX_QUEUE_SIZE,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
60 * 60 * 1000, # 1 hour
|
|
30
|
+
_DEFAULT_MAX_QUEUE_SIZE,
|
|
31
|
+
_DEFAULT_EXPORT_TIMEOUT_MILLIS,
|
|
34
32
|
)
|
|
35
33
|
|
|
36
34
|
self._registry = dict()
|
|
37
35
|
self._exporter = span_exporter
|
|
38
36
|
self.references = references or dict()
|
|
39
|
-
self.spans: Dict[int, List[ReadableSpan]] = dict()
|
|
40
37
|
|
|
41
|
-
def on_start(
|
|
42
|
-
self,
|
|
43
|
-
span: Span,
|
|
44
|
-
parent_context: Optional[Context] = None,
|
|
45
|
-
) -> None:
|
|
38
|
+
def on_start(self, span: Span, parent_context: Optional[Context] = None) -> None:
|
|
46
39
|
# ADD LINKS FROM CONTEXT, HERE
|
|
47
40
|
|
|
48
41
|
for key in self.references.keys():
|
|
@@ -53,65 +46,20 @@ class TraceProcessor(BatchSpanProcessor):
|
|
|
53
46
|
|
|
54
47
|
self._registry[span.context.trace_id][span.context.span_id] = True
|
|
55
48
|
|
|
56
|
-
def on_end(
|
|
57
|
-
|
|
58
|
-
span: ReadableSpan,
|
|
59
|
-
):
|
|
60
|
-
if self.done:
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
if span.context.trace_id not in self.spans:
|
|
64
|
-
self.spans[span.context.trace_id] = list()
|
|
65
|
-
|
|
66
|
-
self.spans[span.context.trace_id].append(span)
|
|
49
|
+
def on_end(self, span: ReadableSpan):
|
|
50
|
+
super().on_end(span)
|
|
67
51
|
|
|
68
52
|
del self._registry[span.context.trace_id][span.context.span_id]
|
|
69
53
|
|
|
70
|
-
if
|
|
71
|
-
self.
|
|
72
|
-
|
|
73
|
-
def export(
|
|
74
|
-
self,
|
|
75
|
-
trace_id: int,
|
|
76
|
-
):
|
|
77
|
-
spans = self.spans[trace_id]
|
|
54
|
+
if self.is_ready(span.get_span_context().trace_id):
|
|
55
|
+
self.force_flush()
|
|
78
56
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
with self.condition:
|
|
83
|
-
self.condition.notify()
|
|
84
|
-
|
|
85
|
-
del self.spans[trace_id]
|
|
86
|
-
|
|
87
|
-
def force_flush(
|
|
88
|
-
self,
|
|
89
|
-
timeout_millis: int = None,
|
|
90
|
-
) -> bool:
|
|
91
|
-
ret = super().force_flush(timeout_millis)
|
|
92
|
-
|
|
93
|
-
if not ret:
|
|
94
|
-
log.error("--------------------------------------------")
|
|
95
|
-
log.error("Agenta SDK - skipping export due to timeout.")
|
|
96
|
-
log.error("--------------------------------------------")
|
|
97
|
-
|
|
98
|
-
def is_ready(
|
|
99
|
-
self,
|
|
100
|
-
trace_id: Optional[int] = None,
|
|
101
|
-
) -> bool:
|
|
102
|
-
is_ready = True
|
|
103
|
-
|
|
104
|
-
try:
|
|
105
|
-
is_ready = self._exporter.is_ready(trace_id)
|
|
106
|
-
except: # pylint: disable=bare-except
|
|
107
|
-
pass
|
|
57
|
+
def is_ready(self, trace_id: Optional[int] = None) -> bool:
|
|
58
|
+
is_ready = not len(self._registry.get(trace_id, {}))
|
|
108
59
|
|
|
109
60
|
return is_ready
|
|
110
61
|
|
|
111
|
-
def fetch(
|
|
112
|
-
self,
|
|
113
|
-
trace_id: Optional[int] = None,
|
|
114
|
-
) -> Dict[str, ReadableSpan]:
|
|
62
|
+
def fetch(self, trace_id: Optional[int] = None) -> Dict[str, ReadableSpan]:
|
|
115
63
|
trace = self._exporter.fetch(trace_id) # type: ignore
|
|
116
64
|
|
|
117
65
|
return trace
|
agenta/sdk/tracing/spans.py
CHANGED
|
@@ -8,10 +8,7 @@ from agenta.sdk.tracing.attributes import serialize
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class CustomSpan(Span): # INHERITANCE FOR TYPING ONLY
|
|
11
|
-
def __init__(
|
|
12
|
-
self,
|
|
13
|
-
span: Span,
|
|
14
|
-
) -> None:
|
|
11
|
+
def __init__(self, span: Span) -> None:
|
|
15
12
|
super().__init__( # INHERITANCE FOR TYPING ONLY
|
|
16
13
|
name=span.name,
|
|
17
14
|
context=span.context,
|
|
@@ -41,10 +38,7 @@ class CustomSpan(Span): # INHERITANCE FOR TYPING ONLY
|
|
|
41
38
|
def is_recording(self) -> bool:
|
|
42
39
|
return self._span.is_recording()
|
|
43
40
|
|
|
44
|
-
def update_name(
|
|
45
|
-
self,
|
|
46
|
-
name: str,
|
|
47
|
-
) -> None:
|
|
41
|
+
def update_name(self, name: str) -> None:
|
|
48
42
|
self._span.update_name(name)
|
|
49
43
|
|
|
50
44
|
def set_status(
|
|
@@ -52,10 +46,7 @@ class CustomSpan(Span): # INHERITANCE FOR TYPING ONLY
|
|
|
52
46
|
status: Union[Status, StatusCode],
|
|
53
47
|
description: Optional[str] = None,
|
|
54
48
|
) -> None:
|
|
55
|
-
self._span.set_status(
|
|
56
|
-
status=status,
|
|
57
|
-
description=description,
|
|
58
|
-
)
|
|
49
|
+
self._span.set_status(status=status, description=description)
|
|
59
50
|
|
|
60
51
|
def end(self) -> None:
|
|
61
52
|
self._span.end()
|
|
@@ -82,10 +73,7 @@ class CustomSpan(Span): # INHERITANCE FOR TYPING ONLY
|
|
|
82
73
|
value: Any,
|
|
83
74
|
namespace: Optional[str] = None,
|
|
84
75
|
) -> None:
|
|
85
|
-
self.set_attributes(
|
|
86
|
-
attributes={key: value},
|
|
87
|
-
namespace=namespace,
|
|
88
|
-
)
|
|
76
|
+
self.set_attributes({key: value}, namespace)
|
|
89
77
|
|
|
90
78
|
def add_event(
|
|
91
79
|
self,
|
agenta/sdk/tracing/tracing.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
from typing import Optional, Any, Dict
|
|
2
|
-
from enum import Enum
|
|
3
2
|
|
|
4
3
|
from httpx import get as check
|
|
5
4
|
|
|
@@ -14,13 +13,14 @@ from opentelemetry.sdk.trace import Span, Tracer, TracerProvider
|
|
|
14
13
|
from opentelemetry.sdk.resources import Resource
|
|
15
14
|
|
|
16
15
|
from agenta.sdk.utils.singleton import Singleton
|
|
17
|
-
from agenta.sdk.utils.exceptions import suppress
|
|
16
|
+
from agenta.sdk.utils.exceptions import suppress # USE IT !
|
|
18
17
|
from agenta.sdk.utils.logging import log
|
|
18
|
+
|
|
19
19
|
from agenta.sdk.tracing.processors import TraceProcessor
|
|
20
|
-
from agenta.sdk.tracing.exporters import InlineExporter, OTLPExporter
|
|
20
|
+
from agenta.sdk.tracing.exporters import ConsoleExporter, InlineExporter, OTLPExporter
|
|
21
21
|
from agenta.sdk.tracing.spans import CustomSpan
|
|
22
|
+
from agenta.sdk.tracing.context import tracing_context
|
|
22
23
|
from agenta.sdk.tracing.inline import parse_inline_trace
|
|
23
|
-
from agenta.sdk.tracing.conventions import Reference, is_valid_attribute_key
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
class Tracing(metaclass=Singleton):
|
|
@@ -35,6 +35,10 @@ class Tracing(metaclass=Singleton):
|
|
|
35
35
|
) -> None:
|
|
36
36
|
# ENDPOINT (OTLP)
|
|
37
37
|
self.otlp_url = url
|
|
38
|
+
# AUTHENTICATION (OTLP)
|
|
39
|
+
self.project_id: Optional[str] = None
|
|
40
|
+
# AUTHORIZATION (OTLP)
|
|
41
|
+
self.api_key: Optional[str] = None
|
|
38
42
|
# HEADERS (OTLP)
|
|
39
43
|
self.headers: Dict[str, str] = dict()
|
|
40
44
|
# REFERENCES
|
|
@@ -42,8 +46,6 @@ class Tracing(metaclass=Singleton):
|
|
|
42
46
|
|
|
43
47
|
# TRACER PROVIDER
|
|
44
48
|
self.tracer_provider: Optional[TracerProvider] = None
|
|
45
|
-
# TRACE PROCESSORS -- INLINE
|
|
46
|
-
self.inline: Optional[TraceProcessor] = None
|
|
47
49
|
# TRACER
|
|
48
50
|
self.tracer: Optional[Tracer] = None
|
|
49
51
|
# INLINE SPANS for INLINE TRACES (INLINE PROCESSOR)
|
|
@@ -53,74 +55,75 @@ class Tracing(metaclass=Singleton):
|
|
|
53
55
|
|
|
54
56
|
def configure(
|
|
55
57
|
self,
|
|
58
|
+
project_id: Optional[str] = None,
|
|
56
59
|
api_key: Optional[str] = None,
|
|
57
|
-
#
|
|
60
|
+
#
|
|
58
61
|
app_id: Optional[str] = None,
|
|
59
62
|
):
|
|
63
|
+
# AUTHENTICATION (OTLP)
|
|
64
|
+
self.project_id = project_id # "f7943e42-ec69-498e-bf58-8db034b9286e"
|
|
65
|
+
self.app_id = app_id
|
|
66
|
+
# AUTHORIZATION (OTLP)
|
|
67
|
+
self.api_key = api_key
|
|
60
68
|
# HEADERS (OTLP)
|
|
69
|
+
self.headers = {}
|
|
70
|
+
if project_id:
|
|
71
|
+
self.headers.update(**{"AG-PROJECT-ID": project_id})
|
|
72
|
+
if app_id:
|
|
73
|
+
self.headers.update(**{"AG-APP-ID": app_id})
|
|
61
74
|
if api_key:
|
|
62
|
-
self.headers
|
|
75
|
+
self.headers.update(**{"Authorization": self.api_key})
|
|
63
76
|
# REFERENCES
|
|
64
|
-
|
|
65
|
-
self.references["application.id"] = app_id
|
|
77
|
+
self.references = {"application_id": app_id}
|
|
66
78
|
|
|
67
79
|
# TRACER PROVIDER
|
|
68
80
|
self.tracer_provider = TracerProvider(
|
|
69
81
|
resource=Resource(attributes={"service.name": "agenta-sdk"})
|
|
70
82
|
)
|
|
83
|
+
# TRACE PROCESSORS -- CONSOLE
|
|
84
|
+
# _console = TraceProcessor(
|
|
85
|
+
# ConsoleExporter(),
|
|
86
|
+
# references=self.references,
|
|
87
|
+
# )
|
|
88
|
+
# self.tracer_provider.add_span_processor(_console)
|
|
71
89
|
# TRACE PROCESSORS -- INLINE
|
|
72
90
|
self.inline = TraceProcessor(
|
|
73
|
-
InlineExporter(
|
|
74
|
-
registry=self.inline_spans,
|
|
75
|
-
),
|
|
91
|
+
InlineExporter(registry=self.inline_spans),
|
|
76
92
|
references=self.references,
|
|
77
93
|
)
|
|
78
94
|
self.tracer_provider.add_span_processor(self.inline)
|
|
79
95
|
# TRACE PROCESSORS -- OTLP
|
|
80
96
|
try:
|
|
81
|
-
log.info("
|
|
82
|
-
log.info(
|
|
83
|
-
"Agenta SDK - connecting to otlp receiver at: %s",
|
|
84
|
-
self.otlp_url,
|
|
85
|
-
)
|
|
86
|
-
log.info("--------------------------------------------")
|
|
97
|
+
log.info(f"Connecting to the remote trace receiver at {self.otlp_url}...")
|
|
87
98
|
|
|
88
|
-
check(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
timeout=1,
|
|
92
|
-
)
|
|
99
|
+
check(self.otlp_url, headers=self.headers, timeout=1)
|
|
100
|
+
|
|
101
|
+
log.info(f"Connection established.")
|
|
93
102
|
|
|
94
103
|
_otlp = TraceProcessor(
|
|
95
|
-
OTLPExporter(
|
|
96
|
-
endpoint=self.otlp_url,
|
|
97
|
-
headers=self.headers,
|
|
98
|
-
),
|
|
104
|
+
OTLPExporter(endpoint=self.otlp_url, headers=self.headers),
|
|
99
105
|
references=self.references,
|
|
100
106
|
)
|
|
101
107
|
|
|
102
108
|
self.tracer_provider.add_span_processor(_otlp)
|
|
103
|
-
|
|
104
|
-
log.
|
|
105
|
-
log.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
log.warning("--------------------------------------------")
|
|
110
|
-
|
|
109
|
+
except Exception as e:
|
|
110
|
+
log.error(e)
|
|
111
|
+
log.warning(f"Connection failed.")
|
|
112
|
+
log.warning(
|
|
113
|
+
f"Warning: Your traces will not be exported since {self.otlp_url} is unreachable."
|
|
114
|
+
)
|
|
111
115
|
# GLOBAL TRACER PROVIDER -- INSTRUMENTATION LIBRARIES
|
|
112
116
|
set_tracer_provider(self.tracer_provider)
|
|
113
117
|
# TRACER
|
|
114
118
|
self.tracer: Tracer = self.tracer_provider.get_tracer("agenta.tracer")
|
|
115
119
|
|
|
116
|
-
def get_current_span(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
_span = get_current_span()
|
|
120
|
+
def get_current_span(
|
|
121
|
+
self,
|
|
122
|
+
):
|
|
123
|
+
_span = get_current_span()
|
|
121
124
|
|
|
122
|
-
|
|
123
|
-
|
|
125
|
+
if _span.is_recording():
|
|
126
|
+
return CustomSpan(_span)
|
|
124
127
|
|
|
125
128
|
return _span
|
|
126
129
|
|
|
@@ -129,104 +132,42 @@ class Tracing(metaclass=Singleton):
|
|
|
129
132
|
attributes: Dict[str, Any],
|
|
130
133
|
span: Optional[Span] = None,
|
|
131
134
|
):
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
span = self.get_current_span()
|
|
135
|
+
if span is None:
|
|
136
|
+
span = self.get_current_span()
|
|
135
137
|
|
|
136
|
-
|
|
137
|
-
attributes={"internals": attributes},
|
|
138
|
-
namespace="data",
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
def store_refs(
|
|
142
|
-
self,
|
|
143
|
-
refs: Dict[str, str],
|
|
144
|
-
span: Optional[Span] = None,
|
|
145
|
-
):
|
|
146
|
-
with suppress():
|
|
147
|
-
if span is None:
|
|
148
|
-
span = self.get_current_span()
|
|
149
|
-
|
|
150
|
-
for key in refs.keys():
|
|
151
|
-
if key in [_.value for _ in Reference.__members__.values()]:
|
|
152
|
-
# ADD REFERENCE TO THIS SPAN
|
|
153
|
-
span.set_attribute(
|
|
154
|
-
key.value if isinstance(key, Enum) else key,
|
|
155
|
-
refs[key],
|
|
156
|
-
namespace="refs",
|
|
157
|
-
)
|
|
158
|
-
|
|
159
|
-
# AND TO ALL SPANS CREATED AFTER THIS ONE
|
|
160
|
-
self.references[key] = refs[key]
|
|
161
|
-
# TODO: THIS SHOULD BE REPLACED BY A TRACE CONTEXT !!!
|
|
162
|
-
|
|
163
|
-
def store_meta(
|
|
164
|
-
self,
|
|
165
|
-
meta: Dict[str, Any],
|
|
166
|
-
span: Optional[Span] = None,
|
|
167
|
-
):
|
|
168
|
-
with suppress():
|
|
169
|
-
if span is None:
|
|
170
|
-
span = self.get_current_span()
|
|
171
|
-
|
|
172
|
-
for key in meta.keys():
|
|
173
|
-
if is_valid_attribute_key(key):
|
|
174
|
-
span.set_attribute(
|
|
175
|
-
key,
|
|
176
|
-
meta[key],
|
|
177
|
-
namespace="meta",
|
|
178
|
-
)
|
|
179
|
-
|
|
180
|
-
def store_metrics(
|
|
181
|
-
self,
|
|
182
|
-
metrics: Dict[str, Any],
|
|
183
|
-
span: Optional[Span] = None,
|
|
184
|
-
):
|
|
185
|
-
with suppress():
|
|
186
|
-
if span is None:
|
|
187
|
-
span = self.get_current_span()
|
|
188
|
-
|
|
189
|
-
for key in metrics.keys():
|
|
190
|
-
if is_valid_attribute_key(key):
|
|
191
|
-
span.set_attribute(
|
|
192
|
-
key,
|
|
193
|
-
metrics[key],
|
|
194
|
-
namespace="metrics",
|
|
195
|
-
)
|
|
138
|
+
span.set_attributes(attributes={"internals": attributes}, namespace="data")
|
|
196
139
|
|
|
197
140
|
def is_inline_trace_ready(
|
|
198
141
|
self,
|
|
199
|
-
trace_id:
|
|
142
|
+
trace_id: int,
|
|
200
143
|
) -> bool:
|
|
201
|
-
is_ready =
|
|
202
|
-
|
|
203
|
-
with suppress():
|
|
204
|
-
if trace_id is not None:
|
|
205
|
-
is_ready = self.inline.is_ready(trace_id)
|
|
144
|
+
is_ready = self.inline.is_ready(trace_id)
|
|
206
145
|
|
|
207
146
|
return is_ready
|
|
208
147
|
|
|
209
148
|
def get_inline_trace(
|
|
210
149
|
self,
|
|
211
|
-
trace_id:
|
|
150
|
+
trace_id: int,
|
|
212
151
|
) -> Dict[str, Any]:
|
|
213
|
-
|
|
152
|
+
if trace_id is None:
|
|
153
|
+
return {}
|
|
154
|
+
|
|
155
|
+
is_ready = self.inline.is_ready(trace_id)
|
|
156
|
+
|
|
157
|
+
if is_ready is False:
|
|
158
|
+
return {}
|
|
214
159
|
|
|
215
|
-
|
|
216
|
-
is_ready = self.inline.is_ready(trace_id)
|
|
160
|
+
otel_spans = self.inline.fetch(trace_id)
|
|
217
161
|
|
|
218
|
-
|
|
219
|
-
|
|
162
|
+
if not otel_spans:
|
|
163
|
+
return {}
|
|
220
164
|
|
|
221
|
-
|
|
222
|
-
_inline_trace = parse_inline_trace(otel_spans)
|
|
165
|
+
inline_trace = parse_inline_trace(self.project_id or self.app_id, otel_spans)
|
|
223
166
|
|
|
224
|
-
return
|
|
167
|
+
return inline_trace
|
|
225
168
|
|
|
226
169
|
|
|
227
|
-
def get_tracer(
|
|
228
|
-
tracing: Tracing,
|
|
229
|
-
) -> Tracer:
|
|
170
|
+
def get_tracer(tracing: Tracing) -> Tracer:
|
|
230
171
|
if tracing is None or tracing.tracer is None or tracing.tracer_provider is None:
|
|
231
172
|
return get_tracer_provider().get_tracer("default.tracer")
|
|
232
173
|
|
agenta/sdk/types.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import json
|
|
2
|
-
from dataclasses import dataclass
|
|
3
2
|
from typing import Dict, List, Optional, Any, Union
|
|
4
3
|
|
|
5
4
|
from pydantic import ConfigDict, BaseModel, HttpUrl
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Union
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
@dataclass
|
|
@@ -185,63 +186,3 @@ class FileInputURL(HttpUrl):
|
|
|
185
186
|
@classmethod
|
|
186
187
|
def __schema_type_properties__(cls) -> dict:
|
|
187
188
|
return {"x-parameter": "file_url", "type": "string"}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
class Context(BaseModel):
|
|
191
|
-
model_config = ConfigDict(extra="allow")
|
|
192
|
-
|
|
193
|
-
def to_json(self):
|
|
194
|
-
return self.model_dump()
|
|
195
|
-
|
|
196
|
-
@classmethod
|
|
197
|
-
def from_json(cls, json_str: str):
|
|
198
|
-
data = json.loads(json_str)
|
|
199
|
-
return cls(**data)
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
class ReferencesResponse(BaseModel):
|
|
203
|
-
app_id: Optional[str] = None
|
|
204
|
-
app_slug: Optional[str] = None
|
|
205
|
-
variant_id: Optional[str] = None
|
|
206
|
-
variant_slug: Optional[str] = None
|
|
207
|
-
variant_version: Optional[int] = None
|
|
208
|
-
environment_id: Optional[str] = None
|
|
209
|
-
environment_slug: Optional[str] = None
|
|
210
|
-
environment_version: Optional[int] = None
|
|
211
|
-
|
|
212
|
-
def __str__(self):
|
|
213
|
-
return str(self.model_dump(exclude_none=True))
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
class LifecyclesResponse(ReferencesResponse):
|
|
217
|
-
committed_at: Optional[str] = None
|
|
218
|
-
committed_by: Optional[str] = None
|
|
219
|
-
committed_by_id: Optional[str] = None
|
|
220
|
-
deployed_at: Optional[str] = None
|
|
221
|
-
deployed_by: Optional[str] = None
|
|
222
|
-
deployed_by_id: Optional[str] = None
|
|
223
|
-
|
|
224
|
-
def __str__(self):
|
|
225
|
-
return self.model_dump_json(indent=4)
|
|
226
|
-
|
|
227
|
-
def __repr__(self):
|
|
228
|
-
return self.__str__()
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
class ConfigurationResponse(LifecyclesResponse):
|
|
232
|
-
params: Dict[str, Any]
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
class DeploymentResponse(LifecyclesResponse):
|
|
236
|
-
pass
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
class Prompt(BaseModel):
|
|
240
|
-
temperature: float
|
|
241
|
-
model: str
|
|
242
|
-
max_tokens: int
|
|
243
|
-
prompt_system: str
|
|
244
|
-
prompt_user: str
|
|
245
|
-
top_p: float
|
|
246
|
-
frequency_penalty: float
|
|
247
|
-
presence_penalty: float
|
agenta/sdk/utils/exceptions.py
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
from contextlib import AbstractContextManager
|
|
2
2
|
from traceback import format_exc
|
|
3
|
-
from functools import wraps
|
|
4
|
-
from inspect import iscoroutinefunction
|
|
5
|
-
|
|
6
3
|
from agenta.sdk.utils.logging import log
|
|
7
4
|
|
|
8
5
|
|
|
9
|
-
class suppress(AbstractContextManager):
|
|
6
|
+
class suppress(AbstractContextManager):
|
|
10
7
|
def __init__(self):
|
|
11
8
|
pass
|
|
12
9
|
|
|
@@ -15,38 +12,8 @@ class suppress(AbstractContextManager): # pylint: disable=invalid-name
|
|
|
15
12
|
|
|
16
13
|
def __exit__(self, exc_type, exc_value, exc_tb):
|
|
17
14
|
if exc_type is None:
|
|
18
|
-
return
|
|
15
|
+
return
|
|
19
16
|
else:
|
|
20
|
-
|
|
21
|
-
log.error("
|
|
22
|
-
|
|
23
|
-
log.error(format_exc().strip("\n"))
|
|
24
|
-
log.error("-------------------------------------------------")
|
|
25
|
-
return True
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def handle_exceptions():
|
|
29
|
-
def decorator(func):
|
|
30
|
-
is_coroutine_function = iscoroutinefunction(func)
|
|
31
|
-
|
|
32
|
-
@wraps(func)
|
|
33
|
-
async def async_wrapper(*args, **kwargs):
|
|
34
|
-
try:
|
|
35
|
-
return await func(*args, **kwargs)
|
|
36
|
-
except Exception as e:
|
|
37
|
-
log.error("--- HANDLING EXCEPTION ---")
|
|
38
|
-
log.error("--------------------------")
|
|
39
|
-
raise e
|
|
40
|
-
|
|
41
|
-
@wraps(func)
|
|
42
|
-
def sync_wrapper(*args, **kwargs):
|
|
43
|
-
try:
|
|
44
|
-
return func(*args, **kwargs)
|
|
45
|
-
except Exception as e:
|
|
46
|
-
log.error("--- HANDLING EXCEPTION ---")
|
|
47
|
-
log.error("--------------------------")
|
|
48
|
-
raise e
|
|
49
|
-
|
|
50
|
-
return async_wrapper if is_coroutine_function else sync_wrapper
|
|
51
|
-
|
|
52
|
-
return decorator
|
|
17
|
+
print("Agenta SDK - Tracing Exception")
|
|
18
|
+
log.error(f"{exc_type.__name__}: {exc_value}\n{format_exc()}")
|
|
19
|
+
return
|