freeplay 0.3.0a11__py3-none-any.whl → 0.3.1__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/errors.py +9 -0
- freeplay/resources/prompts.py +31 -7
- freeplay/support.py +1 -1
- {freeplay-0.3.0a11.dist-info → freeplay-0.3.1.dist-info}/METADATA +1 -1
- {freeplay-0.3.0a11.dist-info → freeplay-0.3.1.dist-info}/RECORD +8 -8
- {freeplay-0.3.0a11.dist-info → freeplay-0.3.1.dist-info}/WHEEL +1 -1
- {freeplay-0.3.0a11.dist-info → freeplay-0.3.1.dist-info}/LICENSE +0 -0
- {freeplay-0.3.0a11.dist-info → freeplay-0.3.1.dist-info}/entry_points.txt +0 -0
freeplay/errors.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
from requests import Response
|
2
|
+
import warnings
|
2
3
|
|
3
4
|
|
4
5
|
class FreeplayError(Exception):
|
@@ -32,3 +33,11 @@ def freeplay_response_error(message: str, response: Response) -> FreeplayError:
|
|
32
33
|
return FreeplayClientError(full_message)
|
33
34
|
else:
|
34
35
|
return FreeplayServerError(full_message)
|
36
|
+
|
37
|
+
|
38
|
+
class FreeplayClientWarning(UserWarning):
|
39
|
+
pass
|
40
|
+
|
41
|
+
|
42
|
+
def log_freeplay_client_warning(message: str) -> None:
|
43
|
+
warnings.warn(message, FreeplayClientWarning)
|
freeplay/resources/prompts.py
CHANGED
@@ -5,7 +5,7 @@ from dataclasses import dataclass
|
|
5
5
|
from pathlib import Path
|
6
6
|
from typing import Dict, Optional, List, cast, Any, Union
|
7
7
|
|
8
|
-
from freeplay.errors import FreeplayConfigurationError, FreeplayClientError
|
8
|
+
from freeplay.errors import FreeplayConfigurationError, FreeplayClientError, log_freeplay_client_warning
|
9
9
|
from freeplay.llm_parameters import LLMParameters
|
10
10
|
from freeplay.model import InputVariables
|
11
11
|
from freeplay.support import CallSupport
|
@@ -144,11 +144,34 @@ class TemplatePrompt:
|
|
144
144
|
self.prompt_info = prompt_info
|
145
145
|
self.messages = messages
|
146
146
|
|
147
|
-
def bind(self, variables: InputVariables) -> BoundPrompt:
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
147
|
+
def bind(self, variables: InputVariables, history: Optional[List[Dict[str, str]]] = None) -> BoundPrompt:
|
148
|
+
# check history for a system message
|
149
|
+
history_clean = []
|
150
|
+
if history:
|
151
|
+
for msg in history:
|
152
|
+
if (msg.get('role') == 'system') & ('system' in [message.get('role') for message in self.messages]):
|
153
|
+
log_freeplay_client_warning("System message found in history, and prompt template."
|
154
|
+
"Removing system message from the history")
|
155
|
+
else:
|
156
|
+
history_clean.append(msg)
|
157
|
+
|
158
|
+
has_history_placeholder = {"kind": "history"} in self.messages
|
159
|
+
if history and not has_history_placeholder:
|
160
|
+
raise FreeplayClientError(
|
161
|
+
"History provided for prompt that does not expect history")
|
162
|
+
if has_history_placeholder and not history:
|
163
|
+
log_freeplay_client_warning("History missing for prompt that expects history")
|
164
|
+
|
165
|
+
bound_messages = []
|
166
|
+
for msg in self.messages:
|
167
|
+
if msg.get('kind') == 'history':
|
168
|
+
bound_messages.extend(history_clean)
|
169
|
+
else:
|
170
|
+
bound_messages.append({
|
171
|
+
'role': msg['role'],
|
172
|
+
'content': bind_template_variables(msg['content'], variables)},
|
173
|
+
)
|
174
|
+
|
152
175
|
return BoundPrompt(self.prompt_info, bound_messages)
|
153
176
|
|
154
177
|
|
@@ -425,13 +448,14 @@ class Prompts:
|
|
425
448
|
template_name: str,
|
426
449
|
environment: str,
|
427
450
|
variables: InputVariables,
|
451
|
+
history: Optional[List[Dict[str, str]]] = None,
|
428
452
|
flavor_name: Optional[str] = None
|
429
453
|
) -> FormattedPrompt:
|
430
454
|
bound_prompt = self.get(
|
431
455
|
project_id=project_id,
|
432
456
|
template_name=template_name,
|
433
457
|
environment=environment
|
434
|
-
).bind(variables=variables)
|
458
|
+
).bind(variables=variables, history=history)
|
435
459
|
|
436
460
|
return bound_prompt.format(flavor_name)
|
437
461
|
|
freeplay/support.py
CHANGED
@@ -198,7 +198,7 @@ class CallSupport:
|
|
198
198
|
api_key=self.freeplay_api_key,
|
199
199
|
url=f'{self.api_base}/v2/projects/{project_id}/test-runs/id/{test_run_id}'
|
200
200
|
)
|
201
|
-
if response.status_code !=
|
201
|
+
if response.status_code != 200:
|
202
202
|
raise freeplay_response_error('Error while retrieving test run results.', response)
|
203
203
|
|
204
204
|
json_dom = response.json()
|
@@ -1,6 +1,6 @@
|
|
1
1
|
freeplay/__init__.py,sha256=oseuUqIVAi-2a_ns4ZbbFqkZez6KGGwI6fPkA0AKt6I,374
|
2
2
|
freeplay/api_support.py,sha256=Kn2x3g6yloHQl3NwFRjbZE9BnIh7d1sgwGwC0mHuvw4,2483
|
3
|
-
freeplay/errors.py,sha256=
|
3
|
+
freeplay/errors.py,sha256=vwotUBldxDzREZOmLUeoiDoZjcvDwgH1AMwKBLhLooE,807
|
4
4
|
freeplay/freeplay.py,sha256=cj0TGxIziS5tEL12czMJrrKrCKRoYR_Qxsipg3ClpsU,1496
|
5
5
|
freeplay/freeplay_cli.py,sha256=lmdsYwzdpWmUKHz_ieCzB-e6j1EnDHlVw3XIEyP_NEk,3460
|
6
6
|
freeplay/llm_parameters.py,sha256=bQbfuC8EICF0XMZQa5pwI3FkQqxmCUVqHO3gYHy3Tg8,898
|
@@ -8,14 +8,14 @@ freeplay/model.py,sha256=pC24wUsedD4RTI4k1BcYuDjizroeEHINH6FtEa_RLCk,384
|
|
8
8
|
freeplay/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
9
|
freeplay/resources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
10
|
freeplay/resources/customer_feedback.py,sha256=aTM7Eez7iYmjXSpRqkHxf4pi6xBrzVnMiQCEJVfPGvg,527
|
11
|
-
freeplay/resources/prompts.py,sha256=
|
11
|
+
freeplay/resources/prompts.py,sha256=HTxD_jD6ovfQCil5zrnSGwIGK5Y-FdX_upW56cJWpQI,18758
|
12
12
|
freeplay/resources/recordings.py,sha256=kUElo6Yvc6lyo221ghbElx75uxftw7HpgBV_R9gYlE4,5938
|
13
13
|
freeplay/resources/sessions.py,sha256=pgfqCBa-qGwwdfym9nnHizEg0Jf4sd_chLAfunwtMCQ,2787
|
14
14
|
freeplay/resources/test_runs.py,sha256=cwhm4s1dj2FqPQN86W6rsFTcay1M-Ip6DAbXp7Utl8c,2370
|
15
|
-
freeplay/support.py,sha256=
|
15
|
+
freeplay/support.py,sha256=oh8KkKHYtVZdrZ9v5VJNrw_I9fqZZZWNQInHOfHjW0s,7848
|
16
16
|
freeplay/utils.py,sha256=8ZncuwCnzsAhRsaoxOMGa0Py8kXqGHlB9Avr3n79fk0,2064
|
17
|
-
freeplay-0.3.
|
18
|
-
freeplay-0.3.
|
19
|
-
freeplay-0.3.
|
20
|
-
freeplay-0.3.
|
21
|
-
freeplay-0.3.
|
17
|
+
freeplay-0.3.1.dist-info/LICENSE,sha256=_jzIw45hB1XHGxiQ8leZ0GH_X7bR_a8qgxaqnHbCUOo,1064
|
18
|
+
freeplay-0.3.1.dist-info/METADATA,sha256=rTBnS0EWPCIboV43KNYlFb5_ogwtNZ1JaWZrtEJEodk,1602
|
19
|
+
freeplay-0.3.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
20
|
+
freeplay-0.3.1.dist-info/entry_points.txt,sha256=32s3rf2UUCqiJT4jnClEXZhdXlvl30uwpcxz-Gsy4UU,54
|
21
|
+
freeplay-0.3.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|