unique_toolkit 0.5.51__tar.gz → 0.5.52__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.
Files changed (52) hide show
  1. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/CHANGELOG.md +4 -0
  2. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/PKG-INFO +7 -3
  3. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/README.md +2 -2
  4. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/pyproject.toml +1 -1
  5. unique_toolkit-0.5.52/unique_toolkit/chat/__init__.py +10 -0
  6. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/chat/schemas.py +35 -0
  7. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/chat/service.py +170 -1
  8. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/language_model/service.py +7 -5
  9. unique_toolkit-0.5.51/unique_toolkit/chat/__init__.py +0 -6
  10. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/LICENSE +0 -0
  11. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/__init__.py +0 -0
  12. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/_common/_base_service.py +0 -0
  13. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/_common/_time_utils.py +0 -0
  14. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/_common/exception.py +0 -0
  15. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/_common/validators.py +0 -0
  16. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/app/__init__.py +0 -0
  17. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/app/init_logging.py +0 -0
  18. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/app/init_sdk.py +0 -0
  19. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/app/performance/async_tasks.py +0 -0
  20. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/app/performance/async_wrapper.py +0 -0
  21. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/app/schemas.py +0 -0
  22. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/app/verification.py +0 -0
  23. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/chat/state.py +0 -0
  24. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/chat/utils.py +0 -0
  25. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/content/__init__.py +0 -0
  26. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/content/schemas.py +0 -0
  27. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/content/service.py +0 -0
  28. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/content/utils.py +0 -0
  29. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/embedding/__init__.py +0 -0
  30. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/embedding/schemas.py +0 -0
  31. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/embedding/service.py +0 -0
  32. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/embedding/utils.py +0 -0
  33. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/evaluators/config.py +0 -0
  34. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/evaluators/context_relevancy/constants.py +0 -0
  35. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/evaluators/context_relevancy/prompts.py +0 -0
  36. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/evaluators/context_relevancy/service.py +0 -0
  37. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/evaluators/context_relevancy/utils.py +0 -0
  38. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/evaluators/exception.py +0 -0
  39. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/evaluators/hallucination/constants.py +0 -0
  40. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/evaluators/hallucination/prompts.py +0 -0
  41. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/evaluators/hallucination/service.py +0 -0
  42. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/evaluators/hallucination/utils.py +0 -0
  43. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/evaluators/output_parser.py +0 -0
  44. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/evaluators/schemas.py +0 -0
  45. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/language_model/__init__.py +0 -0
  46. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/language_model/builder.py +0 -0
  47. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/language_model/infos.py +0 -0
  48. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/language_model/prompt.py +0 -0
  49. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/language_model/schemas.py +0 -0
  50. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/language_model/utils.py +0 -0
  51. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/short_term_memory/schemas.py +0 -0
  52. {unique_toolkit-0.5.51 → unique_toolkit-0.5.52}/unique_toolkit/short_term_memory/service.py +0 -0
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.5.52] - 2025-02-01
9
+ - Add `MessageAssessment` schemas and functions to `ChatService` to handle message assessments.
10
+ - Fix `LanguageModelService.complete_async_util` to use the correct async method.
11
+
8
12
  ## [0.5.51] - 2025-01-30
9
13
  - Add missing structured output arguments in complete_async
10
14
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unique_toolkit
3
- Version: 0.5.51
3
+ Version: 0.5.52
4
4
  Summary:
5
5
  License: Proprietary
6
6
  Author: Martin Fadler
@@ -55,8 +55,8 @@ The `unique_toolkit.app` module encompasses functions for initializing and secur
55
55
 
56
56
  The `unique_toolkit.chat` module encompasses all chat related functionality.
57
57
 
58
- - `service.py` comprises the ChatService and provides an interface to manage and load the chat history and interact with the chat ui, e.g., creating a new assistant message.
59
- - `schemas.py` comprises all relevant schemas, e.g., ChatMessage, used in the ChatService.
58
+ - `service.py` comprises the ChatService and provides an interface to manage and load the chat history and interact with the chat ui, e.g., creating a new assistant message, modifying messages, and managing message assessments.
59
+ - `schemas.py` comprises all relevant schemas, e.g., ChatMessage, MessageAssessment, used in the ChatService.
60
60
  - `utils.py` comprises utility functions to use and convert ChatMessage objects in assistants, e.g., convert_chat_history_to_injectable_string converts the chat history to a string that can be injected into a prompt.
61
61
 
62
62
  ## Content
@@ -100,6 +100,10 @@ All notable changes to this project will be documented in this file.
100
100
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
101
101
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
102
102
 
103
+ ## [0.5.52] - 2025-02-01
104
+ - Add `MessageAssessment` schemas and functions to `ChatService` to handle message assessments.
105
+ - Fix `LanguageModelService.complete_async_util` to use the correct async method.
106
+
103
107
  ## [0.5.51] - 2025-01-30
104
108
  - Add missing structured output arguments in complete_async
105
109
 
@@ -33,8 +33,8 @@ The `unique_toolkit.app` module encompasses functions for initializing and secur
33
33
 
34
34
  The `unique_toolkit.chat` module encompasses all chat related functionality.
35
35
 
36
- - `service.py` comprises the ChatService and provides an interface to manage and load the chat history and interact with the chat ui, e.g., creating a new assistant message.
37
- - `schemas.py` comprises all relevant schemas, e.g., ChatMessage, used in the ChatService.
36
+ - `service.py` comprises the ChatService and provides an interface to manage and load the chat history and interact with the chat ui, e.g., creating a new assistant message, modifying messages, and managing message assessments.
37
+ - `schemas.py` comprises all relevant schemas, e.g., ChatMessage, MessageAssessment, used in the ChatService.
38
38
  - `utils.py` comprises utility functions to use and convert ChatMessage objects in assistants, e.g., convert_chat_history_to_injectable_string converts the chat history to a string that can be injected into a prompt.
39
39
 
40
40
  ## Content
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "unique_toolkit"
3
- version = "0.5.51"
3
+ version = "0.5.52"
4
4
  description = ""
5
5
  authors = [
6
6
  "Martin Fadler <martin.fadler@unique.ch>",
@@ -0,0 +1,10 @@
1
+ from .schemas import ChatMessage as ChatMessage
2
+ from .schemas import ChatMessageRole as ChatMessageRole
3
+ from .schemas import MessageAssessment as MessageAssessment
4
+ from .schemas import MessageAssessmentLabel as MessageAssessmentLabel
5
+ from .schemas import MessageAssessmentStatus as MessageAssessmentStatus
6
+ from .schemas import MessageAssessmentType as MessageAssessmentType
7
+ from .service import ChatService as ChatService
8
+ from .utils import (
9
+ convert_chat_history_to_injectable_string as convert_chat_history_to_injectable_string,
10
+ )
@@ -1,3 +1,4 @@
1
+ from datetime import datetime
1
2
  from enum import StrEnum
2
3
  from typing import Optional
3
4
 
@@ -60,3 +61,37 @@ class ChatMessage(BaseModel):
60
61
  if self.role == ChatMessageRole.TOOL and not self.tool_call_id:
61
62
  raise ValueError("tool_call_ids is required when role is 'tool'")
62
63
  return self
64
+
65
+
66
+ class MessageAssessmentStatus(StrEnum):
67
+ PENDING = "PENDING"
68
+ DONE = "DONE"
69
+ ERROR = "ERROR"
70
+
71
+
72
+ class MessageAssessmentLabel(StrEnum):
73
+ POSITIVE = "POSITIVE"
74
+ NEGATIVE = "NEGATIVE"
75
+ VERIFIED = "VERIFIED"
76
+ UNVERIFIED = "UNVERIFIED"
77
+
78
+
79
+ class MessageAssessmentType(StrEnum):
80
+ HALLUCINATION = "HALLUCINATION"
81
+ COMPLIANCE = "COMPLIANCE"
82
+
83
+
84
+ class MessageAssessment(BaseModel):
85
+ model_config = model_config
86
+
87
+ id: str
88
+ object: str
89
+ message_id: str
90
+ assistant_message_id: str
91
+ status: MessageAssessmentStatus
92
+ explanation: str
93
+ label: MessageAssessmentLabel
94
+ type: MessageAssessmentType
95
+ is_visible: bool
96
+ created_at: datetime
97
+ updated_at: datetime
@@ -8,7 +8,14 @@ from unique_sdk._list_object import ListObject
8
8
  from unique_toolkit._common import _time_utils
9
9
  from unique_toolkit._common._base_service import BaseService
10
10
  from unique_toolkit.app.schemas import Event
11
- from unique_toolkit.chat.schemas import ChatMessage, ChatMessageRole
11
+ from unique_toolkit.chat.schemas import (
12
+ ChatMessage,
13
+ ChatMessageRole,
14
+ MessageAssessment,
15
+ MessageAssessmentLabel,
16
+ MessageAssessmentStatus,
17
+ MessageAssessmentType,
18
+ )
12
19
  from unique_toolkit.content.schemas import ContentReference
13
20
  from unique_toolkit.content.utils import count_tokens
14
21
 
@@ -587,3 +594,165 @@ class ChatService(BaseService):
587
594
  "completedAt": completed_at_datetime,
588
595
  }
589
596
  return params
597
+
598
+ def create_message_assessment(
599
+ self,
600
+ assistant_message_id: str,
601
+ status: MessageAssessmentStatus,
602
+ explanation: str,
603
+ label: MessageAssessmentLabel,
604
+ type: MessageAssessmentType,
605
+ is_visible: bool = True,
606
+ ) -> MessageAssessment:
607
+ """
608
+ Creates a message assessment for an assistant message synchronously.
609
+
610
+ Args:
611
+ assistant_message_id (str): The ID of the assistant message to assess
612
+ status (MessageAssessmentStatus): The status of the assessment (e.g. "DONE")
613
+ explanation (str): Explanation of the assessment
614
+ label (MessageAssessmentLabel): The assessment label (e.g. "NEGATIVE")
615
+ type (MessageAssessmentType): The type of assessment (e.g. "HALLUCINATION")
616
+ is_visible (bool): Whether the assessment is visible to users. Defaults to True.
617
+
618
+ Returns:
619
+ MessageAssessment: The created message assessment
620
+
621
+ Raises:
622
+ Exception: If the creation fails
623
+ """
624
+ try:
625
+ assessment = unique_sdk.MessageAssessment.create(
626
+ user_id=self.event.user_id,
627
+ company_id=self.event.company_id,
628
+ assistant_message_id=assistant_message_id,
629
+ status=status.name,
630
+ explanation=explanation,
631
+ label=label.name,
632
+ type=type.name,
633
+ isVisible=is_visible,
634
+ )
635
+ return MessageAssessment(**assessment)
636
+ except Exception as e:
637
+ self.logger.error(f"Failed to create message assessment: {e}")
638
+ raise e
639
+
640
+ async def create_message_assessment_async(
641
+ self,
642
+ assistant_message_id: str,
643
+ status: MessageAssessmentStatus,
644
+ explanation: str,
645
+ label: MessageAssessmentLabel,
646
+ type: MessageAssessmentType,
647
+ is_visible: bool = True,
648
+ ) -> MessageAssessment:
649
+ """
650
+ Creates a message assessment for an assistant message asynchronously.
651
+
652
+ Args:
653
+ assistant_message_id (str): The ID of the assistant message to assess
654
+ status (MessageAssessmentStatus): The status of the assessment (e.g. "DONE")
655
+ explanation (str): Explanation of the assessment
656
+ label (MessageAssessmentLabel): The assessment label (e.g. "NEGATIVE")
657
+ type (MessageAssessmentType): The type of assessment (e.g. "HALLUCINATION")
658
+ is_visible (bool): Whether the assessment is visible to users. Defaults to True.
659
+
660
+ Returns:
661
+ MessageAssessment: The created message assessment
662
+
663
+ Raises:
664
+ Exception: If the creation fails
665
+ """
666
+ try:
667
+ assessment = await unique_sdk.MessageAssessment.create_async(
668
+ user_id=self.event.user_id,
669
+ company_id=self.event.company_id,
670
+ assistant_message_id=assistant_message_id,
671
+ status=status.name,
672
+ explanation=explanation,
673
+ label=label.name,
674
+ type=type.name,
675
+ isVisible=is_visible,
676
+ )
677
+ return MessageAssessment(**assessment)
678
+ except Exception as e:
679
+ self.logger.error(f"Failed to create message assessment: {e}")
680
+ raise e
681
+
682
+ def modify_message_assessment(
683
+ self,
684
+ assistant_message_id: str,
685
+ status: MessageAssessmentStatus,
686
+ explanation: str,
687
+ label: MessageAssessmentLabel,
688
+ type: MessageAssessmentType,
689
+ ) -> MessageAssessment:
690
+ """
691
+ Modifies a message assessment for an assistant message synchronously.
692
+
693
+ Args:
694
+ assistant_message_id (str): The ID of the assistant message to assess
695
+ status (MessageAssessmentStatus): The status of the assessment (e.g. "DONE")
696
+ explanation (str): Explanation of the assessment
697
+ label (MessageAssessmentLabel): The assessment label (e.g. "NEGATIVE")
698
+ type (MessageAssessmentType): The type of assessment (e.g. "HALLUCINATION")
699
+
700
+ Returns:
701
+ dict: The modified message assessment
702
+
703
+ Raises:
704
+ Exception: If the modification fails
705
+ """
706
+ try:
707
+ assessment = unique_sdk.MessageAssessment.modify(
708
+ user_id=self.event.user_id,
709
+ company_id=self.event.company_id,
710
+ assistant_message_id=assistant_message_id,
711
+ status=status.name,
712
+ explanation=explanation,
713
+ label=label.name,
714
+ type=type.name,
715
+ )
716
+ return MessageAssessment(**assessment)
717
+ except Exception as e:
718
+ self.logger.error(f"Failed to modify message assessment: {e}")
719
+ raise e
720
+
721
+ async def modify_message_assessment_async(
722
+ self,
723
+ assistant_message_id: str,
724
+ status: MessageAssessmentStatus,
725
+ explanation: str,
726
+ label: MessageAssessmentLabel,
727
+ type: MessageAssessmentType,
728
+ ) -> MessageAssessment:
729
+ """
730
+ Modifies a message assessment for an assistant message asynchronously.
731
+
732
+ Args:
733
+ assistant_message_id (str): The ID of the assistant message to assess
734
+ status (MessageAssessmentStatus): The status of the assessment (e.g. "DONE")
735
+ explanation (str): Explanation of the assessment
736
+ label (MessageAssessmentLabel): The assessment label (e.g. "NEGATIVE")
737
+ type (MessageAssessmentType): The type of assessment (e.g. "HALLUCINATION")
738
+
739
+ Returns:
740
+ MessageAssessment: The modified message assessment
741
+
742
+ Raises:
743
+ Exception: If the modification fails
744
+ """
745
+ try:
746
+ assessment = await unique_sdk.MessageAssessment.modify_async(
747
+ user_id=self.event.user_id,
748
+ company_id=self.event.company_id,
749
+ assistant_message_id=assistant_message_id,
750
+ status=status.name,
751
+ explanation=explanation,
752
+ label=label.name,
753
+ type=type.name,
754
+ )
755
+ return MessageAssessment(**assessment)
756
+ except Exception as e:
757
+ self.logger.error(f"Failed to modify message assessment: {e}")
758
+ raise e
@@ -84,8 +84,9 @@ class LanguageModelService(BaseService):
84
84
  self.logger.error(f"Error completing: {e}")
85
85
  raise e
86
86
 
87
+ @classmethod
87
88
  async def complete_async_util(
88
- self,
89
+ cls,
89
90
  company_id: str,
90
91
  messages: LanguageModelMessages,
91
92
  model_name: LanguageModelName | str,
@@ -122,7 +123,7 @@ class LanguageModelService(BaseService):
122
123
  Raises:
123
124
  Exception: If an error occurs during the request, an exception is raised and logged.
124
125
  """
125
- options, model, messages_dict, _ = self._prepare_completion_params_util(
126
+ options, model, messages_dict, _ = cls._prepare_completion_params_util(
126
127
  messages=messages,
127
128
  model_name=model_name,
128
129
  temperature=temperature,
@@ -369,8 +370,9 @@ class LanguageModelService(BaseService):
369
370
  }
370
371
  return options
371
372
 
373
+ @classmethod
372
374
  def _prepare_completion_params_util(
373
- self,
375
+ cls,
374
376
  messages: LanguageModelMessages,
375
377
  model_name: LanguageModelName | str,
376
378
  temperature: float,
@@ -391,10 +393,10 @@ class LanguageModelService(BaseService):
391
393
  - search_context (Optional[dict]): Processed content chunks if provided
392
394
  """
393
395
 
394
- options = self._add_tools_to_options({}, tools)
396
+ options = cls._add_tools_to_options({}, tools)
395
397
 
396
398
  if structured_output_model:
397
- options = self._add_response_format_to_options(
399
+ options = cls._add_response_format_to_options(
398
400
  options, structured_output_model, structured_output_enforce_schema
399
401
  )
400
402
 
@@ -1,6 +0,0 @@
1
- from .schemas import ChatMessage as ChatMessage
2
- from .schemas import ChatMessageRole as ChatMessageRole
3
- from .service import ChatService as ChatService
4
- from .utils import (
5
- convert_chat_history_to_injectable_string as convert_chat_history_to_injectable_string,
6
- )
File without changes