arthur-common 2.1.59__py3-none-any.whl → 2.1.61__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 arthur-common might be problematic. Click here for more details.
- arthur_common/aggregations/aggregator.py +3 -1
- arthur_common/aggregations/functions/agentic_aggregations.py +1 -1
- arthur_common/aggregations/functions/confusion_matrix.py +1 -1
- arthur_common/aggregations/functions/inference_count_by_class.py +1 -1
- arthur_common/aggregations/functions/mean_absolute_error.py +1 -1
- arthur_common/aggregations/functions/mean_squared_error.py +1 -1
- arthur_common/aggregations/functions/multiclass_confusion_matrix.py +1 -1
- arthur_common/aggregations/functions/multiclass_inference_count_by_class.py +1 -1
- arthur_common/aggregations/functions/shield_aggregations.py +1 -1
- arthur_common/models/common_schemas.py +208 -0
- arthur_common/models/connectors.py +3 -3
- arthur_common/models/constants.py +24 -0
- arthur_common/models/datasets.py +0 -9
- arthur_common/models/enums.py +144 -0
- arthur_common/models/metric_schemas.py +63 -0
- arthur_common/models/metrics.py +1 -1
- arthur_common/models/{shield.py → request_schemas.py} +204 -295
- arthur_common/models/response_schemas.py +682 -0
- arthur_common/models/schema_definitions.py +1 -1
- arthur_common/models/task_job_specs.py +3 -12
- arthur_common/tools/duckdb_data_loader.py +4 -2
- {arthur_common-2.1.59.dist-info → arthur_common-2.1.61.dist-info}/METADATA +4 -3
- {arthur_common-2.1.59.dist-info → arthur_common-2.1.61.dist-info}/RECORD +24 -19
- {arthur_common-2.1.59.dist-info → arthur_common-2.1.61.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,682 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import Any, List, Optional, Union
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
5
|
+
|
|
6
|
+
from arthur_common.models.common_schemas import (
|
|
7
|
+
AuthUserRole,
|
|
8
|
+
ExamplesConfig,
|
|
9
|
+
KeywordsConfig,
|
|
10
|
+
PIIConfig,
|
|
11
|
+
RegexConfig,
|
|
12
|
+
ToxicityConfig,
|
|
13
|
+
)
|
|
14
|
+
from arthur_common.models.enums import (
|
|
15
|
+
InferenceFeedbackTarget,
|
|
16
|
+
MetricType,
|
|
17
|
+
PIIEntityTypes,
|
|
18
|
+
RuleResultEnum,
|
|
19
|
+
RuleScope,
|
|
20
|
+
RuleType,
|
|
21
|
+
ToxicityViolationType,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class HTTPError(BaseModel):
|
|
26
|
+
detail: str
|
|
27
|
+
|
|
28
|
+
model_config = ConfigDict(
|
|
29
|
+
json_schema_extra={
|
|
30
|
+
"example": {"detail": "HTTPException raised."},
|
|
31
|
+
},
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class RuleResponse(BaseModel):
|
|
36
|
+
id: str = Field(description="ID of the Rule")
|
|
37
|
+
name: str = Field(description="Name of the Rule")
|
|
38
|
+
type: RuleType = Field(description="Type of Rule")
|
|
39
|
+
apply_to_prompt: bool = Field(description="Rule applies to prompt")
|
|
40
|
+
apply_to_response: bool = Field(description="Rule applies to response")
|
|
41
|
+
enabled: Optional[bool] = Field(
|
|
42
|
+
description="Rule is enabled for the task",
|
|
43
|
+
default=None,
|
|
44
|
+
)
|
|
45
|
+
scope: RuleScope = Field(
|
|
46
|
+
description="Scope of the rule. The rule can be set at default level or task level.",
|
|
47
|
+
)
|
|
48
|
+
# UNIX millis format
|
|
49
|
+
created_at: int = Field(
|
|
50
|
+
description="Time the rule was created in unix milliseconds",
|
|
51
|
+
)
|
|
52
|
+
updated_at: int = Field(
|
|
53
|
+
description="Time the rule was updated in unix milliseconds",
|
|
54
|
+
)
|
|
55
|
+
config: (
|
|
56
|
+
KeywordsConfig
|
|
57
|
+
| RegexConfig
|
|
58
|
+
| ExamplesConfig
|
|
59
|
+
| ToxicityConfig
|
|
60
|
+
| PIIConfig
|
|
61
|
+
| None
|
|
62
|
+
) = Field(description="Config of the rule", default=None)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class HallucinationClaimResponse(BaseModel):
|
|
66
|
+
claim: str
|
|
67
|
+
valid: bool
|
|
68
|
+
reason: str
|
|
69
|
+
order_number: Optional[int] = Field(
|
|
70
|
+
default=-1,
|
|
71
|
+
description="This field is a helper for ordering the claims",
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class PIIEntitySpanResponse(BaseModel):
|
|
76
|
+
entity: PIIEntityTypes
|
|
77
|
+
span: str = Field(
|
|
78
|
+
description="The subtext within the input string that was identified as PII.",
|
|
79
|
+
)
|
|
80
|
+
# Only optional to keep reverse compatibility with old inferences
|
|
81
|
+
confidence: Optional[float] = Field(
|
|
82
|
+
description="Float value representing the confidence score of a given PII identification.",
|
|
83
|
+
default=None,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class KeywordSpanResponse(BaseModel):
|
|
88
|
+
keyword: str = Field(
|
|
89
|
+
description="The keyword from the rule that matched within the input string.",
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class RegexSpanResponse(BaseModel):
|
|
94
|
+
matching_text: str = Field(
|
|
95
|
+
description="The subtext within the input string that matched the regex rule.",
|
|
96
|
+
)
|
|
97
|
+
pattern: Optional[str] = Field(
|
|
98
|
+
description="Pattern that yielded the match.",
|
|
99
|
+
default=None,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class BaseDetailsResponse(BaseModel):
|
|
104
|
+
score: Optional[bool] = None
|
|
105
|
+
message: Optional[str] = None
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class HallucinationDetailsResponse(BaseDetailsResponse):
|
|
109
|
+
claims: list[HallucinationClaimResponse]
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class PIIDetailsResponse(BaseDetailsResponse):
|
|
113
|
+
pii_entities: list[PIIEntitySpanResponse]
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class ToxicityDetailsResponse(BaseDetailsResponse):
|
|
117
|
+
toxicity_score: Optional[float] = None
|
|
118
|
+
toxicity_violation_type: ToxicityViolationType
|
|
119
|
+
|
|
120
|
+
model_config = ConfigDict(extra="forbid")
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class KeywordDetailsResponse(BaseDetailsResponse):
|
|
124
|
+
keyword_matches: list[KeywordSpanResponse] = Field(
|
|
125
|
+
[],
|
|
126
|
+
description="Each keyword in this list corresponds to a keyword that was both configured in the rule that was "
|
|
127
|
+
"run and found in the input text.",
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
model_config = ConfigDict(extra="forbid")
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
class RegexDetailsResponse(BaseDetailsResponse):
|
|
134
|
+
regex_matches: list[RegexSpanResponse] = Field(
|
|
135
|
+
[],
|
|
136
|
+
description="Each string in this list corresponds to a matching span from the input text that matches the "
|
|
137
|
+
"configured regex rule.",
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
model_config = ConfigDict(extra="forbid")
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class ExternalRuleResult(BaseModel):
|
|
144
|
+
id: str = Field(description=" ID of the rule")
|
|
145
|
+
name: str = Field(description="Name of the rule")
|
|
146
|
+
rule_type: RuleType = Field(description="Type of the rule")
|
|
147
|
+
scope: RuleScope = Field(
|
|
148
|
+
description="Scope of the rule. The rule can be set at default level or task level.",
|
|
149
|
+
)
|
|
150
|
+
result: RuleResultEnum = Field(description="Result if the rule")
|
|
151
|
+
latency_ms: int = Field(description="Duration in millisesconds of rule execution")
|
|
152
|
+
|
|
153
|
+
# The super class (BaseDetailsResponse) must come last in this ordering otherwise the fastapi serializer will pick
|
|
154
|
+
# it for the less specific types and you'll waste time figuring out why type1 is being serialized as type2
|
|
155
|
+
# https://github.com/tiangolo/fastapi/issues/2783#issuecomment-776662347
|
|
156
|
+
details: Optional[
|
|
157
|
+
Union[
|
|
158
|
+
KeywordDetailsResponse,
|
|
159
|
+
RegexDetailsResponse,
|
|
160
|
+
HallucinationDetailsResponse,
|
|
161
|
+
PIIDetailsResponse,
|
|
162
|
+
ToxicityDetailsResponse,
|
|
163
|
+
BaseDetailsResponse,
|
|
164
|
+
]
|
|
165
|
+
] = Field(description="Details of the rule output", default=None)
|
|
166
|
+
|
|
167
|
+
model_config = ConfigDict(
|
|
168
|
+
json_schema_extra={
|
|
169
|
+
"example": {
|
|
170
|
+
"id": "90f18c69-d793-4913-9bde-a0c7f3643de0",
|
|
171
|
+
"name": "PII Rule",
|
|
172
|
+
"result": "Pass",
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
class ValidationResult(BaseModel):
|
|
179
|
+
inference_id: Optional[str] = Field(description="ID of the inference", default=None)
|
|
180
|
+
rule_results: Optional[List[ExternalRuleResult]] = Field(
|
|
181
|
+
description="List of rule results",
|
|
182
|
+
default=None,
|
|
183
|
+
)
|
|
184
|
+
user_id: Optional[str] = Field(
|
|
185
|
+
description="The user ID this prompt belongs to",
|
|
186
|
+
default=None,
|
|
187
|
+
)
|
|
188
|
+
model_config = ConfigDict(
|
|
189
|
+
json_schema_extra={
|
|
190
|
+
"example": {
|
|
191
|
+
"inference_id": "4dd1fae1-34b9-4aec-8abe-fe7bf12af31d",
|
|
192
|
+
"rule_results": [
|
|
193
|
+
{
|
|
194
|
+
"id": "90f18c69-d793-4913-9bde-a0c7f3643de0",
|
|
195
|
+
"name": "PII Check",
|
|
196
|
+
"result": "Pass",
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
"id": "946c4a44-b367-4229-84d4-1a8e461cb132",
|
|
200
|
+
"name": "Sensitive Data Check",
|
|
201
|
+
"result": "Pass",
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
class ExternalInferencePrompt(BaseModel):
|
|
210
|
+
id: str
|
|
211
|
+
inference_id: str
|
|
212
|
+
result: RuleResultEnum
|
|
213
|
+
created_at: int
|
|
214
|
+
updated_at: int
|
|
215
|
+
message: str
|
|
216
|
+
prompt_rule_results: List[ExternalRuleResult]
|
|
217
|
+
tokens: int | None = None
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
class ExternalInferenceResponse(BaseModel):
|
|
221
|
+
id: str
|
|
222
|
+
inference_id: str
|
|
223
|
+
result: RuleResultEnum
|
|
224
|
+
created_at: int
|
|
225
|
+
updated_at: int
|
|
226
|
+
message: str
|
|
227
|
+
context: Optional[str] = None
|
|
228
|
+
response_rule_results: List[ExternalRuleResult]
|
|
229
|
+
tokens: int | None = None
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
class InferenceFeedbackResponse(BaseModel):
|
|
233
|
+
id: str
|
|
234
|
+
inference_id: str
|
|
235
|
+
target: InferenceFeedbackTarget
|
|
236
|
+
score: int
|
|
237
|
+
reason: Optional[str] = None
|
|
238
|
+
user_id: Optional[str] = None
|
|
239
|
+
created_at: datetime
|
|
240
|
+
updated_at: datetime
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
class QueryFeedbackResponse(BaseModel):
|
|
244
|
+
feedback: list[InferenceFeedbackResponse] = Field(
|
|
245
|
+
description="List of inferences matching the search filters. Length is less than or equal to page_size parameter",
|
|
246
|
+
)
|
|
247
|
+
page: int = Field(description="The current page number")
|
|
248
|
+
page_size: int = Field(description="The number of feedback items per page")
|
|
249
|
+
total_pages: int = Field(description="The total number of pages")
|
|
250
|
+
total_count: int = Field(
|
|
251
|
+
description="The total number of feedback items matching the query parameters",
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
model_config = ConfigDict(
|
|
255
|
+
json_schema_extra={
|
|
256
|
+
"example": {
|
|
257
|
+
"feedback": [
|
|
258
|
+
{
|
|
259
|
+
"id": "90f18c69-d793-4913-9bde-a0c7f3643de0",
|
|
260
|
+
"inference_id": "81437d71-9557-4611-981b-9283d1c98643",
|
|
261
|
+
"target": "context",
|
|
262
|
+
"score": "0",
|
|
263
|
+
"reason": "good reason",
|
|
264
|
+
"user_id": "user_1",
|
|
265
|
+
"created_at": "2024-06-06T06:37:46.123-04:00",
|
|
266
|
+
"updated_at": "2024-06-06T06:37:46.123-04:00",
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
"id": "248381c2-543b-4de0-98cd-d7511fee6241",
|
|
270
|
+
"inference_id": "bcbc7ca0-4cfc-4f67-9cf8-26cb2291ba33",
|
|
271
|
+
"target": "response_results",
|
|
272
|
+
"score": "1",
|
|
273
|
+
"reason": "some reason",
|
|
274
|
+
"user_id": "user_2",
|
|
275
|
+
"created_at": "2023-05-05T05:26:35.987-04:00",
|
|
276
|
+
"updated_at": "2023-05-05T05:26:35.987-04:00",
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
"page": 1,
|
|
280
|
+
"page_size": 10,
|
|
281
|
+
"total_pages": 1,
|
|
282
|
+
"total_count": 2,
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
class ExternalInference(BaseModel):
|
|
289
|
+
id: str
|
|
290
|
+
result: RuleResultEnum
|
|
291
|
+
created_at: int
|
|
292
|
+
updated_at: int
|
|
293
|
+
task_id: Optional[str] = None
|
|
294
|
+
task_name: str | None = None
|
|
295
|
+
conversation_id: Optional[str] = None
|
|
296
|
+
inference_prompt: ExternalInferencePrompt
|
|
297
|
+
inference_response: Optional[ExternalInferenceResponse] = None
|
|
298
|
+
inference_feedback: List[InferenceFeedbackResponse]
|
|
299
|
+
user_id: str | None = None
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
class QueryInferencesResponse(BaseModel):
|
|
303
|
+
count: int = Field(
|
|
304
|
+
description="The total number of inferences matching the query parameters",
|
|
305
|
+
)
|
|
306
|
+
inferences: list[ExternalInference] = Field(
|
|
307
|
+
description="List of inferences matching the search filters. Length is less than or equal to page_size parameter",
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
model_config = ConfigDict(
|
|
311
|
+
json_schema_extra={
|
|
312
|
+
"example": {
|
|
313
|
+
"count": 1,
|
|
314
|
+
"inferences": [
|
|
315
|
+
{
|
|
316
|
+
"id": "957df309-c907-4b77-abe5-15dd00c081f7",
|
|
317
|
+
"result": "Pass",
|
|
318
|
+
"created_at": 1723204737120,
|
|
319
|
+
"updated_at": 1723204787050,
|
|
320
|
+
"task_id": "957df309-c907-4b77-abe5-15dd00c081f8",
|
|
321
|
+
"task_name": "My task name",
|
|
322
|
+
"conversation_id": "957df309-c907-4b77-abe5-15dd00c08112",
|
|
323
|
+
"inference_prompt": {
|
|
324
|
+
"id": "834f7ebd-cd6b-4691-9473-8bc350f8922c",
|
|
325
|
+
"inference_id": "957df309-c907-4b77-abe5-15dd00c081f7",
|
|
326
|
+
"result": "Pass",
|
|
327
|
+
"created_at": 1723204737121,
|
|
328
|
+
"updated_at": 1723204737121,
|
|
329
|
+
"message": "How many stars are in the solar system?",
|
|
330
|
+
"prompt_rule_results": [
|
|
331
|
+
{
|
|
332
|
+
"id": "bc599a56-2e31-4cb7-910d-9e5ed6455db2",
|
|
333
|
+
"name": "My_PII_Rule",
|
|
334
|
+
"rule_type": "PIIDataRule",
|
|
335
|
+
"scope": "default",
|
|
336
|
+
"result": "Pass",
|
|
337
|
+
"latency_ms": 73,
|
|
338
|
+
"details": None,
|
|
339
|
+
},
|
|
340
|
+
],
|
|
341
|
+
"tokens": 100,
|
|
342
|
+
},
|
|
343
|
+
"inference_response": {
|
|
344
|
+
"id": "ec765a75-1479-4938-8e1c-6334b7deb8ce",
|
|
345
|
+
"inference_id": "957df309-c907-4b77-abe5-15dd00c081f7",
|
|
346
|
+
"result": "Pass",
|
|
347
|
+
"created_at": 1723204786599,
|
|
348
|
+
"updated_at": 1723204786599,
|
|
349
|
+
"message": "There is one star in solar system.",
|
|
350
|
+
"context": "Solar system contains one star.",
|
|
351
|
+
"response_rule_results": [
|
|
352
|
+
{
|
|
353
|
+
"id": "a45267c5-96d9-4de2-a871-debf2c8fdb86",
|
|
354
|
+
"name": "My_another_PII_Rule",
|
|
355
|
+
"rule_type": "PIIDataRule",
|
|
356
|
+
"scope": "default",
|
|
357
|
+
"result": "Pass",
|
|
358
|
+
"latency_ms": 107,
|
|
359
|
+
"details": None,
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
"id": "92b7b46e-eaf2-4226-82d4-be12ceb3e4b7",
|
|
363
|
+
"name": "My_Hallucination_Rule",
|
|
364
|
+
"rule_type": "ModelHallucinationRuleV2",
|
|
365
|
+
"scope": "default",
|
|
366
|
+
"result": "Pass",
|
|
367
|
+
"latency_ms": 700,
|
|
368
|
+
"details": {
|
|
369
|
+
"score": True,
|
|
370
|
+
"message": "All claims were supported by the context!",
|
|
371
|
+
"claims": [
|
|
372
|
+
{
|
|
373
|
+
"claim": "There is one star in solar system.",
|
|
374
|
+
"valid": True,
|
|
375
|
+
"reason": "No hallucination detected!",
|
|
376
|
+
"order_number": 0,
|
|
377
|
+
},
|
|
378
|
+
],
|
|
379
|
+
"pii_results": [],
|
|
380
|
+
"pii_entities": [],
|
|
381
|
+
"toxicity_score": None,
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
],
|
|
385
|
+
"tokens": 100,
|
|
386
|
+
},
|
|
387
|
+
"inference_feedback": [
|
|
388
|
+
{
|
|
389
|
+
"id": "0d602e5c-4ae6-4fc9-a610-68a1d8928ad7",
|
|
390
|
+
"inference_id": "957df309-c907-4b77-abe5-15dd00c081f7",
|
|
391
|
+
"target": "context",
|
|
392
|
+
"score": 100,
|
|
393
|
+
"reason": "Perfect answer.",
|
|
394
|
+
"user_id": "957df309-2137-4b77-abe5-15dd00c081f8",
|
|
395
|
+
"created_at": "2024-08-09T12:08:34.847381",
|
|
396
|
+
"updated_at": "2024-08-09T12:08:34.847386",
|
|
397
|
+
},
|
|
398
|
+
],
|
|
399
|
+
"user_id": "957df309-2137-4b77-abe5-15dd00c081f8",
|
|
400
|
+
},
|
|
401
|
+
],
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
)
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
class MetricResponse(BaseModel):
|
|
408
|
+
id: str = Field(description="ID of the Metric")
|
|
409
|
+
name: str = Field(description="Name of the Metric")
|
|
410
|
+
type: MetricType = Field(description="Type of the Metric")
|
|
411
|
+
metric_metadata: str = Field(description="Metadata of the Metric")
|
|
412
|
+
config: Optional[str] = Field(
|
|
413
|
+
description="JSON-serialized configuration for the Metric",
|
|
414
|
+
default=None,
|
|
415
|
+
)
|
|
416
|
+
created_at: datetime = Field(
|
|
417
|
+
description="Time the Metric was created in unix milliseconds",
|
|
418
|
+
)
|
|
419
|
+
updated_at: datetime = Field(
|
|
420
|
+
description="Time the Metric was updated in unix milliseconds",
|
|
421
|
+
)
|
|
422
|
+
enabled: Optional[bool] = Field(
|
|
423
|
+
description="Whether the Metric is enabled",
|
|
424
|
+
default=None,
|
|
425
|
+
)
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
class TaskResponse(BaseModel):
|
|
429
|
+
id: str = Field(description=" ID of the task")
|
|
430
|
+
name: str = Field(description="Name of the task")
|
|
431
|
+
created_at: int = Field(
|
|
432
|
+
description="Time the task was created in unix milliseconds",
|
|
433
|
+
)
|
|
434
|
+
updated_at: int = Field(
|
|
435
|
+
description="Time the task was created in unix milliseconds",
|
|
436
|
+
)
|
|
437
|
+
is_agentic: Optional[bool] = Field(
|
|
438
|
+
description="Whether the task is agentic or not",
|
|
439
|
+
default=None,
|
|
440
|
+
)
|
|
441
|
+
rules: List[RuleResponse] = Field(description="List of all the rules for the task.")
|
|
442
|
+
metrics: Optional[List[MetricResponse]] = Field(
|
|
443
|
+
description="List of all the metrics for the task.",
|
|
444
|
+
default=None,
|
|
445
|
+
)
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
class SearchTasksResponse(BaseModel):
|
|
449
|
+
count: int = Field(description="The total number of tasks matching the parameters")
|
|
450
|
+
tasks: list[TaskResponse] = Field(
|
|
451
|
+
description="List of tasks matching the search filters. Length is less than or equal to page_size parameter",
|
|
452
|
+
)
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
class SearchRulesResponse(BaseModel):
|
|
456
|
+
count: int = Field(description="The total number of rules matching the parameters")
|
|
457
|
+
rules: list[RuleResponse] = Field(
|
|
458
|
+
description="List of rules matching the search filters. Length is less than or equal to page_size parameter",
|
|
459
|
+
)
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
class FileUploadResult(BaseModel):
|
|
463
|
+
id: str
|
|
464
|
+
name: str
|
|
465
|
+
type: str
|
|
466
|
+
word_count: int
|
|
467
|
+
success: bool
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
class ExternalDocument(BaseModel):
|
|
471
|
+
id: str
|
|
472
|
+
name: str
|
|
473
|
+
type: str
|
|
474
|
+
owner_id: str
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
class ChatDocumentContext(BaseModel):
|
|
478
|
+
id: str
|
|
479
|
+
seq_num: int
|
|
480
|
+
context: str
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
class ChatResponse(BaseModel):
|
|
484
|
+
inference_id: str = Field(description="ID of the inference sent to the chat")
|
|
485
|
+
conversation_id: str = Field(description="ID of the conversation session")
|
|
486
|
+
timestamp: int = Field(
|
|
487
|
+
description="Time the inference was made in unix milliseconds",
|
|
488
|
+
)
|
|
489
|
+
retrieved_context: List[ChatDocumentContext] = Field(
|
|
490
|
+
description="related sections of documents that were most relevant to the inference prompt. "
|
|
491
|
+
"Formatted as a list of retrieved context chunks which include document name, seq num, and context.",
|
|
492
|
+
)
|
|
493
|
+
llm_response: str = Field(
|
|
494
|
+
description="response from the LLM for the original user prompt",
|
|
495
|
+
)
|
|
496
|
+
prompt_results: List[ExternalRuleResult] = Field(
|
|
497
|
+
description="list of rule results for the user prompt",
|
|
498
|
+
)
|
|
499
|
+
response_results: List[ExternalRuleResult] = Field(
|
|
500
|
+
description="list of rule results for the llm response",
|
|
501
|
+
)
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
class TokenUsageCount(BaseModel):
|
|
505
|
+
inference: int = Field(description="Number of inference tokens sent to Arthur.")
|
|
506
|
+
eval_prompt: int = Field(
|
|
507
|
+
description="Number of Prompt tokens incurred by Arthur rules.",
|
|
508
|
+
)
|
|
509
|
+
eval_completion: int = Field(
|
|
510
|
+
description="Number of Completion tokens incurred by Arthur rules.",
|
|
511
|
+
)
|
|
512
|
+
user_input: int = Field(
|
|
513
|
+
description="Number of user input tokens sent to Arthur. This field is deprecated and will be removed in the future. Use inference instead.",
|
|
514
|
+
json_schema_extra={"deprecated": True},
|
|
515
|
+
)
|
|
516
|
+
prompt: int = Field(
|
|
517
|
+
description="Number of Prompt tokens incurred by Arthur rules. This field is deprecated and will be removed in the future. Use eval_prompt instead.",
|
|
518
|
+
json_schema_extra={"deprecated": True},
|
|
519
|
+
)
|
|
520
|
+
completion: int = Field(
|
|
521
|
+
description="Number of Completion tokens incurred by Arthur rules. This field is deprecated and will be removed in the future. Use eval_completion instead.",
|
|
522
|
+
json_schema_extra={"deprecated": True},
|
|
523
|
+
)
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
class TokenUsageResponse(BaseModel):
|
|
527
|
+
rule_type: Optional[str] = None
|
|
528
|
+
task_id: Optional[str] = None
|
|
529
|
+
count: TokenUsageCount
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
class ApiKeyResponse(BaseModel):
|
|
533
|
+
id: str = Field(description="ID of the key")
|
|
534
|
+
key: Optional[str] = Field(
|
|
535
|
+
description="The generated GenAI Engine API key. The key is displayed on key creation request only.",
|
|
536
|
+
default=None,
|
|
537
|
+
)
|
|
538
|
+
description: Optional[str] = Field(
|
|
539
|
+
description="Description of the API key",
|
|
540
|
+
default=None,
|
|
541
|
+
)
|
|
542
|
+
is_active: bool = Field(description="Status of the key.")
|
|
543
|
+
created_at: datetime = Field(description="Creation time of the key")
|
|
544
|
+
deactivated_at: Optional[datetime] = Field(
|
|
545
|
+
description="Deactivation time of the key",
|
|
546
|
+
default=None,
|
|
547
|
+
)
|
|
548
|
+
message: Optional[str] = Field(description="Optional Message", default=None)
|
|
549
|
+
roles: list[str] = Field(
|
|
550
|
+
description="Roles of the API key",
|
|
551
|
+
default=[],
|
|
552
|
+
)
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
class UserResponse(BaseModel):
|
|
556
|
+
id: str
|
|
557
|
+
email: str
|
|
558
|
+
first_name: Optional[str] = None
|
|
559
|
+
last_name: Optional[str] = None
|
|
560
|
+
roles: list[AuthUserRole]
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
class ConversationBaseResponse(BaseModel):
|
|
564
|
+
id: str
|
|
565
|
+
updated_at: datetime
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
class ConversationResponse(ConversationBaseResponse):
|
|
569
|
+
inferences: list[ExternalInference]
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
class HealthResponse(BaseModel):
|
|
573
|
+
message: str
|
|
574
|
+
build_version: Optional[str] = None
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
class ChatDefaultTaskResponse(BaseModel):
|
|
578
|
+
task_id: str
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
class MetricResultResponse(BaseModel):
|
|
582
|
+
id: str = Field(description="ID of the metric result")
|
|
583
|
+
metric_type: MetricType = Field(description="Type of the metric")
|
|
584
|
+
details: Optional[str] = Field(
|
|
585
|
+
description="JSON-serialized metric details",
|
|
586
|
+
default=None,
|
|
587
|
+
)
|
|
588
|
+
prompt_tokens: int = Field(description="Number of prompt tokens used")
|
|
589
|
+
completion_tokens: int = Field(description="Number of completion tokens used")
|
|
590
|
+
latency_ms: int = Field(description="Latency in milliseconds")
|
|
591
|
+
span_id: str = Field(description="ID of the span this result belongs to")
|
|
592
|
+
metric_id: str = Field(description="ID of the metric that generated this result")
|
|
593
|
+
created_at: datetime = Field(description="Time the result was created")
|
|
594
|
+
updated_at: datetime = Field(description="Time the result was last updated")
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
class SpanWithMetricsResponse(BaseModel):
|
|
598
|
+
id: str
|
|
599
|
+
trace_id: str
|
|
600
|
+
span_id: str
|
|
601
|
+
parent_span_id: Optional[str] = None
|
|
602
|
+
span_kind: Optional[str] = None
|
|
603
|
+
span_name: Optional[str] = None
|
|
604
|
+
start_time: datetime
|
|
605
|
+
end_time: datetime
|
|
606
|
+
task_id: Optional[str] = None
|
|
607
|
+
created_at: datetime
|
|
608
|
+
updated_at: datetime
|
|
609
|
+
raw_data: dict[str, Any]
|
|
610
|
+
# Span features for LLM spans (computed on-demand)
|
|
611
|
+
system_prompt: Optional[str] = None
|
|
612
|
+
user_query: Optional[str] = None
|
|
613
|
+
response: Optional[str] = None
|
|
614
|
+
context: Optional[List[dict[str, Any]]] = None
|
|
615
|
+
metric_results: list[MetricResultResponse] = Field(
|
|
616
|
+
description="List of metric results for this span",
|
|
617
|
+
default=[],
|
|
618
|
+
)
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
class NestedSpanWithMetricsResponse(BaseModel):
|
|
622
|
+
"""Nested span response with children for building span trees"""
|
|
623
|
+
|
|
624
|
+
id: str
|
|
625
|
+
trace_id: str
|
|
626
|
+
span_id: str
|
|
627
|
+
parent_span_id: Optional[str] = None
|
|
628
|
+
span_kind: Optional[str] = None
|
|
629
|
+
span_name: Optional[str] = None
|
|
630
|
+
start_time: datetime
|
|
631
|
+
end_time: datetime
|
|
632
|
+
task_id: Optional[str] = None
|
|
633
|
+
created_at: datetime
|
|
634
|
+
updated_at: datetime
|
|
635
|
+
raw_data: dict[str, Any]
|
|
636
|
+
# Span features for LLM spans (computed on-demand)
|
|
637
|
+
system_prompt: Optional[str] = None
|
|
638
|
+
user_query: Optional[str] = None
|
|
639
|
+
response: Optional[str] = None
|
|
640
|
+
context: Optional[List[dict[str, Any]]] = None
|
|
641
|
+
metric_results: list[MetricResultResponse] = Field(
|
|
642
|
+
description="List of metric results for this span",
|
|
643
|
+
default=[],
|
|
644
|
+
)
|
|
645
|
+
children: list["NestedSpanWithMetricsResponse"] = Field(
|
|
646
|
+
description="Child spans nested under this span",
|
|
647
|
+
default=[],
|
|
648
|
+
)
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
class TraceResponse(BaseModel):
|
|
652
|
+
"""Response model for a single trace containing nested spans"""
|
|
653
|
+
|
|
654
|
+
trace_id: str = Field(description="ID of the trace")
|
|
655
|
+
start_time: datetime = Field(
|
|
656
|
+
description="Start time of the earliest span in this trace",
|
|
657
|
+
)
|
|
658
|
+
end_time: datetime = Field(description="End time of the latest span in this trace")
|
|
659
|
+
root_spans: list[NestedSpanWithMetricsResponse] = Field(
|
|
660
|
+
description="Root spans (spans with no parent) in this trace, with children nested",
|
|
661
|
+
default=[],
|
|
662
|
+
)
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
class QueryTracesWithMetricsResponse(BaseModel):
|
|
666
|
+
"""New response format that groups spans into traces with nested structure"""
|
|
667
|
+
|
|
668
|
+
count: int = Field(
|
|
669
|
+
description="The total number of spans matching the query parameters",
|
|
670
|
+
)
|
|
671
|
+
traces: list[TraceResponse] = Field(
|
|
672
|
+
description="List of traces containing nested spans matching the search filters",
|
|
673
|
+
)
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
class QuerySpansResponse(BaseModel):
|
|
677
|
+
count: int = Field(
|
|
678
|
+
description="The total number of spans matching the query parameters",
|
|
679
|
+
)
|
|
680
|
+
spans: list[SpanWithMetricsResponse] = Field(
|
|
681
|
+
description="List of spans with metrics matching the search filters",
|
|
682
|
+
)
|
|
@@ -6,7 +6,7 @@ from uuid import UUID, uuid4
|
|
|
6
6
|
|
|
7
7
|
from pydantic import BaseModel, ConfigDict, Field, computed_field, model_validator
|
|
8
8
|
|
|
9
|
-
from arthur_common.models.
|
|
9
|
+
from arthur_common.models.enums import ModelProblemType
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class ScopeSchemaTag(str, Enum):
|