freeplay 0.5.0a3__py3-none-any.whl → 0.5.0a4__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.
@@ -21,7 +21,7 @@ from freeplay.resources.prompts import (
21
21
  PromptInfo,
22
22
  )
23
23
  from freeplay.resources.sessions import SessionInfo, TraceInfo
24
- from freeplay.support import CallSupport
24
+ from freeplay.support import CallSupport, media_inputs_to_json
25
25
  from freeplay.utils import convert_provider_message_to_dict
26
26
 
27
27
  logger = logging.getLogger(__name__)
@@ -109,18 +109,7 @@ class RecordResponse:
109
109
  completion_id: str
110
110
 
111
111
 
112
- def media_inputs_to_json(media_input: MediaInput) -> Dict[str, Any]:
113
- if isinstance(media_input, MediaInputUrl):
114
- return {
115
- "type": media_input.type,
116
- "url": media_input.url
117
- }
118
- else:
119
- return {
120
- "type": media_input.type,
121
- "data": media_input.data,
122
- "content_type": media_input.content_type
123
- }
112
+
124
113
 
125
114
  class Recordings:
126
115
  def __init__(self, call_support: CallSupport):
@@ -1,7 +1,7 @@
1
1
  from dataclasses import dataclass
2
2
  from typing import List, Optional, Dict, Any
3
3
 
4
- from freeplay.model import InputVariables, NormalizedMessage
4
+ from freeplay.model import InputVariables, NormalizedMessage, MediaInputMap
5
5
  from freeplay.support import CallSupport, DatasetTestCaseRequest, DatasetTestCasesRetrievalResponse
6
6
 
7
7
 
@@ -13,12 +13,14 @@ class DatasetTestCase:
13
13
  output: Optional[str],
14
14
  history: Optional[List[NormalizedMessage]] = None,
15
15
  metadata: Optional[Dict[str, str]] = None,
16
+ media_inputs: Optional[MediaInputMap] = None,
16
17
  id: Optional[str] = None, # Only set on retrieval
17
18
  ):
18
19
  self.inputs = inputs
19
20
  self.output = output
20
21
  self.history = history
21
22
  self.metadata = metadata
23
+ self.media_inputs = media_inputs
22
24
  self.id = id
23
25
 
24
26
 
@@ -44,7 +46,7 @@ class TestCases:
44
46
  return self.create_many(project_id, dataset_id, [test_case])
45
47
 
46
48
  def create_many(self, project_id: str, dataset_id: str, test_cases: List[DatasetTestCase]) -> Dataset:
47
- dataset_test_cases = [DatasetTestCaseRequest(test_case.history, test_case.inputs, test_case.metadata, test_case.output) for test_case in test_cases]
49
+ dataset_test_cases = [DatasetTestCaseRequest(test_case.history, test_case.inputs, test_case.metadata, test_case.output, test_case.media_inputs) for test_case in test_cases]
48
50
  self.call_support.create_test_cases(project_id, dataset_id, dataset_test_cases)
49
51
  return Dataset(dataset_id, test_cases)
50
52
 
@@ -1,5 +1,6 @@
1
1
  import warnings
2
2
  from dataclasses import dataclass
3
+ from uuid import UUID
3
4
  from typing import Any, Dict, List, Optional, Union
4
5
 
5
6
  from freeplay.model import InputVariables, MediaInputBase64, MediaInputUrl, TestRunInfo
@@ -117,10 +118,11 @@ class TestRuns:
117
118
  include_outputs: bool = False,
118
119
  name: Optional[str] = None,
119
120
  description: Optional[str] = None,
120
- flavor_name: Optional[str] = None
121
+ flavor_name: Optional[str] = None,
122
+ target_evaluation_ids: Optional[List[UUID]] = None,
121
123
  ) -> TestRun:
122
124
  test_run = self.call_support.create_test_run(
123
- project_id, testlist, include_outputs, name, description, flavor_name)
125
+ project_id, testlist, include_outputs, name, description, flavor_name, target_evaluation_ids)
124
126
  test_cases = [
125
127
  CompletionTestCase(
126
128
  test_case_id=test_case.id,
freeplay/support.py CHANGED
@@ -1,6 +1,7 @@
1
1
  from dataclasses import asdict, dataclass, field
2
2
  from json import JSONEncoder
3
3
  from typing import Any, Dict, List, Literal, Optional, Union
4
+ from uuid import UUID
4
5
 
5
6
  from freeplay import api_support
6
7
  from freeplay.api_support import try_decode
@@ -11,7 +12,7 @@ from freeplay.model import (
11
12
  MediaInputBase64,
12
13
  MediaInputUrl,
13
14
  NormalizedMessage,
14
- TestRunInfo,
15
+ TestRunInfo, MediaInputMap, MediaInput,
15
16
  )
16
17
 
17
18
  CustomMetadata = Optional[Dict[str, Union[str, int, float, bool]]]
@@ -35,7 +36,6 @@ class ToolSchema:
35
36
 
36
37
  Role = Literal['system', 'user', 'assistant']
37
38
 
38
-
39
39
  MediaType = Literal["image", "audio", "video", "file"]
40
40
 
41
41
 
@@ -56,6 +56,7 @@ class TemplateChatMessage:
56
56
  class HistoryTemplateMessage:
57
57
  kind: Literal["history"]
58
58
 
59
+
59
60
  TemplateMessage = Union[HistoryTemplateMessage, TemplateChatMessage]
60
61
 
61
62
 
@@ -94,6 +95,20 @@ class ProjectInfos:
94
95
  projects: List[ProjectInfo]
95
96
 
96
97
 
98
+ def media_inputs_to_json(media_input: MediaInput) -> Dict[str, Any]:
99
+ if isinstance(media_input, MediaInputUrl):
100
+ return {
101
+ "type": media_input.type,
102
+ "url": media_input.url
103
+ }
104
+ else:
105
+ return {
106
+ "type": media_input.type,
107
+ "data": media_input.data,
108
+ "content_type": media_input.content_type
109
+ }
110
+
111
+
97
112
  class PromptTemplateEncoder(JSONEncoder):
98
113
  def default(self, prompt_template: PromptTemplate) -> Dict[str, Any]:
99
114
  return prompt_template.__dict__
@@ -176,12 +191,19 @@ class TestRunRetrievalResponse:
176
191
 
177
192
 
178
193
  class DatasetTestCaseRequest:
179
- def __init__(self, history: Optional[List[NormalizedMessage]], inputs: InputVariables,
180
- metadata: Optional[Dict[str, str]], output: Optional[str]) -> None:
194
+ def __init__(
195
+ self,
196
+ history: Optional[List[NormalizedMessage]],
197
+ inputs: InputVariables,
198
+ metadata: Optional[Dict[str, str]],
199
+ output: Optional[str],
200
+ media_inputs: Optional[MediaInputMap] = None,
201
+ ) -> None:
181
202
  self.history: Optional[List[NormalizedMessage]] = history
182
203
  self.inputs: InputVariables = inputs
183
204
  self.metadata: Optional[Dict[str, str]] = metadata
184
205
  self.output: Optional[str] = output
206
+ self.media_inputs = media_inputs
185
207
 
186
208
 
187
209
  class DatasetTestCaseResponse:
@@ -325,7 +347,8 @@ class CallSupport:
325
347
  include_outputs: bool = False,
326
348
  name: Optional[str] = None,
327
349
  description: Optional[str] = None,
328
- flavor_name: Optional[str] = None
350
+ flavor_name: Optional[str] = None,
351
+ target_evaluation_ids: Optional[List[UUID]] = None
329
352
  ) -> TestRunResponse:
330
353
  response = api_support.post_raw(
331
354
  api_key=self.freeplay_api_key,
@@ -335,7 +358,10 @@ class CallSupport:
335
358
  'include_outputs': include_outputs,
336
359
  'test_run_name': name,
337
360
  'test_run_description': description,
338
- 'flavor_name': flavor_name
361
+ 'flavor_name': flavor_name,
362
+ 'target_evaluation_ids': [
363
+ str(id) for id in target_evaluation_ids
364
+ ] if target_evaluation_ids is not None else None
339
365
  },
340
366
  )
341
367
 
@@ -403,13 +429,22 @@ class CallSupport:
403
429
  if response.status_code != 201:
404
430
  raise freeplay_response_error('Error while deleting session.', response)
405
431
 
406
- def create_test_cases(self, project_id: str, dataset_id: str, test_cases: List[DatasetTestCaseRequest]) -> None:
432
+ def create_test_cases(
433
+ self,
434
+ project_id: str,
435
+ dataset_id: str,
436
+ test_cases: List[DatasetTestCaseRequest]
437
+ ) -> None:
407
438
  examples = [
408
439
  {
409
440
  "history": test_case.history,
410
441
  "output": test_case.output,
411
442
  "metadata": test_case.metadata,
412
- "inputs": test_case.inputs
443
+ "inputs": test_case.inputs,
444
+ "media_inputs": {
445
+ name: media_inputs_to_json(media_input)
446
+ for name, media_input in test_case.media_inputs.items()
447
+ } if test_case.media_inputs is not None else None
413
448
  } for test_case in test_cases]
414
449
  payload: Dict[str, Any] = {"examples": examples}
415
450
  url = f'{self.api_base}/v2/projects/{project_id}/datasets/id/{dataset_id}/test-cases'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: freeplay
3
- Version: 0.5.0a3
3
+ Version: 0.5.0a4
4
4
  Summary:
5
5
  License: MIT
6
6
  Author: FreePlay Engineering
@@ -10,14 +10,14 @@ freeplay/resources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
10
10
  freeplay/resources/adapters.py,sha256=6ZAPpoLeOkUkV1s9VNQNsYrnupV0-sy11zFfKfctM1Y,9296
11
11
  freeplay/resources/customer_feedback.py,sha256=6AUgHyOcXIpHvrxGAhsQgmDERvRHKutB6J-GkhkGH6s,928
12
12
  freeplay/resources/prompts.py,sha256=pkZa_b3HSrZoPqhcKCXsb26w2In-ETKydclbkXU_hus,24093
13
- freeplay/resources/recordings.py,sha256=OOSgSkQO7CVnOA2y7eSl5B2eMHZv5E3_-3J2XILwKUo,9811
13
+ freeplay/resources/recordings.py,sha256=f6h2b1qFQUJbjVjMaGdWuiVXD9TYbuAUTKe0ReEZ2dg,9452
14
14
  freeplay/resources/sessions.py,sha256=dZtd9nq2nH8pmXxQOJitBnN5Jl3kjggDItDcjC69TYo,3883
15
- freeplay/resources/test_cases.py,sha256=nXL_976RwSJDT6OWDM4GEzbcOzcGkJ9ulvb0XOzCRDM,2240
16
- freeplay/resources/test_runs.py,sha256=IkqW2LrVrLzFcGtalwP4FV-DeQKKb6Nekvy02FfoH8k,5007
17
- freeplay/support.py,sha256=9X-utKyM9BkhCLJbPT184ud26Dc69f3DiHjyN8qq0vQ,15266
15
+ freeplay/resources/test_cases.py,sha256=yJPtcAk1HznXSiJ8K5PtW_PIO_309LqObs4swBzzcNk,2378
16
+ freeplay/resources/test_runs.py,sha256=ZQ7K2hjNRRiQOx8e4-mXTvPDb7ksTsIzBVlq2utrMNo,5117
17
+ freeplay/support.py,sha256=smTwTTMRyK9NvhY0-uILWD_4Ri-Uw6_QZAagfhfOoJo,16372
18
18
  freeplay/utils.py,sha256=OtoSnlDrLEk3MWiXmKFJ4Sw42-1kQ94-d_2ekHT6eUo,5038
19
- freeplay-0.5.0a3.dist-info/LICENSE,sha256=_jzIw45hB1XHGxiQ8leZ0GH_X7bR_a8qgxaqnHbCUOo,1064
20
- freeplay-0.5.0a3.dist-info/METADATA,sha256=wJZwNOsRV5Oq1xPG8Wbx1H4UpbC4oH6RbuVP_erRPqM,1662
21
- freeplay-0.5.0a3.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
22
- freeplay-0.5.0a3.dist-info/entry_points.txt,sha256=32s3rf2UUCqiJT4jnClEXZhdXlvl30uwpcxz-Gsy4UU,54
23
- freeplay-0.5.0a3.dist-info/RECORD,,
19
+ freeplay-0.5.0a4.dist-info/LICENSE,sha256=_jzIw45hB1XHGxiQ8leZ0GH_X7bR_a8qgxaqnHbCUOo,1064
20
+ freeplay-0.5.0a4.dist-info/METADATA,sha256=HLcOsZCmDOAftfWHKMj5YNJ_lNqkmlbnpYrM1eJR6Ig,1662
21
+ freeplay-0.5.0a4.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
22
+ freeplay-0.5.0a4.dist-info/entry_points.txt,sha256=32s3rf2UUCqiJT4jnClEXZhdXlvl30uwpcxz-Gsy4UU,54
23
+ freeplay-0.5.0a4.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.2
2
+ Generator: poetry-core 2.1.3
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any