unique_toolkit 0.5.55__tar.gz → 0.6.0__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 (72) hide show
  1. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/CHANGELOG.md +16 -1
  2. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/PKG-INFO +33 -7
  3. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/README.md +16 -5
  4. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/pyproject.toml +1 -1
  5. unique_toolkit-0.6.0/unique_toolkit/_common/validate_required_values.py +21 -0
  6. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/app/__init__.py +20 -0
  7. unique_toolkit-0.6.0/unique_toolkit/app/schemas.py +135 -0
  8. unique_toolkit-0.6.0/unique_toolkit/chat/__init__.py +11 -0
  9. unique_toolkit-0.6.0/unique_toolkit/chat/constants.py +3 -0
  10. unique_toolkit-0.6.0/unique_toolkit/chat/functions.py +661 -0
  11. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/chat/schemas.py +11 -11
  12. unique_toolkit-0.6.0/unique_toolkit/chat/service.py +601 -0
  13. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/content/__init__.py +1 -0
  14. unique_toolkit-0.6.0/unique_toolkit/content/constants.py +2 -0
  15. unique_toolkit-0.6.0/unique_toolkit/content/functions.py +475 -0
  16. unique_toolkit-0.6.0/unique_toolkit/content/service.py +346 -0
  17. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/content/utils.py +32 -0
  18. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/embedding/__init__.py +3 -0
  19. unique_toolkit-0.6.0/unique_toolkit/embedding/constants.py +2 -0
  20. unique_toolkit-0.6.0/unique_toolkit/embedding/functions.py +79 -0
  21. unique_toolkit-0.6.0/unique_toolkit/embedding/service.py +96 -0
  22. unique_toolkit-0.6.0/unique_toolkit/evaluators/__init__.py +1 -0
  23. unique_toolkit-0.6.0/unique_toolkit/evaluators/constants.py +1 -0
  24. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/evaluators/context_relevancy/constants.py +3 -3
  25. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/evaluators/context_relevancy/utils.py +5 -2
  26. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/evaluators/hallucination/utils.py +2 -1
  27. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/language_model/__init__.py +1 -0
  28. unique_toolkit-0.6.0/unique_toolkit/language_model/constants.py +4 -0
  29. unique_toolkit-0.6.0/unique_toolkit/language_model/functions.py +362 -0
  30. unique_toolkit-0.6.0/unique_toolkit/language_model/service.py +377 -0
  31. unique_toolkit-0.6.0/unique_toolkit/short_term_memory/__init__.py +5 -0
  32. unique_toolkit-0.6.0/unique_toolkit/short_term_memory/constants.py +1 -0
  33. unique_toolkit-0.6.0/unique_toolkit/short_term_memory/functions.py +175 -0
  34. unique_toolkit-0.6.0/unique_toolkit/short_term_memory/service.py +183 -0
  35. unique_toolkit-0.5.55/unique_toolkit/app/schemas.py +0 -69
  36. unique_toolkit-0.5.55/unique_toolkit/chat/__init__.py +0 -10
  37. unique_toolkit-0.5.55/unique_toolkit/chat/service.py +0 -758
  38. unique_toolkit-0.5.55/unique_toolkit/content/service.py +0 -498
  39. unique_toolkit-0.5.55/unique_toolkit/embedding/service.py +0 -83
  40. unique_toolkit-0.5.55/unique_toolkit/language_model/service.py +0 -424
  41. unique_toolkit-0.5.55/unique_toolkit/short_term_memory/service.py +0 -57
  42. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/LICENSE +0 -0
  43. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/__init__.py +0 -0
  44. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/_common/_base_service.py +0 -0
  45. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/_common/_time_utils.py +0 -0
  46. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/_common/exception.py +0 -0
  47. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/_common/validators.py +0 -0
  48. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/app/init_logging.py +0 -0
  49. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/app/init_sdk.py +0 -0
  50. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/app/performance/async_tasks.py +0 -0
  51. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/app/performance/async_wrapper.py +0 -0
  52. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/app/verification.py +0 -0
  53. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/chat/state.py +0 -0
  54. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/chat/utils.py +0 -0
  55. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/content/schemas.py +0 -0
  56. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/embedding/schemas.py +0 -0
  57. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/embedding/utils.py +0 -0
  58. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/evaluators/config.py +0 -0
  59. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/evaluators/context_relevancy/prompts.py +0 -0
  60. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/evaluators/context_relevancy/service.py +0 -0
  61. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/evaluators/exception.py +0 -0
  62. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/evaluators/hallucination/constants.py +0 -0
  63. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/evaluators/hallucination/prompts.py +0 -0
  64. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/evaluators/hallucination/service.py +0 -0
  65. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/evaluators/output_parser.py +0 -0
  66. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/evaluators/schemas.py +0 -0
  67. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/language_model/builder.py +0 -0
  68. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/language_model/infos.py +0 -0
  69. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/language_model/prompt.py +0 -0
  70. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/language_model/schemas.py +0 -0
  71. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/language_model/utils.py +0 -0
  72. {unique_toolkit-0.5.55 → unique_toolkit-0.6.0}/unique_toolkit/short_term_memory/schemas.py +0 -0
@@ -5,6 +5,21 @@ 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.6.0] - 2025-02-21
9
+ - make for each domain, its base functionality accessible from `functions.py`
10
+ - make it possible to instantiate the domain services directly from different event types, inhereted from common `BaseEvent`
11
+ - extend the functionalities in the ShortTermMemoryService by adding the `find_latest_memory` and `create_memory` functions for sync and async usage
12
+ - remove logger dependency from service classes
13
+ - marked deprecated:
14
+ - `from_chat_event` in ShortTermMemoryService, use `ShortTermMemoryService(event=event)` instead
15
+ - `complete_async_util` in LanguageModelService, use `functions.complete_async` instead
16
+ - `stream_complete_async` in LanguageModelService, use `stream_complete_to_chat_async` instead
17
+ - `stream_complete` in LanguageModelService, use `stream_complete_to_chat` instead
18
+ - `Event` and nested schemas in `app`, use `ChatEvent` and `ChatEventUserMessage`, `ChatEventAssistantMessage` and `ChatEventToolMessage` instead
19
+
20
+ ## [0.5.56] - 2025-02-19
21
+ - Add `MessageAssessment` title field and change label values
22
+
8
23
  ## [0.5.55] - 2025-02-18
9
24
  - Log `contentId` for better debugging
10
25
 
@@ -35,7 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
35
50
  - Move tool_calls to assistant message as not needed anywhere else.
36
51
 
37
52
  ## [0.5.46] - 2025-01-07
38
- - Added `AZURE_GPT_35_TURBO_0125` as new model into toolkit.
53
+ - Added `AZURE_GPT_35_TURBO_0125` as new model into toolkit.
39
54
 
40
55
  ## [0.5.45] - 2025-01-03
41
56
  - Added `ShortTermMemoryService` class to handle short term memory.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unique_toolkit
3
- Version: 0.5.55
3
+ Version: 0.6.0
4
4
  Summary:
5
5
  License: Proprietary
6
6
  Author: Martin Fadler
@@ -29,10 +29,9 @@ The Toolkit is structured along the following domains:
29
29
  - `unique_toolkit.content`
30
30
  - `unique_toolkit.embedding`
31
31
  - `unique_toolkit.language_model`
32
+ - `unique_toolkit.short_term_memory`
32
33
 
33
- Each domain comprises a service class (in `service.py`) which encapsulates the basic functionalities to interact with the domain entities, the schemas
34
- (in `schemas.py`) used in the service and required for interacting with the service functions, utility functions (in `utils.py`) which give additional
35
- functionality to interact with the domain entities (all domains except embedding) and other domain specific functionalities which are explained in the respective domain documentation.
34
+ Each domain comprises a set of functions (in `functions.py`) and a service class (in `service.py`) which encapsulates the basic functionalities to interact with the domain entities, the schemas (in `schemas.py`) used in the service and required for interacting with the service functions, utility functions (in `utils.py`) which give additional functionality to interact with the domain entities (all domains except embedding) and other domain specific functionalities which are explained in the respective domain documentation.
36
35
 
37
36
  In addition, the `unique_toolkit.app` module provides functions to initialize apps that interact with the Unique platform. It also includes some utility functions to run async tasks in parallel (async webserver and app implementation required).
38
37
 
@@ -55,14 +54,16 @@ The `unique_toolkit.app` module encompasses functions for initializing and secur
55
54
 
56
55
  The `unique_toolkit.chat` module encompasses all chat related functionality.
57
56
 
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.
57
+ - `functions.py` comprises the functions to manage and load the chat history and interact with the chat ui, e.g., creating a new assistant message.
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.
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
63
63
 
64
64
  The `unique_toolkit.content` module encompasses all content related functionality. Content can be any type of textual data that is stored in the Knowledgebase on the Unique platform. During the ingestion of the content, the content is parsed, split in chunks, indexed, and stored in the database.
65
65
 
66
+ - `functions.py` comprises the functions to manage and load the chat history and interact with the chat ui, e.g., creating a new assistant message.
66
67
  - `service.py` comprises the ContentService and provides an interface to interact with the content, e.g., search content, search content chunks, upload and download content.
67
68
  - `schemas.py` comprises all relevant schemas, e.g., Content and ContentChunk, used in the ContentService.
68
69
  - `utils.py` comprise utility functions to manipulate Content and ContentChunk objects, e.g., sort_content_chunks and merge_content_chunks.
@@ -71,6 +72,7 @@ The `unique_toolkit.content` module encompasses all content related functionalit
71
72
 
72
73
  The `unique_toolkit.embedding` module encompasses all embedding related functionality. Embeddings are used to represent textual data in a high-dimensional space. The embeddings can be used to calculate the similarity between two texts, for instance.
73
74
 
75
+ - `functions.py` comprises the functions to embed text and calculate the similarity between two texts.
74
76
  - `service.py` encompasses the EmbeddingService and provides an interface to interact with the embeddings, e.g., embed text and calculate the similarity between two texts.
75
77
  - `schemas.py` comprises all relevant schemas, e.g., Embeddings, used in the EmbeddingService.
76
78
 
@@ -80,10 +82,19 @@ The `unique_toolkit.language_model` module encompasses all language model relate
80
82
  Unique platform.
81
83
 
82
84
  - `infos.py` comprises the information on all language models deployed through the Unique platform. We recommend to use the LanguageModel class, initialized with the LanguageModelName, e.g., LanguageModel(LanguageModelName.AZURE_GPT_35_TURBO_0125) to get the information on the specific language model like the name, version, token limits or retirement date.
85
+ - `functions.py` comprises the functions to complete and stream complete to chat.
83
86
  - `service.py` comprises the LanguageModelService and provides an interface to interact with the language models, e.g., complete or stream_complete.
84
87
  - `schemas.py` comprises all relevant schemas, e.g., LanguageModelResponse, used in the LanguageModelService.
85
88
  - `utils.py` comprises utility functions to parse the output of the language model, e.g., convert_string_to_json finds and parses the last json object in a string.
86
89
 
90
+ ## Short Term Memory
91
+
92
+ The `unique_toolkit.short_term_memory` module encompasses all short term memory related functionality.
93
+
94
+ - `functions.py` comprises the functions to manage and load the chat history and interact with the chat ui, e.g., creating a new assistant message.
95
+ - `service.py` comprises the ShortTermMemoryService and provides an interface to interact with the short term memory, e.g., create memory.
96
+ - `schemas.py` comprises all relevant schemas, e.g., ShortTermMemory, used in the ShortTermMemoryService.
97
+
87
98
  # Development instructions
88
99
 
89
100
  1. Install poetry on your system (through `brew` or `pipx`).
@@ -100,6 +111,21 @@ All notable changes to this project will be documented in this file.
100
111
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
101
112
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
102
113
 
114
+ ## [0.6.0] - 2025-02-21
115
+ - make for each domain, its base functionality accessible from `functions.py`
116
+ - make it possible to instantiate the domain services directly from different event types, inhereted from common `BaseEvent`
117
+ - extend the functionalities in the ShortTermMemoryService by adding the `find_latest_memory` and `create_memory` functions for sync and async usage
118
+ - remove logger dependency from service classes
119
+ - marked deprecated:
120
+ - `from_chat_event` in ShortTermMemoryService, use `ShortTermMemoryService(event=event)` instead
121
+ - `complete_async_util` in LanguageModelService, use `functions.complete_async` instead
122
+ - `stream_complete_async` in LanguageModelService, use `stream_complete_to_chat_async` instead
123
+ - `stream_complete` in LanguageModelService, use `stream_complete_to_chat` instead
124
+ - `Event` and nested schemas in `app`, use `ChatEvent` and `ChatEventUserMessage`, `ChatEventAssistantMessage` and `ChatEventToolMessage` instead
125
+
126
+ ## [0.5.56] - 2025-02-19
127
+ - Add `MessageAssessment` title field and change label values
128
+
103
129
  ## [0.5.55] - 2025-02-18
104
130
  - Log `contentId` for better debugging
105
131
 
@@ -130,7 +156,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
130
156
  - Move tool_calls to assistant message as not needed anywhere else.
131
157
 
132
158
  ## [0.5.46] - 2025-01-07
133
- - Added `AZURE_GPT_35_TURBO_0125` as new model into toolkit.
159
+ - Added `AZURE_GPT_35_TURBO_0125` as new model into toolkit.
134
160
 
135
161
  ## [0.5.45] - 2025-01-03
136
162
  - Added `ShortTermMemoryService` class to handle short term memory.
@@ -7,10 +7,9 @@ The Toolkit is structured along the following domains:
7
7
  - `unique_toolkit.content`
8
8
  - `unique_toolkit.embedding`
9
9
  - `unique_toolkit.language_model`
10
+ - `unique_toolkit.short_term_memory`
10
11
 
11
- Each domain comprises a service class (in `service.py`) which encapsulates the basic functionalities to interact with the domain entities, the schemas
12
- (in `schemas.py`) used in the service and required for interacting with the service functions, utility functions (in `utils.py`) which give additional
13
- functionality to interact with the domain entities (all domains except embedding) and other domain specific functionalities which are explained in the respective domain documentation.
12
+ Each domain comprises a set of functions (in `functions.py`) and a service class (in `service.py`) which encapsulates the basic functionalities to interact with the domain entities, the schemas (in `schemas.py`) used in the service and required for interacting with the service functions, utility functions (in `utils.py`) which give additional functionality to interact with the domain entities (all domains except embedding) and other domain specific functionalities which are explained in the respective domain documentation.
14
13
 
15
14
  In addition, the `unique_toolkit.app` module provides functions to initialize apps that interact with the Unique platform. It also includes some utility functions to run async tasks in parallel (async webserver and app implementation required).
16
15
 
@@ -33,14 +32,16 @@ The `unique_toolkit.app` module encompasses functions for initializing and secur
33
32
 
34
33
  The `unique_toolkit.chat` module encompasses all chat related functionality.
35
34
 
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.
35
+ - `functions.py` comprises the functions to manage and load the chat history and interact with the chat ui, e.g., creating a new assistant message.
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.
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
41
41
 
42
42
  The `unique_toolkit.content` module encompasses all content related functionality. Content can be any type of textual data that is stored in the Knowledgebase on the Unique platform. During the ingestion of the content, the content is parsed, split in chunks, indexed, and stored in the database.
43
43
 
44
+ - `functions.py` comprises the functions to manage and load the chat history and interact with the chat ui, e.g., creating a new assistant message.
44
45
  - `service.py` comprises the ContentService and provides an interface to interact with the content, e.g., search content, search content chunks, upload and download content.
45
46
  - `schemas.py` comprises all relevant schemas, e.g., Content and ContentChunk, used in the ContentService.
46
47
  - `utils.py` comprise utility functions to manipulate Content and ContentChunk objects, e.g., sort_content_chunks and merge_content_chunks.
@@ -49,6 +50,7 @@ The `unique_toolkit.content` module encompasses all content related functionalit
49
50
 
50
51
  The `unique_toolkit.embedding` module encompasses all embedding related functionality. Embeddings are used to represent textual data in a high-dimensional space. The embeddings can be used to calculate the similarity between two texts, for instance.
51
52
 
53
+ - `functions.py` comprises the functions to embed text and calculate the similarity between two texts.
52
54
  - `service.py` encompasses the EmbeddingService and provides an interface to interact with the embeddings, e.g., embed text and calculate the similarity between two texts.
53
55
  - `schemas.py` comprises all relevant schemas, e.g., Embeddings, used in the EmbeddingService.
54
56
 
@@ -58,10 +60,19 @@ The `unique_toolkit.language_model` module encompasses all language model relate
58
60
  Unique platform.
59
61
 
60
62
  - `infos.py` comprises the information on all language models deployed through the Unique platform. We recommend to use the LanguageModel class, initialized with the LanguageModelName, e.g., LanguageModel(LanguageModelName.AZURE_GPT_35_TURBO_0125) to get the information on the specific language model like the name, version, token limits or retirement date.
63
+ - `functions.py` comprises the functions to complete and stream complete to chat.
61
64
  - `service.py` comprises the LanguageModelService and provides an interface to interact with the language models, e.g., complete or stream_complete.
62
65
  - `schemas.py` comprises all relevant schemas, e.g., LanguageModelResponse, used in the LanguageModelService.
63
66
  - `utils.py` comprises utility functions to parse the output of the language model, e.g., convert_string_to_json finds and parses the last json object in a string.
64
67
 
68
+ ## Short Term Memory
69
+
70
+ The `unique_toolkit.short_term_memory` module encompasses all short term memory related functionality.
71
+
72
+ - `functions.py` comprises the functions to manage and load the chat history and interact with the chat ui, e.g., creating a new assistant message.
73
+ - `service.py` comprises the ShortTermMemoryService and provides an interface to interact with the short term memory, e.g., create memory.
74
+ - `schemas.py` comprises all relevant schemas, e.g., ShortTermMemory, used in the ShortTermMemoryService.
75
+
65
76
  # Development instructions
66
77
 
67
78
  1. Install poetry on your system (through `brew` or `pipx`).
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "unique_toolkit"
3
- version = "0.5.55"
3
+ version = "0.6.0"
4
4
  description = ""
5
5
  authors = [
6
6
  "Martin Fadler <martin.fadler@unique.ch>",
@@ -0,0 +1,21 @@
1
+ from typing import Sequence, TypeVar
2
+
3
+ T = TypeVar("T")
4
+
5
+
6
+ def validate_required_values(values: Sequence[T | None]) -> Sequence[T]:
7
+ """
8
+ Validates that all values are not None and returns the sequence.
9
+
10
+ Args:
11
+ values: Sequence of possibly None values
12
+
13
+ Returns:
14
+ The same sequence, now guaranteed to have no None values
15
+
16
+ Raises:
17
+ ValueError: If any values are None
18
+ """
19
+ if any(v is None for v in values):
20
+ raise ValueError("Required values cannot be None")
21
+ return values # type: ignore # We know these aren't None after validation
@@ -5,6 +5,24 @@ from .performance.async_tasks import (
5
5
  run_async_tasks_parallel as run_async_tasks_parallel,
6
6
  )
7
7
  from .performance.async_wrapper import to_async as to_async
8
+ from .schemas import (
9
+ BaseEvent as BaseEvent,
10
+ )
11
+ from .schemas import (
12
+ ChatEvent as ChatEvent,
13
+ )
14
+ from .schemas import (
15
+ ChatEventAdditionalParameters as ChatEventAdditionalParameters,
16
+ )
17
+ from .schemas import (
18
+ ChatEventAssistantMessage as ChatEventAssistantMessage,
19
+ )
20
+ from .schemas import (
21
+ ChatEventPayload as ChatEventPayload,
22
+ )
23
+ from .schemas import (
24
+ ChatEventUserMessage as ChatEventUserMessage,
25
+ )
8
26
  from .schemas import (
9
27
  Event as Event,
10
28
  )
@@ -23,3 +41,5 @@ from .schemas import (
23
41
  from .verification import (
24
42
  verify_signature_and_construct_event as verify_signature_and_construct_event,
25
43
  )
44
+
45
+ DOMAIN_NAME = "app"
@@ -0,0 +1,135 @@
1
+ from enum import StrEnum
2
+ from typing import Any, Optional
3
+
4
+ from humps import camelize
5
+ from pydantic import BaseModel, ConfigDict
6
+ from typing_extensions import deprecated
7
+
8
+ # set config to convert camelCase to snake_case
9
+ model_config = ConfigDict(
10
+ alias_generator=camelize,
11
+ populate_by_name=True,
12
+ arbitrary_types_allowed=True,
13
+ )
14
+
15
+
16
+ class EventName(StrEnum):
17
+ EXTERNAL_MODULE_CHOSEN = "unique.chat.external-module.chosen"
18
+
19
+
20
+ class BaseEvent(BaseModel):
21
+ model_config = model_config
22
+
23
+ id: str
24
+ event: str
25
+ user_id: str
26
+ company_id: str
27
+
28
+
29
+ ###
30
+ # ChatEvent schemas
31
+ ###
32
+
33
+
34
+ class ChatEventUserMessage(BaseModel):
35
+ model_config = model_config
36
+
37
+ id: str
38
+ text: str
39
+ original_text: str
40
+ created_at: str
41
+ language: str
42
+
43
+
44
+ @deprecated(
45
+ "Use `ChatEventUserMessage` instead. "
46
+ "This class will be removed in the next major version."
47
+ )
48
+ class EventUserMessage(ChatEventUserMessage):
49
+ """Deprecated: Use `ChatEventUserMessage` instead."""
50
+
51
+ pass
52
+
53
+
54
+ class ChatEventAssistantMessage(BaseModel):
55
+ model_config = model_config
56
+
57
+ id: str
58
+ created_at: str
59
+
60
+
61
+ @deprecated(
62
+ "Use `ChatEventAssistantMessage` instead. "
63
+ "This class will be removed in the next major version."
64
+ )
65
+ class EventAssistantMessage(ChatEventAssistantMessage):
66
+ """Deprecated: Use `ChatEventAssistantMessage` instead."""
67
+
68
+ pass
69
+
70
+
71
+ class ChatEventAdditionalParameters(BaseModel):
72
+ model_config = model_config
73
+
74
+ translate_to_language: Optional[str] = None
75
+ content_id_to_translate: Optional[str] = None
76
+
77
+
78
+ @deprecated(
79
+ "Use `ChatEventAdditionalParameters` instead. "
80
+ "This class will be removed in the next major version."
81
+ )
82
+ class EventAdditionalParameters(ChatEventAdditionalParameters):
83
+ """Deprecated: Use `ChatEventAdditionalParameters` instead."""
84
+
85
+ pass
86
+
87
+
88
+ class ChatEventPayload(BaseModel):
89
+ model_config = model_config
90
+
91
+ name: str
92
+ description: str
93
+ configuration: dict[str, Any]
94
+ chat_id: str
95
+ assistant_id: str
96
+ user_message: ChatEventUserMessage
97
+ assistant_message: ChatEventAssistantMessage
98
+ text: Optional[str] = None
99
+ additional_parameters: Optional[ChatEventAdditionalParameters] = None
100
+ user_metadata: Optional[dict[str, Any]] = None
101
+ tool_parameters: Optional[dict[str, Any]] = None
102
+ metadata_filter: Optional[dict[str, Any]] = None
103
+
104
+
105
+ @deprecated("""UUse `ChatEventPayload` instead.
106
+ This class will be removed in the next major version.""")
107
+ class EventPayload(ChatEventPayload):
108
+ user_message: EventUserMessage
109
+ assistant_message: EventAssistantMessage
110
+ additional_parameters: Optional[EventAdditionalParameters] = None
111
+
112
+
113
+ @deprecated(
114
+ """Use the more specific `ChatEvent` instead that has the same properties. \
115
+ This class will be removed in the next major version."""
116
+ )
117
+ class Event(BaseModel):
118
+ model_config = model_config
119
+
120
+ id: str
121
+ event: EventName
122
+ user_id: str
123
+ company_id: str
124
+ payload: EventPayload
125
+ created_at: Optional[int] = None
126
+ version: Optional[str] = None
127
+
128
+
129
+ class ChatEvent(BaseEvent):
130
+ model_config = model_config
131
+
132
+ event: EventName
133
+ payload: ChatEventPayload
134
+ created_at: Optional[int] = None
135
+ version: Optional[str] = None
@@ -0,0 +1,11 @@
1
+ from .constants import DOMAIN_NAME as DOMAIN_NAME
2
+ from .schemas import ChatMessage as ChatMessage
3
+ from .schemas import ChatMessageAssessment as ChatMessageAssessment
4
+ from .schemas import ChatMessageAssessmentLabel as ChatMessageAssessmentLabel
5
+ from .schemas import ChatMessageAssessmentStatus as ChatMessageAssessmentStatus
6
+ from .schemas import ChatMessageAssessmentType as ChatMessageAssessmentType
7
+ from .schemas import ChatMessageRole as ChatMessageRole
8
+ from .service import ChatService as ChatService
9
+ from .utils import (
10
+ convert_chat_history_to_injectable_string as convert_chat_history_to_injectable_string,
11
+ )
@@ -0,0 +1,3 @@
1
+ DOMAIN_NAME = "chat"
2
+ DEFAULT_PERCENT_OF_MAX_TOKENS = 0.15
3
+ DEFAULT_MAX_MESSAGES = 4