freeplay 0.3.0a9__py3-none-any.whl → 0.3.0a11__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.
- freeplay/__init__.py +2 -1
- freeplay/api_support.py +7 -0
- freeplay/freeplay.py +1 -1
- freeplay/resources/recordings.py +7 -1
- freeplay/resources/sessions.py +63 -3
- freeplay/support.py +22 -2
- {freeplay-0.3.0a9.dist-info → freeplay-0.3.0a11.dist-info}/METADATA +1 -1
- freeplay-0.3.0a11.dist-info/RECORD +21 -0
- {freeplay-0.3.0a9.dist-info → freeplay-0.3.0a11.dist-info}/WHEEL +1 -1
- freeplay-0.3.0a9.dist-info/RECORD +0 -21
- {freeplay-0.3.0a9.dist-info → freeplay-0.3.0a11.dist-info}/LICENSE +0 -0
- {freeplay-0.3.0a9.dist-info → freeplay-0.3.0a11.dist-info}/entry_points.txt +0 -0
freeplay/__init__.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
from .freeplay import Freeplay
|
2
2
|
from .resources.prompts import PromptInfo
|
3
3
|
from .resources.recordings import CallInfo, ResponseInfo, RecordPayload, TestRunInfo
|
4
|
-
from .resources.sessions import SessionInfo
|
4
|
+
from .resources.sessions import SessionInfo, TraceInfo
|
5
5
|
|
6
6
|
__all__ = [
|
7
7
|
'CallInfo',
|
@@ -11,4 +11,5 @@ __all__ = [
|
|
11
11
|
'ResponseInfo',
|
12
12
|
'SessionInfo',
|
13
13
|
'TestRunInfo',
|
14
|
+
'TraceInfo',
|
14
15
|
]
|
freeplay/api_support.py
CHANGED
@@ -60,6 +60,13 @@ def post_raw(api_key: str, url: str, payload: t.Optional[Dict[str, t.Any]] = Non
|
|
60
60
|
)
|
61
61
|
|
62
62
|
|
63
|
+
def delete_raw(api_key: str, url: str) -> Response:
|
64
|
+
return requests.delete(
|
65
|
+
url=url,
|
66
|
+
headers=build_request_header(api_key),
|
67
|
+
)
|
68
|
+
|
69
|
+
|
63
70
|
def get(target_type: t.Type[T], api_key: str, url: str) -> T:
|
64
71
|
response = requests.get(
|
65
72
|
url=url,
|
freeplay/freeplay.py
CHANGED
@@ -36,5 +36,5 @@ class Freeplay:
|
|
36
36
|
self.customer_feedback = CustomerFeedback(self.call_support)
|
37
37
|
self.prompts = Prompts(self.call_support, resolver)
|
38
38
|
self.recordings = Recordings(self.call_support)
|
39
|
-
self.sessions = Sessions()
|
39
|
+
self.sessions = Sessions(self.call_support)
|
40
40
|
self.test_runs = TestRuns(self.call_support)
|
freeplay/resources/recordings.py
CHANGED
@@ -10,7 +10,7 @@ from freeplay.errors import FreeplayClientError, FreeplayError
|
|
10
10
|
from freeplay.llm_parameters import LLMParameters
|
11
11
|
from freeplay.model import InputVariables, OpenAIFunctionCall
|
12
12
|
from freeplay.resources.prompts import PromptInfo
|
13
|
-
from freeplay.resources.sessions import SessionInfo
|
13
|
+
from freeplay.resources.sessions import SessionInfo, TraceInfo
|
14
14
|
from freeplay.support import CallSupport
|
15
15
|
|
16
16
|
logger = logging.getLogger(__name__)
|
@@ -62,6 +62,7 @@ class RecordPayload:
|
|
62
62
|
response_info: Optional[ResponseInfo] = None
|
63
63
|
test_run_info: Optional[TestRunInfo] = None
|
64
64
|
eval_results: Optional[Dict[str, Union[bool, float]]] = None
|
65
|
+
trace_info: Optional[TraceInfo] = None
|
65
66
|
|
66
67
|
|
67
68
|
@dataclass
|
@@ -117,6 +118,11 @@ class Recordings:
|
|
117
118
|
if record_payload.eval_results is not None:
|
118
119
|
record_api_payload['eval_results'] = record_payload.eval_results
|
119
120
|
|
121
|
+
if record_payload.trace_info is not None:
|
122
|
+
record_api_payload['trace_info'] = {
|
123
|
+
"trace_id": record_payload.trace_info.trace_id
|
124
|
+
}
|
125
|
+
|
120
126
|
try:
|
121
127
|
recorded_response = api_support.post_raw(
|
122
128
|
api_key=self.call_support.freeplay_api_key,
|
freeplay/resources/sessions.py
CHANGED
@@ -2,6 +2,9 @@ import uuid
|
|
2
2
|
from dataclasses import dataclass
|
3
3
|
from typing import Optional, Dict, Union
|
4
4
|
|
5
|
+
from freeplay.errors import FreeplayClientError
|
6
|
+
from freeplay.support import CallSupport
|
7
|
+
|
5
8
|
CustomMetadata = Optional[Dict[str, Union[str, int, float]]]
|
6
9
|
|
7
10
|
|
@@ -11,22 +14,79 @@ class SessionInfo:
|
|
11
14
|
custom_metadata: CustomMetadata
|
12
15
|
|
13
16
|
|
17
|
+
class TraceInfo:
|
18
|
+
session_id: str
|
19
|
+
trace_id: str
|
20
|
+
input: Optional[str] = None
|
21
|
+
_call_support: CallSupport
|
22
|
+
|
23
|
+
def __init__(
|
24
|
+
self,
|
25
|
+
trace_id: str,
|
26
|
+
session_id: str,
|
27
|
+
_call_support: CallSupport,
|
28
|
+
input: Optional[str] = None,
|
29
|
+
):
|
30
|
+
self.trace_id = trace_id
|
31
|
+
self.session_id = session_id
|
32
|
+
self.input = input
|
33
|
+
self._call_support = _call_support
|
34
|
+
|
35
|
+
def record_output(self, project_id: str, output: str) -> None:
|
36
|
+
if self.input is None:
|
37
|
+
raise FreeplayClientError("Input must be set before recording output")
|
38
|
+
self._call_support.record_trace(project_id, self.session_id, self.trace_id, self.input, output)
|
39
|
+
|
40
|
+
|
14
41
|
@dataclass
|
15
42
|
class Session:
|
16
43
|
session_id: str
|
17
44
|
custom_metadata: CustomMetadata
|
18
45
|
|
19
|
-
def __init__(self, session_id: str, custom_metadata: CustomMetadata):
|
46
|
+
def __init__(self, session_id: str, custom_metadata: CustomMetadata, _call_support: CallSupport):
|
20
47
|
self.session_id = session_id
|
21
48
|
self.custom_metadata = custom_metadata
|
22
49
|
self._session_info = SessionInfo(self.session_id, self.custom_metadata)
|
50
|
+
self._call_support = _call_support
|
23
51
|
|
24
52
|
@property
|
25
53
|
def session_info(self) -> SessionInfo:
|
26
54
|
return self._session_info
|
27
55
|
|
56
|
+
def create_trace(self, input: str) -> TraceInfo:
|
57
|
+
return TraceInfo(
|
58
|
+
trace_id=str(uuid.uuid4()),
|
59
|
+
session_id=self.session_id,
|
60
|
+
input=input,
|
61
|
+
_call_support=self._call_support
|
62
|
+
)
|
63
|
+
|
64
|
+
def restore_trace(self, trace_id: uuid.UUID, input: Optional[str]) -> TraceInfo:
|
65
|
+
return TraceInfo(
|
66
|
+
trace_id=str(trace_id),
|
67
|
+
session_id=self.session_id,
|
68
|
+
input=input,
|
69
|
+
_call_support=self._call_support
|
70
|
+
)
|
71
|
+
|
28
72
|
|
29
73
|
class Sessions:
|
30
|
-
|
74
|
+
def __init__(self, call_support: CallSupport):
|
75
|
+
self.call_support = call_support
|
76
|
+
|
31
77
|
def create(self, custom_metadata: CustomMetadata = None) -> Session:
|
32
|
-
return Session(
|
78
|
+
return Session(
|
79
|
+
session_id=str(uuid.uuid4()),
|
80
|
+
custom_metadata=custom_metadata,
|
81
|
+
_call_support=self.call_support,
|
82
|
+
)
|
83
|
+
|
84
|
+
def delete(self, project_id: str, session_id: str) -> None:
|
85
|
+
self.call_support.delete_session(project_id, session_id)
|
86
|
+
|
87
|
+
def restore_session(self, session_id: str, custom_metadata: CustomMetadata = None) -> Session:
|
88
|
+
return Session(
|
89
|
+
session_id=session_id,
|
90
|
+
custom_metadata=custom_metadata,
|
91
|
+
_call_support=self.call_support,
|
92
|
+
)
|
freeplay/support.py
CHANGED
@@ -177,8 +177,8 @@ class CallSupport:
|
|
177
177
|
payload={
|
178
178
|
'dataset_name': testlist,
|
179
179
|
'include_test_case_outputs': include_test_case_outputs,
|
180
|
-
'
|
181
|
-
'
|
180
|
+
'test_run_name': name,
|
181
|
+
'test_run_description': description
|
182
182
|
},
|
183
183
|
)
|
184
184
|
|
@@ -210,3 +210,23 @@ class CallSupport:
|
|
210
210
|
summary_statistics=json_dom['summary_statistics']
|
211
211
|
)
|
212
212
|
|
213
|
+
def record_trace(self, project_id: str, session_id: str, trace_id: str, input: str, output: str) -> None:
|
214
|
+
response = api_support.post_raw(
|
215
|
+
self.freeplay_api_key,
|
216
|
+
f'{self.api_base}/v2/projects/{project_id}/sessions/{session_id}/traces/id/{trace_id}',
|
217
|
+
{
|
218
|
+
'input': input,
|
219
|
+
'output': output
|
220
|
+
}
|
221
|
+
)
|
222
|
+
if response.status_code != 201:
|
223
|
+
raise freeplay_response_error('Error while recording trace.', response)
|
224
|
+
|
225
|
+
def delete_session(self, project_id: str, session_id: str) -> None:
|
226
|
+
response = api_support.delete_raw(
|
227
|
+
self.freeplay_api_key,
|
228
|
+
f'{self.api_base}/v2/projects/{project_id}/sessions/{session_id}'
|
229
|
+
)
|
230
|
+
if response.status_code != 201:
|
231
|
+
raise freeplay_response_error('Error while deleting session.', response)
|
232
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
freeplay/__init__.py,sha256=oseuUqIVAi-2a_ns4ZbbFqkZez6KGGwI6fPkA0AKt6I,374
|
2
|
+
freeplay/api_support.py,sha256=Kn2x3g6yloHQl3NwFRjbZE9BnIh7d1sgwGwC0mHuvw4,2483
|
3
|
+
freeplay/errors.py,sha256=bPqsw32YX-xSr7O-G49M0sSFF7mq-YF1WGq928UV47s,631
|
4
|
+
freeplay/freeplay.py,sha256=cj0TGxIziS5tEL12czMJrrKrCKRoYR_Qxsipg3ClpsU,1496
|
5
|
+
freeplay/freeplay_cli.py,sha256=lmdsYwzdpWmUKHz_ieCzB-e6j1EnDHlVw3XIEyP_NEk,3460
|
6
|
+
freeplay/llm_parameters.py,sha256=bQbfuC8EICF0XMZQa5pwI3FkQqxmCUVqHO3gYHy3Tg8,898
|
7
|
+
freeplay/model.py,sha256=pC24wUsedD4RTI4k1BcYuDjizroeEHINH6FtEa_RLCk,384
|
8
|
+
freeplay/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
+
freeplay/resources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
+
freeplay/resources/customer_feedback.py,sha256=aTM7Eez7iYmjXSpRqkHxf4pi6xBrzVnMiQCEJVfPGvg,527
|
11
|
+
freeplay/resources/prompts.py,sha256=V57JsLsWiMe4hAmysT8flKve7RPR8cxrxehmgUJPSeg,17537
|
12
|
+
freeplay/resources/recordings.py,sha256=kUElo6Yvc6lyo221ghbElx75uxftw7HpgBV_R9gYlE4,5938
|
13
|
+
freeplay/resources/sessions.py,sha256=pgfqCBa-qGwwdfym9nnHizEg0Jf4sd_chLAfunwtMCQ,2787
|
14
|
+
freeplay/resources/test_runs.py,sha256=cwhm4s1dj2FqPQN86W6rsFTcay1M-Ip6DAbXp7Utl8c,2370
|
15
|
+
freeplay/support.py,sha256=Fc7v8SQ1y62S08tuLAQfUI_qR2ZgLgah9kdL8sTbFMs,7848
|
16
|
+
freeplay/utils.py,sha256=8ZncuwCnzsAhRsaoxOMGa0Py8kXqGHlB9Avr3n79fk0,2064
|
17
|
+
freeplay-0.3.0a11.dist-info/LICENSE,sha256=_jzIw45hB1XHGxiQ8leZ0GH_X7bR_a8qgxaqnHbCUOo,1064
|
18
|
+
freeplay-0.3.0a11.dist-info/METADATA,sha256=Wo8u_ihnXH4S_963icBvw9CK_AeDrPAC8bfujKBbXLg,1605
|
19
|
+
freeplay-0.3.0a11.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
20
|
+
freeplay-0.3.0a11.dist-info/entry_points.txt,sha256=32s3rf2UUCqiJT4jnClEXZhdXlvl30uwpcxz-Gsy4UU,54
|
21
|
+
freeplay-0.3.0a11.dist-info/RECORD,,
|
@@ -1,21 +0,0 @@
|
|
1
|
-
freeplay/__init__.py,sha256=_Uk0dUfn59IuToFeFXlhmA1-ULoA3uBWkg8DGbVomhw,346
|
2
|
-
freeplay/api_support.py,sha256=Tmc6VRcmPcIgXrDNJXz0VbBD969t5QHAyV3yZlMsYRI,2331
|
3
|
-
freeplay/errors.py,sha256=bPqsw32YX-xSr7O-G49M0sSFF7mq-YF1WGq928UV47s,631
|
4
|
-
freeplay/freeplay.py,sha256=vwtgLNcHnXTAjyuXU1cOjvYuLBqcZ-RQDAjdFAKh7q0,1479
|
5
|
-
freeplay/freeplay_cli.py,sha256=lmdsYwzdpWmUKHz_ieCzB-e6j1EnDHlVw3XIEyP_NEk,3460
|
6
|
-
freeplay/llm_parameters.py,sha256=bQbfuC8EICF0XMZQa5pwI3FkQqxmCUVqHO3gYHy3Tg8,898
|
7
|
-
freeplay/model.py,sha256=pC24wUsedD4RTI4k1BcYuDjizroeEHINH6FtEa_RLCk,384
|
8
|
-
freeplay/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
-
freeplay/resources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
-
freeplay/resources/customer_feedback.py,sha256=aTM7Eez7iYmjXSpRqkHxf4pi6xBrzVnMiQCEJVfPGvg,527
|
11
|
-
freeplay/resources/prompts.py,sha256=V57JsLsWiMe4hAmysT8flKve7RPR8cxrxehmgUJPSeg,17537
|
12
|
-
freeplay/resources/recordings.py,sha256=6iPSvHtnPPPk53hd1z-qul7h-DRTrkL-qp1eSL0Umls,5707
|
13
|
-
freeplay/resources/sessions.py,sha256=ioWdeTM9BSrEWKrFH66ysQIw5kCTlCVopJDmWtFgHz0,868
|
14
|
-
freeplay/resources/test_runs.py,sha256=cwhm4s1dj2FqPQN86W6rsFTcay1M-Ip6DAbXp7Utl8c,2370
|
15
|
-
freeplay/support.py,sha256=5CUbtPpXtawOR2vR7UNRcVA7j9k9e3C4--2-Vk3p4qk,6952
|
16
|
-
freeplay/utils.py,sha256=8ZncuwCnzsAhRsaoxOMGa0Py8kXqGHlB9Avr3n79fk0,2064
|
17
|
-
freeplay-0.3.0a9.dist-info/LICENSE,sha256=_jzIw45hB1XHGxiQ8leZ0GH_X7bR_a8qgxaqnHbCUOo,1064
|
18
|
-
freeplay-0.3.0a9.dist-info/METADATA,sha256=gKY4Vte7Lny8s1bfFBylE3Drieg2SjFUrH2PsnvEdUI,1604
|
19
|
-
freeplay-0.3.0a9.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
20
|
-
freeplay-0.3.0a9.dist-info/entry_points.txt,sha256=32s3rf2UUCqiJT4jnClEXZhdXlvl30uwpcxz-Gsy4UU,54
|
21
|
-
freeplay-0.3.0a9.dist-info/RECORD,,
|
File without changes
|
File without changes
|