freeplay 0.3.0a3__tar.gz → 0.3.0a5__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: freeplay
3
- Version: 0.3.0a3
3
+ Version: 0.3.0a5
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.3.0-alpha.3"
3
+ version = "0.3.0-alpha.5"
4
4
  description = ""
5
5
  authors = ["FreePlay Engineering <engineering@freeplay.ai>"]
6
6
  license = "MIT"
File without changes
@@ -1,14 +1,15 @@
1
+ import copy
1
2
  import json
2
3
  from abc import ABC, abstractmethod
3
4
  from dataclasses import dataclass
4
5
  from pathlib import Path
5
- from typing import Dict, Optional, List, Union, cast, Any
6
+ from typing import Dict, Optional, List, cast, Any
6
7
 
7
8
  from freeplay.errors import FreeplayConfigurationError, FreeplayClientError
8
9
  from freeplay.llm_parameters import LLMParameters
9
10
  from freeplay.model import InputVariables
10
- from freeplay.support import PromptTemplate, PromptTemplates, PromptTemplateMetadata
11
11
  from freeplay.support import CallSupport
12
+ from freeplay.support import PromptTemplate, PromptTemplates, PromptTemplateMetadata
12
13
  from freeplay.utils import bind_template_variables
13
14
 
14
15
 
@@ -39,12 +40,18 @@ class FormattedPrompt:
39
40
  self,
40
41
  prompt_info: PromptInfo,
41
42
  messages: List[Dict[str, str]],
42
- formatted_prompt: Union[str, List[Dict[str, str]]]
43
+ formatted_prompt: List[Dict[str, str]]
43
44
  ):
44
45
  self.prompt_info = prompt_info
45
- self.messages = messages
46
46
  self.llm_prompt = formatted_prompt
47
47
 
48
+ maybe_system_content = next(
49
+ (message['content'] for message in messages if message['role'] == 'system'), None)
50
+ self.system_content = maybe_system_content
51
+
52
+ # Note: messages are **not formatted** for the provider.
53
+ self.messages = messages
54
+
48
55
  def all_messages(
49
56
  self,
50
57
  new_message: Dict[str, str]
@@ -62,26 +69,16 @@ class BoundPrompt:
62
69
  self.messages = messages
63
70
 
64
71
  @staticmethod
65
- def __to_anthropic_role(role: str) -> str:
66
- if role == 'assistant' or role == 'Assistant':
67
- return 'Assistant'
68
- else:
69
- # Anthropic does not support system role for now.
70
- return 'Human'
71
-
72
- @staticmethod
73
- def __format_messages_for_flavor(flavor_name: str, messages: List[Dict[str, str]]) -> Union[
74
- str, List[Dict[str, str]]]:
72
+ def __format_messages_for_flavor(
73
+ flavor_name: str,
74
+ messages: List[Dict[str, str]]
75
+ ) -> List[Dict[str, str]]:
75
76
  if flavor_name == 'azure_openai_chat' or flavor_name == 'openai_chat':
76
- return messages
77
+ # We need a deepcopy here to avoid referential equality with the llm_prompt
78
+ return copy.deepcopy(messages)
77
79
  elif flavor_name == 'anthropic_chat':
78
- formatted_messages = []
79
- for message in messages:
80
- role = BoundPrompt.__to_anthropic_role(message['role'])
81
- formatted_messages.append(f"{role}: {message['content']}")
82
- formatted_messages.append('Assistant:')
83
-
84
- return "\n\n" + "\n\n".join(formatted_messages)
80
+ messages_without_system = [message for message in messages if message['role'] != 'system']
81
+ return messages_without_system
85
82
  raise MissingFlavorError(flavor_name)
86
83
 
87
84
  def format(
@@ -89,12 +86,12 @@ class BoundPrompt:
89
86
  flavor_name: Optional[str] = None
90
87
  ) -> FormattedPrompt:
91
88
  final_flavor = flavor_name or self.prompt_info.flavor_name
92
- llm_format = BoundPrompt.__format_messages_for_flavor(final_flavor, self.messages)
89
+ formatted_prompt = BoundPrompt.__format_messages_for_flavor(final_flavor, self.messages)
93
90
 
94
91
  return FormattedPrompt(
95
92
  self.prompt_info,
96
93
  self.messages,
97
- llm_format,
94
+ formatted_prompt
98
95
  )
99
96
 
100
97
 
@@ -1,7 +1,7 @@
1
1
  import json
2
2
  import logging
3
3
  from dataclasses import dataclass
4
- from typing import Dict, Optional, List
4
+ from typing import Any, Dict, List, Optional
5
5
 
6
6
  from requests import HTTPError
7
7
 
@@ -23,15 +23,17 @@ class CallInfo:
23
23
  start_time: float
24
24
  end_time: float
25
25
  model_parameters: LLMParameters
26
+ provider_info: Optional[Dict[str, Any]] = None
26
27
 
27
28
  @staticmethod
28
29
  def from_prompt_info(prompt_info: PromptInfo, start_time: float, end_time: float) -> 'CallInfo':
29
30
  return CallInfo(
30
- prompt_info.provider,
31
- prompt_info.model,
32
- start_time,
33
- end_time,
34
- prompt_info.model_parameters
31
+ provider=prompt_info.provider,
32
+ model=prompt_info.model,
33
+ start_time=start_time,
34
+ end_time=end_time,
35
+ model_parameters=prompt_info.model_parameters,
36
+ provider_info=prompt_info.provider_info,
35
37
  )
36
38
 
37
39
 
@@ -94,6 +96,7 @@ class Recordings:
94
96
  "model": record_payload.call_info.model,
95
97
  "provider": record_payload.call_info.provider,
96
98
  "llm_parameters": record_payload.call_info.model_parameters,
99
+ "provider_info": record_payload.call_info.provider_info,
97
100
  }
98
101
 
99
102
  if record_payload.session_info.custom_metadata is not None:
File without changes
File without changes