freeplay 0.2.24__tar.gz → 0.2.25__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.2.24
3
+ Version: 0.2.25
4
4
  Summary:
5
5
  License: MIT
6
6
  Author: FreePlay Engineering
@@ -46,8 +46,20 @@ class CallSupport:
46
46
  raise FreeplayConfigurationError(f'Could not find template with name "{template_name}"')
47
47
  return templates[0]
48
48
 
49
- def create_session(self, project_id: str, tag: str, test_run_id: Optional[str] = None) -> JsonDom:
50
- request_body = {'test_run_id': test_run_id} if test_run_id is not None else None
49
+ def create_session(
50
+ self,
51
+ project_id: str,
52
+ tag: str,
53
+ test_run_id: Optional[str] = None,
54
+ metadata: Optional[dict[str, str|int|float]] = None
55
+ ) -> JsonDom:
56
+ request_body: dict[str, Any] = {}
57
+ if test_run_id is not None:
58
+ request_body['test_run_id'] = test_run_id
59
+ if metadata is not None:
60
+ check_all_values_string_or_number(metadata)
61
+ request_body['metadata'] = metadata
62
+
51
63
  response = api_support.post_raw(api_key=self.freeplay_api_key,
52
64
  url=f'{self.api_base}/projects/{project_id}/sessions/tag/{tag}',
53
65
  payload=request_body)
@@ -535,9 +547,10 @@ class Freeplay:
535
547
  variables: dict[str, str],
536
548
  tag: str = default_tag,
537
549
  flavor: Optional[Flavor] = None,
550
+ metadata: Optional[dict[str, str|int|float]] = None,
538
551
  **kwargs: Any
539
552
  ) -> CompletionResponse:
540
- project_session = self.call_support.create_session(project_id, tag)
553
+ project_session = self.call_support.create_session(project_id, tag, None, metadata)
541
554
  prompts = self.call_support.get_prompts(project_id, tag)
542
555
  completion_flavor = flavor or self.client_flavor
543
556
 
@@ -557,9 +570,10 @@ class Freeplay:
557
570
  variables: dict[str, str],
558
571
  tag: str = default_tag,
559
572
  flavor: Optional[Flavor] = None,
573
+ metadata: Optional[dict[str, str|int|float]] = None,
560
574
  **kwargs: Any
561
575
  ) -> Generator[CompletionChunk, None, None]:
562
- project_session = self.call_support.create_session(project_id, tag)
576
+ project_session = self.call_support.create_session(project_id, tag, None, metadata)
563
577
  prompts = self.call_support.get_prompts(project_id, tag)
564
578
  completion_flavor = flavor or self.client_flavor
565
579
 
@@ -597,9 +611,10 @@ class Freeplay:
597
611
  template_name: str,
598
612
  variables: Variables,
599
613
  tag: str = default_tag,
614
+ metadata: Optional[dict[str, str|int|float]] = None,
600
615
  **kwargs: Any
601
616
  ) -> Tuple[ChatSession, ChatCompletionResponse]:
602
- session = self.__create_chat_session(project_id, tag, template_name, variables)
617
+ session = self.__create_chat_session(project_id, tag, template_name, variables, metadata)
603
618
  completion_response = session.start_chat(**kwargs)
604
619
  return session, completion_response
605
620
 
@@ -632,17 +647,24 @@ class Freeplay:
632
647
  template_name: str,
633
648
  variables: Variables,
634
649
  tag: str = default_tag,
650
+ metadata: Optional[dict[str, str|int|float]] = None,
635
651
  **kwargs: Any
636
652
  ) -> Tuple[ChatSession, Generator[CompletionChunk, None, None]]:
637
653
  """Returns a chat session, the base prompt template messages, and a streamed response from the LLM."""
638
- session = self.__create_chat_session(project_id, tag, template_name, variables)
654
+ session = self.__create_chat_session(project_id, tag, template_name, variables, metadata)
639
655
  completion_response = session.start_chat_stream(**kwargs)
640
656
  return session, completion_response
641
657
 
642
- def __create_chat_session(self, project_id: str, tag: str, template_name: str, variables: Variables) -> ChatSession:
658
+ def __create_chat_session(
659
+ self,
660
+ project_id: str,
661
+ tag: str,
662
+ template_name: str,
663
+ variables: Variables,
664
+ metadata: Optional[dict[str, str|int|float]] = None) -> ChatSession:
643
665
  chat_flavor = require_chat_flavor(self.client_flavor) if self.client_flavor else None
644
666
 
645
- project_session = self.call_support.create_session(project_id, tag)
667
+ project_session = self.call_support.create_session(project_id, tag, None, metadata)
646
668
  prompts = self.call_support.get_prompts(project_id, tag)
647
669
  return ChatSession(
648
670
  self.call_support,
@@ -677,3 +699,9 @@ def require_chat_flavor(flavor: Flavor) -> ChatFlavor:
677
699
  raise FreeplayConfigurationError('A Chat flavor is required to start a chat session.')
678
700
 
679
701
  return flavor
702
+
703
+ def check_all_values_string_or_number(metadata: Optional[dict[str, str|int|float]]) -> None:
704
+ if metadata:
705
+ for key, value in metadata.items():
706
+ if not isinstance(value, (str, int, float)):
707
+ raise FreeplayConfigurationError(f"Invalid value for key {key}: Value must be a string or number.")
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "freeplay"
3
- version = "0.2.24"
3
+ version = "0.2.25"
4
4
  description = ""
5
5
  authors = ["FreePlay Engineering <engineering@freeplay.ai>"]
6
6
  license = "MIT"
File without changes
File without changes
File without changes
File without changes
File without changes