freeplay 0.3.0a6__py3-none-any.whl → 0.3.0a8__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.
@@ -3,7 +3,7 @@ import json
3
3
  from abc import ABC, abstractmethod
4
4
  from dataclasses import dataclass
5
5
  from pathlib import Path
6
- from typing import Dict, Optional, List, cast, Any
6
+ from typing import Dict, Optional, List, cast, Any, Union
7
7
 
8
8
  from freeplay.errors import FreeplayConfigurationError, FreeplayClientError
9
9
  from freeplay.llm_parameters import LLMParameters
@@ -40,10 +40,13 @@ class FormattedPrompt:
40
40
  self,
41
41
  prompt_info: PromptInfo,
42
42
  messages: List[Dict[str, str]],
43
- formatted_prompt: List[Dict[str, str]]
43
+ formatted_prompt: Optional[List[Dict[str, str]]] = None,
44
+ formatted_prompt_text: Optional[str] = None
44
45
  ):
45
46
  self.prompt_info = prompt_info
46
47
  self.llm_prompt = formatted_prompt
48
+ if formatted_prompt_text:
49
+ self.llm_prompt_text = formatted_prompt_text
47
50
 
48
51
  maybe_system_content = next(
49
52
  (message['content'] for message in messages if message['role'] == 'system'), None)
@@ -72,13 +75,24 @@ class BoundPrompt:
72
75
  def __format_messages_for_flavor(
73
76
  flavor_name: str,
74
77
  messages: List[Dict[str, str]]
75
- ) -> List[Dict[str, str]]:
78
+ ) -> Union[str, List[Dict[str, str]]]:
76
79
  if flavor_name == 'azure_openai_chat' or flavor_name == 'openai_chat':
77
80
  # We need a deepcopy here to avoid referential equality with the llm_prompt
78
81
  return copy.deepcopy(messages)
79
82
  elif flavor_name == 'anthropic_chat':
80
83
  messages_without_system = [message for message in messages if message['role'] != 'system']
81
84
  return messages_without_system
85
+ elif flavor_name == 'llama_3_chat':
86
+ if len(messages) < 1:
87
+ raise ValueError("Must have at least one message to format")
88
+
89
+ formatted = "<|begin_of_text|>"
90
+ for message in messages:
91
+ formatted += f"<|start_header_id|>{message['role']}<|end_header_id|>\n{message['content']}<|eot_id|>"
92
+ formatted += "<|start_header_id|>assistant<|end_header_id|>"
93
+
94
+ return formatted
95
+
82
96
  raise MissingFlavorError(flavor_name)
83
97
 
84
98
  def format(
@@ -88,11 +102,18 @@ class BoundPrompt:
88
102
  final_flavor = flavor_name or self.prompt_info.flavor_name
89
103
  formatted_prompt = BoundPrompt.__format_messages_for_flavor(final_flavor, self.messages)
90
104
 
91
- return FormattedPrompt(
92
- self.prompt_info,
93
- self.messages,
94
- formatted_prompt
95
- )
105
+ if isinstance(formatted_prompt, str):
106
+ return FormattedPrompt(
107
+ prompt_info=self.prompt_info,
108
+ messages=self.messages,
109
+ formatted_prompt_text=formatted_prompt
110
+ )
111
+ else:
112
+ return FormattedPrompt(
113
+ prompt_info=self.prompt_info,
114
+ messages=self.messages,
115
+ formatted_prompt=formatted_prompt
116
+ )
96
117
 
97
118
 
98
119
  class TemplatePrompt:
@@ -1,7 +1,7 @@
1
1
  import json
2
2
  import logging
3
3
  from dataclasses import dataclass
4
- from typing import Any, Dict, List, Optional
4
+ from typing import Any, Dict, List, Optional, Union
5
5
 
6
6
  from requests import HTTPError
7
7
 
@@ -61,6 +61,7 @@ class RecordPayload:
61
61
  call_info: CallInfo
62
62
  response_info: ResponseInfo
63
63
  test_run_info: Optional[TestRunInfo] = None
64
+ eval_results: Optional[Dict[str, Union[bool, float]]] = None
64
65
 
65
66
 
66
67
  @dataclass
@@ -111,6 +112,9 @@ class Recordings:
111
112
  if record_payload.test_run_info is not None:
112
113
  record_api_payload['test_case_id'] = record_payload.test_run_info.test_case_id
113
114
 
115
+ if record_payload.eval_results is not None:
116
+ record_api_payload['eval_results'] = record_payload.eval_results
117
+
114
118
  try:
115
119
  recorded_response = api_support.post_raw(
116
120
  api_key=self.call_support.freeplay_api_key,
@@ -40,8 +40,15 @@ class TestRuns:
40
40
  def __init__(self, call_support: CallSupport) -> None:
41
41
  self.call_support = call_support
42
42
 
43
- def create(self, project_id: str, testlist: str, include_outputs: bool = False) -> TestRun:
44
- test_run = self.call_support.create_test_run(project_id, testlist, include_outputs)
43
+ def create(
44
+ self,
45
+ project_id: str,
46
+ testlist: str,
47
+ include_outputs: bool = False,
48
+ name: Optional[str] = None,
49
+ description: Optional[str] = None
50
+ ) -> TestRun:
51
+ test_run = self.call_support.create_test_run(project_id, testlist, include_outputs, name, description)
45
52
  test_cases = [
46
53
  TestCase(test_case_id=test_case.id, variables=test_case.variables, output=test_case.output)
47
54
  for test_case in test_run.test_cases
freeplay/support.py CHANGED
@@ -123,7 +123,9 @@ class CallSupport:
123
123
  self,
124
124
  project_id: str,
125
125
  testlist: str,
126
- include_test_case_outputs: bool = False
126
+ include_test_case_outputs: bool = False,
127
+ name: Optional[str] = None,
128
+ description: Optional[str] = None
127
129
  ) -> TestRunResponse:
128
130
  response = api_support.post_raw(
129
131
  api_key=self.freeplay_api_key,
@@ -131,6 +133,8 @@ class CallSupport:
131
133
  payload={
132
134
  'testlist_name': testlist,
133
135
  'include_test_case_outputs': include_test_case_outputs,
136
+ 'name': name,
137
+ 'description': description
134
138
  },
135
139
  )
136
140
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: freeplay
3
- Version: 0.3.0a6
3
+ Version: 0.3.0a8
4
4
  Summary:
5
5
  License: MIT
6
6
  Author: FreePlay Engineering
@@ -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=ieR9_duwWFktmVSX8u_XdGZYcb3soHqwFjQdyvSJqac,12400
12
- freeplay/resources/recordings.py,sha256=CQMhvKLGXVMkW3o0Ixu_zM5k38RSNQRcEM6U30hMNDE,5412
11
+ freeplay/resources/prompts.py,sha256=v0EY2hHVzqGlOCvrfg3E907LImTRQ69Nx2Xbpu0UID4,13352
12
+ freeplay/resources/recordings.py,sha256=7H10N8bJpQ_upJ_tkIdYOOE1JfFwe8T7hfH8yr76a2M,5614
13
13
  freeplay/resources/sessions.py,sha256=ioWdeTM9BSrEWKrFH66ysQIw5kCTlCVopJDmWtFgHz0,868
14
- freeplay/resources/test_runs.py,sha256=2NAwoW_Yx7K8YM7QyQ3sv9dN6p0gjNgUAR7wSzLYP6w,1452
15
- freeplay/support.py,sha256=7BizelIEIaSRFj2IL53-RQkjncUNlUS-DPUln2VxoJg,4532
14
+ freeplay/resources/test_runs.py,sha256=NfYcEKJu6Br0YUleo2ZtYi35uRw207uaAhwCBYDJtXQ,1612
15
+ freeplay/support.py,sha256=rlkFuZSByYUdfw2BvKRdqjdmsrl2_4ZsMpDv8htKn7o,4692
16
16
  freeplay/utils.py,sha256=8ZncuwCnzsAhRsaoxOMGa0Py8kXqGHlB9Avr3n79fk0,2064
17
- freeplay-0.3.0a6.dist-info/LICENSE,sha256=_jzIw45hB1XHGxiQ8leZ0GH_X7bR_a8qgxaqnHbCUOo,1064
18
- freeplay-0.3.0a6.dist-info/METADATA,sha256=skFosdzJU5udk9ucgrmvZgTAsBQ9uKkKsGWmQKtqTL0,1553
19
- freeplay-0.3.0a6.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
20
- freeplay-0.3.0a6.dist-info/entry_points.txt,sha256=32s3rf2UUCqiJT4jnClEXZhdXlvl30uwpcxz-Gsy4UU,54
21
- freeplay-0.3.0a6.dist-info/RECORD,,
17
+ freeplay-0.3.0a8.dist-info/LICENSE,sha256=_jzIw45hB1XHGxiQ8leZ0GH_X7bR_a8qgxaqnHbCUOo,1064
18
+ freeplay-0.3.0a8.dist-info/METADATA,sha256=pJpMSO5APQpgFpNWoNBdGhSx2vTrYA750NHOABY74ww,1553
19
+ freeplay-0.3.0a8.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
20
+ freeplay-0.3.0a8.dist-info/entry_points.txt,sha256=32s3rf2UUCqiJT4jnClEXZhdXlvl30uwpcxz-Gsy4UU,54
21
+ freeplay-0.3.0a8.dist-info/RECORD,,