freeplay 0.2.31__py3-none-any.whl → 0.2.32__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/freeplay.py CHANGED
@@ -3,7 +3,6 @@ import logging
3
3
  from dataclasses import dataclass
4
4
  from typing import Any, Dict, Generator, List, Optional, Tuple, Union
5
5
 
6
- from . import api_support
7
6
  from .completions import (
8
7
  PromptTemplates,
9
8
  CompletionResponse,
@@ -11,7 +10,7 @@ from .completions import (
11
10
  ChatCompletionResponse,
12
11
  ChatMessage
13
12
  )
14
- from .errors import FreeplayConfigurationError, freeplay_response_error
13
+ from .errors import FreeplayConfigurationError
15
14
  from .flavors import Flavor, ChatFlavor, require_chat_flavor, get_chat_flavor_from_config
16
15
  from .llm_parameters import LLMParameters
17
16
  from .model import InputVariables
@@ -236,6 +235,8 @@ class FreeplayTestRun:
236
235
  # The simplifications are:
237
236
  # - Always assumes there is a single choice returned, does not support multiple
238
237
  # - Does not support an "escape hatch" to allow use of features we don't explicitly expose
238
+
239
+
239
240
  class Freeplay:
240
241
  def __init__(
241
242
  self,
@@ -341,25 +342,6 @@ class Freeplay:
341
342
  completion_parameters=LLMParameters(kwargs),
342
343
  metadata=metadata)
343
344
 
344
- def create_test_run(self, project_id: str, testlist: str) -> FreeplayTestRun:
345
- response = api_support.post_raw(
346
- api_key=self.freeplay_api_key,
347
- url=f'{self.api_base}/projects/{project_id}/test-runs',
348
- payload={'playlist_name': testlist},
349
- )
350
-
351
- if response.status_code != 201:
352
- raise freeplay_response_error('Error while creating a test run.', response)
353
-
354
- json_dom = response.json()
355
-
356
- return FreeplayTestRun(
357
- self.call_support,
358
- self.client_flavor,
359
- self.provider_config,
360
- json_dom['test_run_id'],
361
- json_dom['inputs'])
362
-
363
345
  def start_chat(
364
346
  self,
365
347
  project_id: str,
@@ -410,6 +392,17 @@ class Freeplay:
410
392
  completion_response = session.start_chat_stream(**kwargs)
411
393
  return session, completion_response
412
394
 
395
+ def create_test_run(self, project_id: str, testlist: str) -> FreeplayTestRun:
396
+ test_run_response = self.call_support.create_test_run(project_id=project_id, testlist=testlist)
397
+
398
+ return FreeplayTestRun(
399
+ self.call_support,
400
+ self.client_flavor,
401
+ self.provider_config,
402
+ test_run_response.test_run_id,
403
+ [test_case.variables for test_case in test_run_response.test_cases]
404
+ )
405
+
413
406
  def __create_chat_session(
414
407
  self,
415
408
  project_id: str,
freeplay/freeplay_thin.py CHANGED
@@ -1,7 +1,7 @@
1
1
  from .completions import PromptTemplates
2
2
  from .errors import FreeplayConfigurationError
3
3
  from .record import DefaultRecordProcessor
4
- from .support import (CallSupport)
4
+ from .support import CallSupport
5
5
 
6
6
 
7
7
  class FreeplayThin:
@@ -13,7 +13,8 @@ class FreeplayThin:
13
13
  if not freeplay_api_key or not freeplay_api_key.strip():
14
14
  raise FreeplayConfigurationError("Freeplay API key not set. It must be set to the Freeplay API.")
15
15
 
16
- self.call_support = CallSupport(freeplay_api_key, api_base, DefaultRecordProcessor(freeplay_api_key, api_base))
16
+ self.call_support = CallSupport(freeplay_api_key, api_base,
17
+ DefaultRecordProcessor(freeplay_api_key, api_base))
17
18
  self.freeplay_api_key = freeplay_api_key
18
19
  self.api_base = api_base
19
20
 
freeplay/model.py CHANGED
@@ -1,5 +1,5 @@
1
1
  from dataclasses import dataclass
2
- from typing import List, Union, Any, Dict
2
+ from typing import List, Union, Any, Dict, Mapping
3
3
 
4
4
  from pydantic import RootModel
5
5
 
@@ -7,11 +7,11 @@ InputValue = Union[str, int, bool, dict[str, Any], list[Any]]
7
7
  InputVariable = RootModel[Union[Dict[str, "InputVariable"], List["InputVariable"], str, int, bool, float]]
8
8
  InputVariable.model_rebuild()
9
9
 
10
- InputVariables = Dict[str, InputValue]
10
+ InputVariables = Mapping[str, InputValue]
11
11
 
12
12
  PydanticInputVariables = RootModel[Dict[str, InputVariable]]
13
13
 
14
- TestRunInput = Dict[str, InputValue]
14
+ TestRunInput = Mapping[str, InputValue]
15
15
 
16
16
 
17
17
  @dataclass
freeplay/record.py CHANGED
@@ -25,6 +25,7 @@ class RecordCallFields:
25
25
  variables: InputVariables
26
26
  tag: str
27
27
  test_run_id: Optional[str]
28
+ test_case_id: Optional[str]
28
29
  record_format_type: Optional[str]
29
30
  model: Optional[str]
30
31
  provider: Optional[str]
@@ -87,6 +88,9 @@ class DefaultRecordProcessor(RecordProcessor):
87
88
  if record_call.test_run_id is not None:
88
89
  record_payload['test_run_id'] = record_call.test_run_id
89
90
 
91
+ if record_call.test_case_id is not None:
92
+ record_payload['test_case_id'] = record_call.test_case_id
93
+
90
94
  try:
91
95
  recorded_response = api_support.post_raw(
92
96
  api_key=self.freeplay_api_key,
freeplay/support.py CHANGED
@@ -1,7 +1,8 @@
1
1
  import json
2
2
  import time
3
3
  from copy import copy
4
- from typing import cast, Dict, Any, Optional, Union, List, Generator
4
+ from typing import Dict, Any, Optional, Union, List, Generator
5
+ from uuid import uuid4
5
6
 
6
7
  from freeplay import api_support
7
8
  from freeplay.api_support import try_decode
@@ -13,12 +14,29 @@ from freeplay.llm_parameters import LLMParameters
13
14
  from freeplay.model import InputVariables
14
15
  from freeplay.provider_config import ProviderConfig
15
16
  from freeplay.record import RecordProcessor, RecordCallFields
16
- from freeplay.utils import check_all_values_string_or_number
17
- from uuid import uuid4
18
17
 
19
18
  JsonDom = Dict[str, Any]
20
19
 
21
20
 
21
+ class TestCaseTestRunResponse:
22
+ def __init__(self, test_case: JsonDom):
23
+ self.variables: InputVariables = test_case['variables']
24
+ self.id: str = test_case['id']
25
+
26
+
27
+ class TestRunResponse:
28
+ def __init__(
29
+ self,
30
+ test_run_id: str,
31
+ test_cases: list[JsonDom]
32
+ ):
33
+ self.test_cases = [
34
+ TestCaseTestRunResponse(test_case)
35
+ for test_case in test_cases
36
+ ]
37
+ self.test_run_id = test_run_id
38
+
39
+
22
40
  class CallSupport:
23
41
  def __init__(
24
42
  self,
@@ -67,6 +85,20 @@ class CallSupport:
67
85
 
68
86
  return maybe_prompts
69
87
 
88
+ def create_test_run(self, project_id: str, testlist: str) -> TestRunResponse:
89
+ response = api_support.post_raw(
90
+ api_key=self.freeplay_api_key,
91
+ url=f'{self.api_base}/projects/{project_id}/test-runs-cases',
92
+ payload={'testlist_name': testlist},
93
+ )
94
+
95
+ if response.status_code != 201:
96
+ raise freeplay_response_error('Error while creating a test run.', response)
97
+
98
+ json_dom = response.json()
99
+
100
+ return TestRunResponse(json_dom['test_run_id'], json_dom['test_cases'])
101
+
70
102
  # noinspection PyUnboundLocalVariable
71
103
  def prepare_and_make_chat_call(
72
104
  self,
@@ -80,7 +112,7 @@ class CallSupport:
80
112
  new_messages: Optional[List[ChatMessage]],
81
113
  test_run_id: Optional[str] = None,
82
114
  completion_parameters: Optional[LLMParameters] = None,
83
- metadata: Optional[Dict[str, Union[str,int,float]]] = None
115
+ metadata: Optional[Dict[str, Union[str, int, float]]] = None
84
116
  ) -> ChatCompletionResponse:
85
117
  # make call
86
118
  start = time.time()
@@ -110,6 +142,7 @@ class CallSupport:
110
142
  record_format_type=flavor.record_format_type,
111
143
  tag=tag,
112
144
  test_run_id=test_run_id,
145
+ test_case_id=None,
113
146
  model=model,
114
147
  provider=flavor.provider,
115
148
  llm_parameters=params,
@@ -131,7 +164,7 @@ class CallSupport:
131
164
  message_history: List[ChatMessage],
132
165
  test_run_id: Optional[str] = None,
133
166
  completion_parameters: Optional[LLMParameters] = None,
134
- metadata: Optional[Dict[str, Union[str,int,float]]] = None
167
+ metadata: Optional[Dict[str, Union[str, int, float]]] = None
135
168
  ) -> Generator[CompletionChunk, None, None]:
136
169
  # make call
137
170
  start = time.time()
@@ -164,6 +197,7 @@ class CallSupport:
164
197
  record_format_type=flavor.record_format_type,
165
198
  tag=tag,
166
199
  test_run_id=test_run_id,
200
+ test_case_id=None,
167
201
  model=model,
168
202
  provider=flavor.provider,
169
203
  llm_parameters=params,
@@ -183,7 +217,7 @@ class CallSupport:
183
217
  tag: str,
184
218
  test_run_id: Optional[str] = None,
185
219
  completion_parameters: Optional[LLMParameters] = None,
186
- metadata: Optional[Dict[str, Union[str,int,float]]] = None
220
+ metadata: Optional[Dict[str, Union[str, int, float]]] = None
187
221
  ) -> CompletionResponse:
188
222
  target_template = self.find_template_by_name(prompts, template_name)
189
223
  params = target_template.get_params() \
@@ -215,6 +249,7 @@ class CallSupport:
215
249
  record_format_type=final_flavor.record_format_type,
216
250
  tag=tag,
217
251
  test_run_id=test_run_id,
252
+ test_case_id=None,
218
253
  model=model,
219
254
  provider=final_flavor.provider,
220
255
  llm_parameters=params,
@@ -235,7 +270,7 @@ class CallSupport:
235
270
  tag: str,
236
271
  test_run_id: Optional[str] = None,
237
272
  completion_parameters: Optional[LLMParameters] = None,
238
- metadata: Optional[Dict[str, Union[str,int,float]]] = None
273
+ metadata: Optional[Dict[str, Union[str, int, float]]] = None
239
274
  ) -> Generator[CompletionChunk, None, None]:
240
275
  target_template = self.find_template_by_name(prompts, template_name)
241
276
  params = target_template.get_params() \
@@ -272,6 +307,7 @@ class CallSupport:
272
307
  record_format_type=final_flavor.record_format_type,
273
308
  tag=tag,
274
309
  test_run_id=test_run_id,
310
+ test_case_id=None,
275
311
  model=model,
276
312
  provider=final_flavor.provider,
277
313
  llm_parameters=params,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: freeplay
3
- Version: 0.2.31
3
+ Version: 0.2.32
4
4
  Summary:
5
5
  License: MIT
6
6
  Author: FreePlay Engineering
@@ -12,7 +12,6 @@ Classifier: Programming Language :: Python :: 3.8
12
12
  Classifier: Programming Language :: Python :: 3.9
13
13
  Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
- Classifier: Programming Language :: Python :: 3.12
16
15
  Requires-Dist: anthropic (>=0.7.7,<0.8.0)
17
16
  Requires-Dist: click (==8.1.7)
18
17
  Requires-Dist: dacite (>=1.8.0,<2.0.0)
@@ -3,18 +3,18 @@ freeplay/api_support.py,sha256=E4Mxa3Lx31TEw_X6o4s9eAR1TSxs0PhFYYaWax6dH2I,2027
3
3
  freeplay/completions.py,sha256=F1rMBtQaCtn0rBQqvCurkV25g8gLtwnEod5rRvf-txY,1176
4
4
  freeplay/errors.py,sha256=bPqsw32YX-xSr7O-G49M0sSFF7mq-YF1WGq928UV47s,631
5
5
  freeplay/flavors.py,sha256=XroBKT8Nf92VTsuC261Nceo9f9stkkpC5CXbi8y4NEs,17236
6
- freeplay/freeplay.py,sha256=qKBgpBEDl7drJTNRxli2_nPGkC0cjM-L7W_vd8Omhas,17346
6
+ freeplay/freeplay.py,sha256=BLlr4YXh3a624xcM93KvZGsiIGSMrIMFM07lLyVCIao,17089
7
7
  freeplay/freeplay_cli.py,sha256=nasbc_ckSr5-YtUKfg_w-6X1geQZ9s5u79VzRULGsbs,3868
8
- freeplay/freeplay_thin.py,sha256=MY8Ej9zVY8cYB_mh7YpHkyqtOKb3LxWJK1R_Los6XeY,829
8
+ freeplay/freeplay_thin.py,sha256=WHoVCkS30mDM7ghjDadgfj48BNL5EvaXktUsGfeXlIY,867
9
9
  freeplay/llm_parameters.py,sha256=bQbfuC8EICF0XMZQa5pwI3FkQqxmCUVqHO3gYHy3Tg8,898
10
- freeplay/model.py,sha256=zmcaE4ZuJeWL7mxZ7hNc-EVMljyn3PHqzSvZbZ3XWZk,519
10
+ freeplay/model.py,sha256=kVARXUEJKbhOdWz7T8eR7npTPXlpaY9wWaEzJvbIvOU,534
11
11
  freeplay/provider_config.py,sha256=hruf3Khusrwb76_-hv7ouuxmvJuaRyC1UxIw7XlJx8A,1416
12
12
  freeplay/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- freeplay/record.py,sha256=PCKZjBtTNTHaHxJDIVIQMDdpdMXyAljgMCWfmbfNlyo,3202
14
- freeplay/support.py,sha256=Z46_39J3he1Ilbhb1P7-D0_RRfJYSoq5Jug6cchF53g,11525
13
+ freeplay/record.py,sha256=_0uo0rUFZz8kwgWC0JhxFg13JyXgMfAVCkzZsuRLzBA,3354
14
+ freeplay/support.py,sha256=OOnUZOMYnLSEG_3toycWfHb2XZ8meF77uQRllYexXeo,12616
15
15
  freeplay/utils.py,sha256=cRCCIzVqWNDKlTI-DDhXGyCkplbd-X4qzDs__aUpvww,1840
16
- freeplay-0.2.31.dist-info/LICENSE,sha256=_jzIw45hB1XHGxiQ8leZ0GH_X7bR_a8qgxaqnHbCUOo,1064
17
- freeplay-0.2.31.dist-info/METADATA,sha256=nejUVtT4OHp01SPHN3N3YNwBgnxDZdPIEUKtcerPRMU,1684
18
- freeplay-0.2.31.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
19
- freeplay-0.2.31.dist-info/entry_points.txt,sha256=32s3rf2UUCqiJT4jnClEXZhdXlvl30uwpcxz-Gsy4UU,54
20
- freeplay-0.2.31.dist-info/RECORD,,
16
+ freeplay-0.2.32.dist-info/LICENSE,sha256=_jzIw45hB1XHGxiQ8leZ0GH_X7bR_a8qgxaqnHbCUOo,1064
17
+ freeplay-0.2.32.dist-info/METADATA,sha256=o9MiS7BrkV0M2Erp7bKomeRUBgveiqW6XQf7LLyVA4s,1633
18
+ freeplay-0.2.32.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
19
+ freeplay-0.2.32.dist-info/entry_points.txt,sha256=32s3rf2UUCqiJT4jnClEXZhdXlvl30uwpcxz-Gsy4UU,54
20
+ freeplay-0.2.32.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.8.1
2
+ Generator: poetry-core 1.6.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any