freeplay 0.5.0a2__tar.gz → 0.5.0a4__tar.gz

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.
Files changed (22) hide show
  1. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/PKG-INFO +1 -1
  2. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/pyproject.toml +1 -1
  3. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/src/freeplay/resources/recordings.py +2 -13
  4. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/src/freeplay/resources/test_cases.py +4 -2
  5. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/src/freeplay/resources/test_runs.py +4 -2
  6. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/src/freeplay/support.py +43 -8
  7. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/src/freeplay/utils.py +39 -1
  8. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/LICENSE +0 -0
  9. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/README.md +0 -0
  10. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/src/freeplay/__init__.py +0 -0
  11. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/src/freeplay/api_support.py +0 -0
  12. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/src/freeplay/errors.py +0 -0
  13. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/src/freeplay/freeplay.py +0 -0
  14. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/src/freeplay/freeplay_cli.py +0 -0
  15. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/src/freeplay/llm_parameters.py +0 -0
  16. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/src/freeplay/model.py +0 -0
  17. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/src/freeplay/py.typed +0 -0
  18. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/src/freeplay/resources/__init__.py +0 -0
  19. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/src/freeplay/resources/adapters.py +0 -0
  20. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/src/freeplay/resources/customer_feedback.py +0 -0
  21. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/src/freeplay/resources/prompts.py +0 -0
  22. {freeplay-0.5.0a2 → freeplay-0.5.0a4}/src/freeplay/resources/sessions.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: freeplay
3
- Version: 0.5.0a2
3
+ Version: 0.5.0a4
4
4
  Summary:
5
5
  License: MIT
6
6
  Author: FreePlay Engineering
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "freeplay"
3
- version = "0.5.0a2"
3
+ version = "0.5.0a4"
4
4
  description = ""
5
5
  authors = ["FreePlay Engineering <engineering@freeplay.ai>"]
6
6
  license = "MIT"
@@ -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,
@@ -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'
@@ -75,8 +75,42 @@ def get_user_agent() -> str:
75
75
  # Recursively convert Pydantic models, lists, and dicts to dict compatible format -- used to allow us to accept
76
76
  # provider message shapes (usually generated types) or the default {'content': ..., 'role': ...} shape.
77
77
  def convert_provider_message_to_dict(obj: Any) -> Any:
78
+ """
79
+ Convert provider message objects to dictionaries.
80
+ For Vertex AI objects, automatically converts to camelCase.
81
+ """
82
+ # List of possible raw attribute names in Vertex AI objects
83
+ vertex_raw_attrs = [
84
+ '_raw_content', # For Content objects
85
+ '_raw_tool', # For Tool objects
86
+ '_raw_message', # For message objects
87
+ '_raw_candidate', # For Candidate objects
88
+ '_raw_response', # For response objects
89
+ '_raw_function_declaration', # For FunctionDeclaration
90
+ '_raw_generation_config', # For GenerationConfig
91
+ '_pb', # Generic protobuf attribute
92
+ ]
93
+
94
+ # Check for Vertex AI objects with raw protobuf attributes
95
+ for attr_name in vertex_raw_attrs:
96
+ if hasattr(obj, attr_name):
97
+ raw_obj = getattr(obj, attr_name)
98
+ if raw_obj is not None:
99
+ try:
100
+ # Use the metaclass to_dict with camelCase conversion
101
+ return type(raw_obj).to_dict(
102
+ raw_obj,
103
+ preserving_proto_field_name=False, # camelCase
104
+ use_integers_for_enums=False, # Keep as strings (we'll lowercase them)
105
+ including_default_value_fields=False # Exclude defaults
106
+ )
107
+ except: # noqa: E722
108
+ # If we can't convert, continue to the next attribute
109
+ pass
110
+
111
+ # For non-Vertex AI objects, use their standard to_dict methods
78
112
  if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')):
79
- # Vertex AI has a to_dict method
113
+ # Regular to_dict (for Vertex AI wrappers without _raw_* attributes)
80
114
  return obj.to_dict()
81
115
  elif hasattr(obj, 'model_dump'):
82
116
  # Pydantic v2
@@ -85,7 +119,11 @@ def convert_provider_message_to_dict(obj: Any) -> Any:
85
119
  # Pydantic v1
86
120
  return obj.dict(encode_json=True)
87
121
  elif isinstance(obj, dict):
122
+ # Handle dictionaries recursively
88
123
  return {k: convert_provider_message_to_dict(v) for k, v in obj.items()}
89
124
  elif isinstance(obj, list):
125
+ # Handle lists recursively
90
126
  return [convert_provider_message_to_dict(item) for item in obj]
127
+
128
+ # Return as-is for primitive types
91
129
  return obj
File without changes
File without changes