freeplay 0.2.31__tar.gz → 0.2.32__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.
- {freeplay-0.2.31 → freeplay-0.2.32}/PKG-INFO +1 -2
- {freeplay-0.2.31 → freeplay-0.2.32}/pyproject.toml +1 -1
- {freeplay-0.2.31 → freeplay-0.2.32}/src/freeplay/freeplay.py +14 -21
- {freeplay-0.2.31 → freeplay-0.2.32}/src/freeplay/freeplay_thin.py +3 -2
- {freeplay-0.2.31 → freeplay-0.2.32}/src/freeplay/model.py +3 -3
- {freeplay-0.2.31 → freeplay-0.2.32}/src/freeplay/record.py +4 -0
- {freeplay-0.2.31 → freeplay-0.2.32}/src/freeplay/support.py +43 -7
- {freeplay-0.2.31 → freeplay-0.2.32}/LICENSE +0 -0
- {freeplay-0.2.31 → freeplay-0.2.32}/README.md +0 -0
- {freeplay-0.2.31 → freeplay-0.2.32}/src/freeplay/__init__.py +0 -0
- {freeplay-0.2.31 → freeplay-0.2.32}/src/freeplay/api_support.py +0 -0
- {freeplay-0.2.31 → freeplay-0.2.32}/src/freeplay/completions.py +0 -0
- {freeplay-0.2.31 → freeplay-0.2.32}/src/freeplay/errors.py +0 -0
- {freeplay-0.2.31 → freeplay-0.2.32}/src/freeplay/flavors.py +0 -0
- {freeplay-0.2.31 → freeplay-0.2.32}/src/freeplay/freeplay_cli.py +0 -0
- {freeplay-0.2.31 → freeplay-0.2.32}/src/freeplay/llm_parameters.py +0 -0
- {freeplay-0.2.31 → freeplay-0.2.32}/src/freeplay/provider_config.py +0 -0
- {freeplay-0.2.31 → freeplay-0.2.32}/src/freeplay/py.typed +0 -0
- {freeplay-0.2.31 → freeplay-0.2.32}/src/freeplay/utils.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: freeplay
|
3
|
-
Version: 0.2.
|
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,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
|
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,
|
@@ -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
|
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,
|
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
|
|
@@ -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 =
|
10
|
+
InputVariables = Mapping[str, InputValue]
|
11
11
|
|
12
12
|
PydanticInputVariables = RootModel[Dict[str, InputVariable]]
|
13
13
|
|
14
|
-
TestRunInput =
|
14
|
+
TestRunInput = Mapping[str, InputValue]
|
15
15
|
|
16
16
|
|
17
17
|
@dataclass
|
@@ -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,
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import json
|
2
2
|
import time
|
3
3
|
from copy import copy
|
4
|
-
from typing import
|
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,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|