-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.py
More file actions
1400 lines (1146 loc) · 48.5 KB
/
client.py
File metadata and controls
1400 lines (1146 loc) · 48.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This file was auto-generated by Fern from our API Definition.
import datetime as dt
import typing
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.pagination import AsyncPager, SyncPager
from ..core.request_options import RequestOptions
from ..requests.chat_message import ChatMessageParams
from ..requests.evaluator_activation_deactivation_request_activate_item import (
EvaluatorActivationDeactivationRequestActivateItemParams,
)
from ..requests.evaluator_activation_deactivation_request_deactivate_item import (
EvaluatorActivationDeactivationRequestDeactivateItemParams,
)
from ..types.create_evaluator_log_response import CreateEvaluatorLogResponse
from ..types.evaluator_response import EvaluatorResponse
from ..types.file_environment_response import FileEnvironmentResponse
from ..types.file_sort_by import FileSortBy
from ..types.list_evaluators import ListEvaluators
from ..types.sort_order import SortOrder
from .raw_client import AsyncRawEvaluatorsClient, RawEvaluatorsClient
from .requests.create_evaluator_log_request_judgment import CreateEvaluatorLogRequestJudgmentParams
from .requests.create_evaluator_log_request_spec import CreateEvaluatorLogRequestSpecParams
from .requests.evaluator_request_spec import EvaluatorRequestSpecParams
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)
class EvaluatorsClient:
def __init__(self, *, client_wrapper: SyncClientWrapper):
self._raw_client = RawEvaluatorsClient(client_wrapper=client_wrapper)
@property
def with_raw_response(self) -> RawEvaluatorsClient:
"""
Retrieves a raw implementation of this client that returns raw responses.
Returns
-------
RawEvaluatorsClient
"""
return self._raw_client
def log(
self,
*,
parent_id: str,
version_id: typing.Optional[str] = None,
environment: typing.Optional[str] = None,
path: typing.Optional[str] = OMIT,
id: typing.Optional[str] = OMIT,
start_time: typing.Optional[dt.datetime] = OMIT,
end_time: typing.Optional[dt.datetime] = OMIT,
output: typing.Optional[str] = OMIT,
created_at: typing.Optional[dt.datetime] = OMIT,
error: typing.Optional[str] = OMIT,
provider_latency: typing.Optional[float] = OMIT,
stdout: typing.Optional[str] = OMIT,
provider_request: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
provider_response: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
inputs: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
source: typing.Optional[str] = OMIT,
metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
source_datapoint_id: typing.Optional[str] = OMIT,
trace_parent_id: typing.Optional[str] = OMIT,
user: typing.Optional[str] = OMIT,
create_evaluator_log_request_environment: typing.Optional[str] = OMIT,
save: typing.Optional[bool] = OMIT,
log_id: typing.Optional[str] = OMIT,
output_message: typing.Optional[ChatMessageParams] = OMIT,
judgment: typing.Optional[CreateEvaluatorLogRequestJudgmentParams] = OMIT,
marked_completed: typing.Optional[bool] = OMIT,
spec: typing.Optional[CreateEvaluatorLogRequestSpecParams] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> CreateEvaluatorLogResponse:
"""
Submit Evaluator judgment for an existing Log.
Creates a new Log. The evaluated Log will be set as the parent of the created Log.
Parameters
----------
parent_id : str
Identifier of the evaluated Log. The newly created Log will have this one set as parent.
version_id : typing.Optional[str]
ID of the Evaluator version to log against.
environment : typing.Optional[str]
Name of the Environment identifying a deployed version to log to.
path : typing.Optional[str]
Path of the Evaluator, including the name. This locates the Evaluator in the Humanloop filesystem and is used as as a unique identifier. For example: `folder/name` or just `name`.
id : typing.Optional[str]
ID for an existing Evaluator.
start_time : typing.Optional[dt.datetime]
When the logged event started.
end_time : typing.Optional[dt.datetime]
When the logged event ended.
output : typing.Optional[str]
Generated output from the LLM. Only populated for LLM Evaluator Logs.
created_at : typing.Optional[dt.datetime]
User defined timestamp for when the log was created.
error : typing.Optional[str]
Error message if the log is an error.
provider_latency : typing.Optional[float]
Duration of the logged event in seconds.
stdout : typing.Optional[str]
Captured log and debug statements.
provider_request : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
Raw request sent to provider. Only populated for LLM Evaluator Logs.
provider_response : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
Raw response received the provider. Only populated for LLM Evaluator Logs.
inputs : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
The inputs passed to the prompt template.
source : typing.Optional[str]
Identifies where the model was called from.
metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
Any additional metadata to record.
source_datapoint_id : typing.Optional[str]
Unique identifier for the Datapoint that this Log is derived from. This can be used by Humanloop to associate Logs to Evaluations. If provided, Humanloop will automatically associate this Log to Evaluations that require a Log for this Datapoint-Version pair.
trace_parent_id : typing.Optional[str]
The ID of the parent Log to nest this Log under in a Trace.
user : typing.Optional[str]
End-user ID related to the Log.
create_evaluator_log_request_environment : typing.Optional[str]
The name of the Environment the Log is associated to.
save : typing.Optional[bool]
Whether the request/response payloads will be stored on Humanloop.
log_id : typing.Optional[str]
This will identify a Log. If you don't provide a Log ID, Humanloop will generate one for you.
output_message : typing.Optional[ChatMessageParams]
The message returned by the LLM. Only populated for LLM Evaluator Logs.
judgment : typing.Optional[CreateEvaluatorLogRequestJudgmentParams]
Evaluator assessment of the Log.
marked_completed : typing.Optional[bool]
Whether the Log has been manually marked as completed by a user.
spec : typing.Optional[CreateEvaluatorLogRequestSpecParams]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
CreateEvaluatorLogResponse
Successful Response
Examples
--------
from humanloop import Humanloop
client = Humanloop(api_key="YOUR_API_KEY", )
client.evaluators.log(parent_id='parent_id', )
"""
_response = self._raw_client.log(
parent_id=parent_id,
version_id=version_id,
environment=environment,
path=path,
id=id,
start_time=start_time,
end_time=end_time,
output=output,
created_at=created_at,
error=error,
provider_latency=provider_latency,
stdout=stdout,
provider_request=provider_request,
provider_response=provider_response,
inputs=inputs,
source=source,
metadata=metadata,
source_datapoint_id=source_datapoint_id,
trace_parent_id=trace_parent_id,
user=user,
create_evaluator_log_request_environment=create_evaluator_log_request_environment,
save=save,
log_id=log_id,
output_message=output_message,
judgment=judgment,
marked_completed=marked_completed,
spec=spec,
request_options=request_options,
)
return _response.data
def list(
self,
*,
page: typing.Optional[int] = None,
size: typing.Optional[int] = None,
name: typing.Optional[str] = None,
user_filter: typing.Optional[str] = None,
sort_by: typing.Optional[FileSortBy] = None,
order: typing.Optional[SortOrder] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> SyncPager[EvaluatorResponse]:
"""
Get a list of all Evaluators.
Parameters
----------
page : typing.Optional[int]
Page offset for pagination.
size : typing.Optional[int]
Page size for pagination. Number of Evaluators to fetch.
name : typing.Optional[str]
Case-insensitive filter for Evaluator name.
user_filter : typing.Optional[str]
Case-insensitive filter for users in the Evaluator. This filter matches against both email address and name of users.
sort_by : typing.Optional[FileSortBy]
Field to sort Evaluators by
order : typing.Optional[SortOrder]
Direction to sort by.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
SyncPager[EvaluatorResponse]
Successful Response
Examples
--------
from humanloop import Humanloop
client = Humanloop(api_key="YOUR_API_KEY", )
response = client.evaluators.list(size=1, )
for item in response:
yield item
# alternatively, you can paginate page-by-page
for page in response.iter_pages():
yield page
"""
return self._raw_client.list(
page=page,
size=size,
name=name,
user_filter=user_filter,
sort_by=sort_by,
order=order,
request_options=request_options,
)
def upsert(
self,
*,
spec: EvaluatorRequestSpecParams,
path: typing.Optional[str] = OMIT,
id: typing.Optional[str] = OMIT,
version_name: typing.Optional[str] = OMIT,
version_description: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> EvaluatorResponse:
"""
Create an Evaluator or update it with a new version if it already exists.
Evaluators are identified by the `ID` or their `path`. The spec provided determines the version of the Evaluator.
You can provide `version_name` and `version_description` to identify and describe your versions.
Version names must be unique within an Evaluator - attempting to create a version with a name
that already exists will result in a 409 Conflict error.
Parameters
----------
spec : EvaluatorRequestSpecParams
path : typing.Optional[str]
Path of the Evaluator, including the name. This locates the Evaluator in the Humanloop filesystem and is used as as a unique identifier. For example: `folder/name` or just `name`.
id : typing.Optional[str]
ID for an existing Evaluator.
version_name : typing.Optional[str]
Unique name for the Evaluator version. Version names must be unique for a given Evaluator.
version_description : typing.Optional[str]
Description of the version, e.g., the changes made in this version.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
EvaluatorResponse
Successful Response
Examples
--------
from humanloop import Humanloop
client = Humanloop(api_key="YOUR_API_KEY", )
client.evaluators.upsert(path='Shared Evaluators/Accuracy Evaluator', spec={'arguments_type': "target_required", 'return_type': "number", 'evaluator_type': 'python', 'code': 'def evaluate(answer, target):\n return 0.5'}, version_name='simple-evaluator', version_description='Simple evaluator that returns 0.5', )
"""
_response = self._raw_client.upsert(
spec=spec,
path=path,
id=id,
version_name=version_name,
version_description=version_description,
request_options=request_options,
)
return _response.data
def get(
self,
id: str,
*,
version_id: typing.Optional[str] = None,
environment: typing.Optional[str] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> EvaluatorResponse:
"""
Retrieve the Evaluator with the given ID.
By default, the deployed version of the Evaluator is returned. Use the query parameters
`version_id` or `environment` to target a specific version of the Evaluator.
Parameters
----------
id : str
Unique identifier for Evaluator.
version_id : typing.Optional[str]
A specific Version ID of the Evaluator to retrieve.
environment : typing.Optional[str]
Name of the Environment to retrieve a deployed Version from.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
EvaluatorResponse
Successful Response
Examples
--------
from humanloop import Humanloop
client = Humanloop(api_key="YOUR_API_KEY", )
client.evaluators.get(id='ev_890bcd', )
"""
_response = self._raw_client.get(
id, version_id=version_id, environment=environment, request_options=request_options
)
return _response.data
def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
"""
Delete the Evaluator with the given ID.
Parameters
----------
id : str
Unique identifier for Evaluator.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
None
Examples
--------
from humanloop import Humanloop
client = Humanloop(api_key="YOUR_API_KEY", )
client.evaluators.delete(id='ev_890bcd', )
"""
_response = self._raw_client.delete(id, request_options=request_options)
return _response.data
def move(
self,
id: str,
*,
path: typing.Optional[str] = OMIT,
name: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> EvaluatorResponse:
"""
Move the Evaluator to a different path or change the name.
Parameters
----------
id : str
Unique identifier for Evaluator.
path : typing.Optional[str]
Path of the Evaluator including the Evaluator name, which is used as a unique identifier.
name : typing.Optional[str]
Name of the Evaluator, which is used as a unique identifier.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
EvaluatorResponse
Successful Response
Examples
--------
from humanloop import Humanloop
client = Humanloop(api_key="YOUR_API_KEY", )
client.evaluators.move(id='ev_890bcd', path='new directory/new name', )
"""
_response = self._raw_client.move(id, path=path, name=name, request_options=request_options)
return _response.data
def list_versions(
self,
id: str,
*,
evaluator_aggregates: typing.Optional[bool] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> ListEvaluators:
"""
Get a list of all the versions of an Evaluator.
Parameters
----------
id : str
Unique identifier for the Evaluator.
evaluator_aggregates : typing.Optional[bool]
Whether to include Evaluator aggregate results for the versions in the response
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
ListEvaluators
Successful Response
Examples
--------
from humanloop import Humanloop
client = Humanloop(api_key="YOUR_API_KEY", )
client.evaluators.list_versions(id='ev_890bcd', )
"""
_response = self._raw_client.list_versions(
id, evaluator_aggregates=evaluator_aggregates, request_options=request_options
)
return _response.data
def delete_evaluator_version(
self, id: str, version_id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> None:
"""
Delete a version of the Evaluator.
Parameters
----------
id : str
Unique identifier for Evaluator.
version_id : str
Unique identifier for the specific version of the Evaluator.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
None
Examples
--------
from humanloop import Humanloop
client = Humanloop(api_key="YOUR_API_KEY", )
client.evaluators.delete_evaluator_version(id='id', version_id='version_id', )
"""
_response = self._raw_client.delete_evaluator_version(id, version_id, request_options=request_options)
return _response.data
def update_evaluator_version(
self,
id: str,
version_id: str,
*,
name: typing.Optional[str] = OMIT,
description: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> EvaluatorResponse:
"""
Update the name or description of the Evaluator version.
Parameters
----------
id : str
Unique identifier for Evaluator.
version_id : str
Unique identifier for the specific version of the Evaluator.
name : typing.Optional[str]
Name of the version.
description : typing.Optional[str]
Description of the version.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
EvaluatorResponse
Successful Response
Examples
--------
from humanloop import Humanloop
client = Humanloop(api_key="YOUR_API_KEY", )
client.evaluators.update_evaluator_version(id='id', version_id='version_id', )
"""
_response = self._raw_client.update_evaluator_version(
id, version_id, name=name, description=description, request_options=request_options
)
return _response.data
def set_deployment(
self, id: str, environment_id: str, *, version_id: str, request_options: typing.Optional[RequestOptions] = None
) -> EvaluatorResponse:
"""
Deploy Evaluator to an Environment.
Set the deployed version for the specified Environment. This Evaluator
will be used for calls made to the Evaluator in this Environment.
Parameters
----------
id : str
Unique identifier for Evaluator.
environment_id : str
Unique identifier for the Environment to deploy the Version to.
version_id : str
Unique identifier for the specific version of the Evaluator.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
EvaluatorResponse
Successful Response
Examples
--------
from humanloop import Humanloop
client = Humanloop(api_key="YOUR_API_KEY", )
client.evaluators.set_deployment(id='ev_890bcd', environment_id='staging', version_id='evv_012def', )
"""
_response = self._raw_client.set_deployment(
id, environment_id, version_id=version_id, request_options=request_options
)
return _response.data
def remove_deployment(
self, id: str, environment_id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> None:
"""
Remove deployed Evaluator from the Environment.
Remove the deployed version for the specified Environment. This Evaluator
will no longer be used for calls made to the Evaluator in this Environment.
Parameters
----------
id : str
Unique identifier for Evaluator.
environment_id : str
Unique identifier for the Environment to remove the deployment from.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
None
Examples
--------
from humanloop import Humanloop
client = Humanloop(api_key="YOUR_API_KEY", )
client.evaluators.remove_deployment(id='ev_890bcd', environment_id='staging', )
"""
_response = self._raw_client.remove_deployment(id, environment_id, request_options=request_options)
return _response.data
def list_environments(
self, id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> typing.List[FileEnvironmentResponse]:
"""
List all Environments and their deployed versions for the Evaluator.
Parameters
----------
id : str
Unique identifier for Evaluator.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
typing.List[FileEnvironmentResponse]
Successful Response
Examples
--------
from humanloop import Humanloop
client = Humanloop(api_key="YOUR_API_KEY", )
client.evaluators.list_environments(id='ev_890bcd', )
"""
_response = self._raw_client.list_environments(id, request_options=request_options)
return _response.data
def update_monitoring(
self,
id: str,
*,
activate: typing.Optional[typing.Sequence[EvaluatorActivationDeactivationRequestActivateItemParams]] = OMIT,
deactivate: typing.Optional[typing.Sequence[EvaluatorActivationDeactivationRequestDeactivateItemParams]] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> EvaluatorResponse:
"""
Activate and deactivate Evaluators for monitoring the Evaluator.
An activated Evaluator will automatically be run on all new Logs
within the Evaluator for monitoring purposes.
Parameters
----------
id : str
activate : typing.Optional[typing.Sequence[EvaluatorActivationDeactivationRequestActivateItemParams]]
Evaluators to activate for Monitoring. These will be automatically run on new Logs.
deactivate : typing.Optional[typing.Sequence[EvaluatorActivationDeactivationRequestDeactivateItemParams]]
Evaluators to deactivate. These will not be run on new Logs.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
EvaluatorResponse
Successful Response
Examples
--------
from humanloop import Humanloop
client = Humanloop(api_key="YOUR_API_KEY", )
client.evaluators.update_monitoring(id='id', )
"""
_response = self._raw_client.update_monitoring(
id, activate=activate, deactivate=deactivate, request_options=request_options
)
return _response.data
class AsyncEvaluatorsClient:
def __init__(self, *, client_wrapper: AsyncClientWrapper):
self._raw_client = AsyncRawEvaluatorsClient(client_wrapper=client_wrapper)
@property
def with_raw_response(self) -> AsyncRawEvaluatorsClient:
"""
Retrieves a raw implementation of this client that returns raw responses.
Returns
-------
AsyncRawEvaluatorsClient
"""
return self._raw_client
async def log(
self,
*,
parent_id: str,
version_id: typing.Optional[str] = None,
environment: typing.Optional[str] = None,
path: typing.Optional[str] = OMIT,
id: typing.Optional[str] = OMIT,
start_time: typing.Optional[dt.datetime] = OMIT,
end_time: typing.Optional[dt.datetime] = OMIT,
output: typing.Optional[str] = OMIT,
created_at: typing.Optional[dt.datetime] = OMIT,
error: typing.Optional[str] = OMIT,
provider_latency: typing.Optional[float] = OMIT,
stdout: typing.Optional[str] = OMIT,
provider_request: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
provider_response: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
inputs: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
source: typing.Optional[str] = OMIT,
metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
source_datapoint_id: typing.Optional[str] = OMIT,
trace_parent_id: typing.Optional[str] = OMIT,
user: typing.Optional[str] = OMIT,
create_evaluator_log_request_environment: typing.Optional[str] = OMIT,
save: typing.Optional[bool] = OMIT,
log_id: typing.Optional[str] = OMIT,
output_message: typing.Optional[ChatMessageParams] = OMIT,
judgment: typing.Optional[CreateEvaluatorLogRequestJudgmentParams] = OMIT,
marked_completed: typing.Optional[bool] = OMIT,
spec: typing.Optional[CreateEvaluatorLogRequestSpecParams] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> CreateEvaluatorLogResponse:
"""
Submit Evaluator judgment for an existing Log.
Creates a new Log. The evaluated Log will be set as the parent of the created Log.
Parameters
----------
parent_id : str
Identifier of the evaluated Log. The newly created Log will have this one set as parent.
version_id : typing.Optional[str]
ID of the Evaluator version to log against.
environment : typing.Optional[str]
Name of the Environment identifying a deployed version to log to.
path : typing.Optional[str]
Path of the Evaluator, including the name. This locates the Evaluator in the Humanloop filesystem and is used as as a unique identifier. For example: `folder/name` or just `name`.
id : typing.Optional[str]
ID for an existing Evaluator.
start_time : typing.Optional[dt.datetime]
When the logged event started.
end_time : typing.Optional[dt.datetime]
When the logged event ended.
output : typing.Optional[str]
Generated output from the LLM. Only populated for LLM Evaluator Logs.
created_at : typing.Optional[dt.datetime]
User defined timestamp for when the log was created.
error : typing.Optional[str]
Error message if the log is an error.
provider_latency : typing.Optional[float]
Duration of the logged event in seconds.
stdout : typing.Optional[str]
Captured log and debug statements.
provider_request : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
Raw request sent to provider. Only populated for LLM Evaluator Logs.
provider_response : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
Raw response received the provider. Only populated for LLM Evaluator Logs.
inputs : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
The inputs passed to the prompt template.
source : typing.Optional[str]
Identifies where the model was called from.
metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
Any additional metadata to record.
source_datapoint_id : typing.Optional[str]
Unique identifier for the Datapoint that this Log is derived from. This can be used by Humanloop to associate Logs to Evaluations. If provided, Humanloop will automatically associate this Log to Evaluations that require a Log for this Datapoint-Version pair.
trace_parent_id : typing.Optional[str]
The ID of the parent Log to nest this Log under in a Trace.
user : typing.Optional[str]
End-user ID related to the Log.
create_evaluator_log_request_environment : typing.Optional[str]
The name of the Environment the Log is associated to.
save : typing.Optional[bool]
Whether the request/response payloads will be stored on Humanloop.
log_id : typing.Optional[str]
This will identify a Log. If you don't provide a Log ID, Humanloop will generate one for you.
output_message : typing.Optional[ChatMessageParams]
The message returned by the LLM. Only populated for LLM Evaluator Logs.
judgment : typing.Optional[CreateEvaluatorLogRequestJudgmentParams]
Evaluator assessment of the Log.
marked_completed : typing.Optional[bool]
Whether the Log has been manually marked as completed by a user.
spec : typing.Optional[CreateEvaluatorLogRequestSpecParams]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
CreateEvaluatorLogResponse
Successful Response
Examples
--------
from humanloop import AsyncHumanloop
import asyncio
client = AsyncHumanloop(api_key="YOUR_API_KEY", )
async def main() -> None:
await client.evaluators.log(parent_id='parent_id', )
asyncio.run(main())
"""
_response = await self._raw_client.log(
parent_id=parent_id,
version_id=version_id,
environment=environment,
path=path,
id=id,
start_time=start_time,
end_time=end_time,
output=output,
created_at=created_at,
error=error,
provider_latency=provider_latency,
stdout=stdout,
provider_request=provider_request,
provider_response=provider_response,
inputs=inputs,
source=source,
metadata=metadata,
source_datapoint_id=source_datapoint_id,
trace_parent_id=trace_parent_id,
user=user,
create_evaluator_log_request_environment=create_evaluator_log_request_environment,
save=save,
log_id=log_id,
output_message=output_message,
judgment=judgment,
marked_completed=marked_completed,
spec=spec,
request_options=request_options,
)
return _response.data
async def list(
self,
*,
page: typing.Optional[int] = None,
size: typing.Optional[int] = None,
name: typing.Optional[str] = None,
user_filter: typing.Optional[str] = None,
sort_by: typing.Optional[FileSortBy] = None,
order: typing.Optional[SortOrder] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> AsyncPager[EvaluatorResponse]:
"""
Get a list of all Evaluators.
Parameters
----------
page : typing.Optional[int]
Page offset for pagination.
size : typing.Optional[int]
Page size for pagination. Number of Evaluators to fetch.
name : typing.Optional[str]
Case-insensitive filter for Evaluator name.
user_filter : typing.Optional[str]
Case-insensitive filter for users in the Evaluator. This filter matches against both email address and name of users.
sort_by : typing.Optional[FileSortBy]
Field to sort Evaluators by
order : typing.Optional[SortOrder]
Direction to sort by.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AsyncPager[EvaluatorResponse]
Successful Response
Examples
--------
from humanloop import AsyncHumanloop
import asyncio
client = AsyncHumanloop(api_key="YOUR_API_KEY", )
async def main() -> None:
response = await client.evaluators.list(size=1, )
async for item in response:
yield item
# alternatively, you can paginate page-by-page
async for page in response.iter_pages():
yield page
asyncio.run(main())
"""
return await self._raw_client.list(
page=page,
size=size,
name=name,
user_filter=user_filter,
sort_by=sort_by,
order=order,
request_options=request_options,
)
async def upsert(
self,
*,
spec: EvaluatorRequestSpecParams,
path: typing.Optional[str] = OMIT,
id: typing.Optional[str] = OMIT,
version_name: typing.Optional[str] = OMIT,
version_description: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> EvaluatorResponse:
"""
Create an Evaluator or update it with a new version if it already exists.
Evaluators are identified by the `ID` or their `path`. The spec provided determines the version of the Evaluator.
You can provide `version_name` and `version_description` to identify and describe your versions.
Version names must be unique within an Evaluator - attempting to create a version with a name
that already exists will result in a 409 Conflict error.
Parameters
----------
spec : EvaluatorRequestSpecParams
path : typing.Optional[str]
Path of the Evaluator, including the name. This locates the Evaluator in the Humanloop filesystem and is used as as a unique identifier. For example: `folder/name` or just `name`.
id : typing.Optional[str]
ID for an existing Evaluator.
version_name : typing.Optional[str]
Unique name for the Evaluator version. Version names must be unique for a given Evaluator.
version_description : typing.Optional[str]
Description of the version, e.g., the changes made in this version.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
EvaluatorResponse
Successful Response
Examples
--------
from humanloop import AsyncHumanloop
import asyncio
client = AsyncHumanloop(api_key="YOUR_API_KEY", )
async def main() -> None:
await client.evaluators.upsert(path='Shared Evaluators/Accuracy Evaluator', spec={'arguments_type': "target_required", 'return_type': "number", 'evaluator_type': 'python', 'code': 'def evaluate(answer, target):\n return 0.5'}, version_name='simple-evaluator', version_description='Simple evaluator that returns 0.5', )
asyncio.run(main())
"""
_response = await self._raw_client.upsert(
spec=spec,