No project description provided
Project description
Unique Toolkit
This package provides highlevel abstractions and methods on top of unique_sdk
to ease application development for the Unique Platform.
The Toolkit is structured along the following domains:
unique_toolkit.chat
unique_toolkit.content
unique_toolkit.embedding
unique_toolkit.language_model
unique_toolkit.short_term_memory
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.
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).
Changelog
See the CHANGELOG.md file for details on changes and version history.
Domains
App
The unique_toolkit.app
module encompasses functions for initializing and securing apps that will interact with the Unique platform.
init_logging.py
can be used to initalize the logger either with unique dictConfig or an any other dictConfig.init_sdk.py
can be used to initialize the sdk using the correct env variables and retrieving the endpoint secret.schemas.py
contains the Event schema which can be used to parse and validate the unique.chat.external-module.chosen event.verification.py
can be used to verify the endpoint secret and construct the event.
Chat
The unique_toolkit.chat
module encompasses all chat related functionality.
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.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 and stream complete.schemas.py
comprises all relevant schemas, e.g., ChatMessage, used in the ChatService.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.
Content
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.
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.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.schemas.py
comprises all relevant schemas, e.g., Content and ContentChunk, used in the ContentService.utils.py
comprise utility functions to manipulate Content and ContentChunk objects, e.g., sort_content_chunks and merge_content_chunks.
Embedding
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.
functions.py
comprises the functions to embed text and calculate the similarity between two texts.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.schemas.py
comprises all relevant schemas, e.g., Embeddings, used in the EmbeddingService.
Language Model
The unique_toolkit.language_model
module encompasses all language model related functionality and information on the different language models deployed through the
Unique platform.
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.functions.py
comprises the functions to complete and stream complete to chat.service.py
comprises the LanguageModelService and provides an interface to interact with the language models, e.g., complete.schemas.py
comprises all relevant schemas, e.g., LanguageModelResponse, used in the LanguageModelService.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.
Short Term Memory
The unique_toolkit.short_term_memory
module encompasses all short term memory related functionality.
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.service.py
comprises the ShortTermMemoryService and provides an interface to interact with the short term memory, e.g., create memory.schemas.py
comprises all relevant schemas, e.g., ShortTermMemory, used in the ShortTermMemoryService.
Development instructions
-
Install poetry on your system (through
brew
orpipx
). -
Install
pyenv
and install python 3.11.pyenv
is recommended as otherwise poetry uses the python version used to install itself and not the user preferred python version. -
If you then run
python --version
in your terminal, you should be able to see python version as specified in.python-version
. -
Then finally run
poetry install
to install the package and all dependencies.
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
[0.7.10] - 2025-04-22
- Deprecate internal variables of services
[0.7.9] - 2025-04-17
- add
AZURE_GPT_41_2025_0414
as part of the models
[0.7.8] - 2025-04-08
- add
AZURE_GPT_4o_2024_1120
as part of the models
[0.7.7] - 2025-04-11
- Add tool choice parameter to chat event payload
[0.7.6] - 2025-04-08
- De provisioning o1-preview
[0.7.5] - 2025-04-07
- Skip None values when serializing to json schema for LanguageModelInfo
[0.7.4] - 2025-03-20
- add
AZURE_GPT_45_PREVIEW_2025_0227
as part of the models
[0.7.3] - 2025-03-20
- Enable handling tool calls in message builder
[0.7.2] - 2025-03-17
- HotFix
ContentService.search_content_chunks
to usechat_id
from event if provided.
[0.7.1] - 2025-03-11
- Fix Breaking change:
ContentService.search_content_chunks
ContentService.search_content_chunks
now acceptschat_id
for the specific to handle chat_only instances
[0.7.0] - 2025-03-11
- Fix the issue with
ShortTermMemoryService.create_memory_async
addingself.chat_id
andself.message_id
as part of the parameter. - Breaking change:
ContentService.search_content_on_chat
now requires you pass in achat_id
for the specific chat instance
[0.6.9] - 2025-03-11
- Add o1-preview as part of the language model info, make the name consistent across board.
[0.6.8] - 2025-03-11
- Add
verify_request_and_construct_event
toverification.py
[0.6.7] - 2025-03-10
- Extend language model message builder
[0.6.6] - 2025-03-10
- Add o1, o1-mini and o3-mini models
- Remove deprecated gpt4 models
- Make token_limits and encoder a required attribute of LanguageModelInfo
[0.6.5] - 2025-03-04
- Add
upload_content_from_bytes
toContentService
- Add
download_content_to_bytes
toContentService
[0.6.3] - 2025-02-27
- Simplified imports for services.
from unique_toolkit.language_model import LanguageModelService
->from unique_toolkit import LanguageModelService
to reduce number of import lines.
[0.6.3] - 2025-02-26
- Add
builder
method toLanguageModelMessages
class
[0.6.2] - 2025-02-25
- Deprecate
LanguageModel
in favor ofLanguageModelInfo
LanguageModelTokenLimits
properties become mandatory, initialization allows- init with
token_limit
andfraction_input
orinput_token_limit
andoutput_token_limit
- only
input_token_limit
andoutput_token_limit
are members of model
- init with
[0.6.1] - 2025-02-25
- [BREAKING]
LanguageModelService.stream_complete
andLanguageModelService.stream_complete_async
are now moved toChatService.stream_complete
andChatService.stream_complete_async
. Correspondinglyassistant_message_id
anduser_message_id
are removed fromLanguageModelService
. - Add
create_user_message
andcreate_user_message_async
toChatService
(similar tocreate_assistant_message
andcreate_assistant_message_async
)
[0.6.0] - 2025-02-21
- make for each domain, its base functionality accessible from
functions.py
- make it possible to instantiate the domain services directly from different event types, inhereted from common
BaseEvent
- extend the functionalities in the ShortTermMemoryService by adding the
find_latest_memory
andcreate_memory
functions for sync and async usage - remove logger dependency from service classes
- marked deprecated:
from_chat_event
in ShortTermMemoryService, useShortTermMemoryService(event=event)
insteadcomplete_async_util
in LanguageModelService, usefunctions.complete_async
insteadstream_complete_async
in LanguageModelService, usestream_complete_to_chat_async
insteadstream_complete
in LanguageModelService, usestream_complete_to_chat
insteadEvent
and nested schemas inapp
, useChatEvent
andChatEventUserMessage
,ChatEventAssistantMessage
andChatEventToolMessage
instead
[0.5.56] - 2025-02-19
- Add
MessageAssessment
title field and change label values
[0.5.55] - 2025-02-18
- Log
contentId
for better debugging
[0.5.54] - 2025-02-10
- Add
created_at
,completed_at
,updated_at
andgpt_request
toChatMessage
schema.
[0.5.53] - 2025-02-01
- Correct
MessageAssessment
schemas
[0.5.52] - 2025-02-01
- Add
MessageAssessment
schemas and functions toChatService
to handle message assessments. - Fix
LanguageModelService.complete_async_util
to use the correct async method.
[0.5.51] - 2025-01-30
- Add missing structured output arguments in complete_async
[0.5.50] - 2025-01-30
- Add the possibility to define completion output structure through a pydantic class
[0.5.49] - 2025-01-24
- Add
parsed
andrefusal
toLanguageModelAssistantMessage
to support structured output
[0.5.48] - 2025-01-19
- Added the possibility define tool parameters with a json schema (Useful when generating tool parameters from a pydantic object)
[0.5.47] - 2025-01-07
- Added a message builder to build language model messages conveniently without importing all different messages.
- Move tool_calls to assistant message as not needed anywhere else.
[0.5.46] - 2025-01-07
- Added
AZURE_GPT_35_TURBO_0125
as new model into toolkit.
[0.5.45] - 2025-01-03
- Added
ShortTermMemoryService
class to handle short term memory.
[0.5.44] - 2024-12-18
- Add
event_constructor
toverify_signature_and_construct_event
to allow for custom event construction.
[0.5.43] - 2024-12-13
- Add
Prompt
class to handle templated prompts that can be formatted into LanguageModelSystemMessage and LanguageModelUserMessage.
[0.5.42] - 2024-12-11
- Update
LanguageModelTokenLimits
with fix avoiding floats for token
[0.5.41] - 2024-12-11
- Update
LanguageModelTokenLimits
includes a fraction_input now to always have input/output token limits available.
[0.5.40] - 2024-12-11
- Add
other_options
toLanguageModelService.complete
,LanguageModelService.complete_async
,LanguageModelService.stream_complete
andLanguageModelService.stream_complete_async
[0.5.39] - 2024-12-09
- Add
contentIds
toSearch.create
andSearch.create_async
- Use
metadata_filter
from event inContentService.search_content_chunks
andContentService.async_search_content_chunks
as default.
[0.5.38] - 2024-11-26
- Added string representation to
LanguageModelMessage
andLanguageModelMessages
class
[0.5.37] - 2024-11-26
content
parameter inChatService.modify_assistant_message
andChatService.modify_assistant_message_async
is now optional- Added optional parameter
original_content
toChatService.modify_assistant_message
andChatService.modify_assistant_message_async
- Added optional parameter
original_content
toChatService.create_assistant_message
andChatService.create_assistant_message_async
[0.5.36] - 2024-11-19
- Add possibility to return the response from the download file from chat request
- Add possibility to not specify a filename and use filename from response headers
[0.5.35] - 2024-11-18
- Add the possibilty to upload files without triggering ingestion by setting
skip_ingestion
toTrue
inContentService.upload_content
[0.5.34] - 2024-11-15
- Add
content_id_to_translate
toEventAdditionalParameters
[0.5.33] - 2024-10-30
- Force randomizing tool_call_id. This is helpful to better identify the tool_calls.
[0.5.32] - 2024-10-30
- Extending
LanguageModelName
with GPT-4o-2024-0806. This model is invoked usingAZURE_GPT_4o_2024_0806
.
[0.5.31] - 2024-10-29
- Adding support for function calling. Assistant message for tool calls can be directly created with
LanguageModelFunctionCall.create_assistant_message_from_tool_calls
. Better separation of schemas for different types ofLanguageModelMessages
.
[0.5.30] - 2024-10-28
- Correctly use
temperature
parameter inLanguageModelService.complete
andLanguageModelService.complete_async
methods
[0.5.29] - 2024-10-28
- Allow numbers in
LanguageModelTool
name
[0.5.28] - 2024-10-23
- Correctly use
temperature
parameter inLanguageModelService.stream_complete
andLanguageModelService.stream_complete_async
methods
[0.5.27] - 2024-10-22
- Add encoder_name to to language model info
- Verify tool name for
LanguageModelTool
to conform with frontent requirements. - Add
search_on_chat
toContentService
[0.5.26] - 2024-10-16
- Bump
unique_sdk
version
[0.5.25] - 2024-09-26
- Add
evaluators
for hallucination and context relevancy evaluation
[0.5.24] - 2024-09-26
- Add
originalText
to_construct_message_modify_params
and_construct_message_create_params
. This addition makes sure that theoriginalText
on the database is populated with thetext
[0.5.23] - 2024-09-23
- Add
set_completed_at
as a boolen parameter to the following functions:modify_user_message
,modify_user_message_async
,modify_assistant_message
,modify_assistant_message_async
,create_assistant_message
andcreate_assistant_message
. This parameter allows thecompletedAt
timestamp on the database to be updated when set to True.
[0.5.22] - 2024-09-17
- Add
LanguageModelToolMessage
as additionalLanguageModelMessage
[0.5.21] - 2024-09-16
- Add
tool
as new role toChatMessage
, as well astool_calls
andtool_call_id
as additional parameters
[0.5.20] - 2024-09-16
LanguageModelService
now supports complete_util_async that can be called without instantiating the class, currently being used in the Hallucination service and evaluation API
[0.5.19] - 2024-09-11
LanguageModelMessage
now supports content as a list of dictionary. Useful when adding image_url content along user message.
[0.5.18] - 2024-09-03
- Adds option to use
metadata_filter
with search. - Adds
user_metadata
,tool_parameters
andmetadata_filter
toEventPayload
. - Adds
update_debug_info
andmodify_user_message
(and the correspondingasync
variants) toChatService
.
[0.5.17] - 2024-08-30
- Add option to initiate
LanguageModel
with a string. - Add option to call
LanguageModelService
functions also with a string instead ofLanguageModelName
enum for parametermodel_name
.
[0.5.16] - 2024-08-29
- Fix
ContentService.upload_content
function.
[0.5.15] - 2024-08-27
- Possibility to specify root directory in
ContentService.download_content
[0.5.14] - 2024-08-26
- Add AZURE_GPT_4o_MINI_2024_0718 to language model infos
[0.5.13] - 2024-08-19
- Added
items
toLanguageModelToolParameterProperty
schema to add support for parameters with list types. - Added
returns
toLanguageModelTool
schema to describe the return types of tool calls.
[0.5.12] - 2024-08-7
- added
completedAt
datetime tounique_sdk.Message.modify
andunique_sdk.Message.modify_async
- added
original_text
andlanguage
toEventUserMessage
[0.5.11] - 2024-08-6
- made all domain specific functions and classes directly importable from
unique_toolkit.[DOMAIN_NAME]
- renamed
RerankerConfig
toContentRerankerConfig
- renamed
get_cosine_similarity
tocalculate_cosine_similarity
and moved it tounique_toolkit.embedding.utils
- moved
calculate_tokens
fromunique_toolkit.content.utils
tounique_toolkit.embedding.utils
- disabled deprecation warning in
LanguageModel
- added
additional_parameters
to event - removed
ChatState
and useEvent
instead
[0.5.10] - 2024-08-6
- fix content schema
[0.5.9] - 2024-08-6
- added
created_at
andupdated_at
to content schema
[0.5.8] - 2024-08-1
RerankerConfig
serialization alias added
[0.5.7] - 2024-07-31
- Replace mocked async service calls with async calls in
unique_sdk
- Change async methods name from
async_*
to*_async
- Remove
chat_only
andscope_ids
attributes fromChatState
class - Replace
AsyncExecutor
by simpler utility functionrun_async_tasks_parallel
[0.5.6] - 2024-07-30
- Bug fix:
ContentService.search_content_chunks
and it'sasync
equivalent now acceptNone
as a valid parameter value forscope_ids
.
[0.5.5] - 2024-07-30
- Added parameters to
ContentService.search_content_chunks
andContentService.async_search_content_chunks
reranker_config
to optinally rerank the search resultssearch_language
to specify a language for full-text-search
[0.5.4] - 2024-07-26
- correct ChatMessage schema
[0.5.3] - 2024-07-25
- downgrade numpy version to ^1.26.4 to be compatible with langchain libraries (require numpy<2.0)
[0.5.2] - 2024-07-25
- correct event schema
[0.5.1] - 2024-07-23
- correct documentation
[0.5.0] - 2024-07-23
Added
-
Added
unique_toolkit.app
module with the following components:init_logging.py
for initializing the logger.init_sdk.py
for initializing the SDK with environment variables.schemas.py
containing the Event schema.verification.py
for verifying the endpoint secret and constructing the event.
-
Added
unique_toolkit.chat
module with the following components:state.py
containing theChatState
class.service.py
containing theChatService
class for managing chat interactions.schemas.py
containing relevant schemas such asChatMessage
.utils.py
with utility functions for chat interactions.
-
Added
unique_toolkit.content
module with the following components:service.py
containing theContentService
class for interacting with content.schemas.py
containing relevant schemas such asContent
andContentChunk
.utils.py
with utility functions for manipulating content objects.
-
Added
unique_toolkit.embedding
module with the following components:service.py
containing theEmbeddingService
class for working with embeddings.schemas.py
containing relevant schemas such asEmbeddings
.
-
Added
unique_toolkit.language_model
module with the following components:infos.py
containing information on language models deployed on the Unique platform.service.py
containing theLanguageModelService
class for interacting with language models.schemas.py
containing relevant schemas such asLanguageModelResponse
.utils.py
with utility functions for parsing language model output.
[0.0.2] - 2024-07-10
- Initial release of
unique_toolkit
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file unique_toolkit-0.7.10.tar.gz
.
File metadata
- Download URL: unique_toolkit-0.7.10.tar.gz
- Upload date:
- Size: 51.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-1021-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65d158cd5ac43b4fc661c49e3c73dfe312ad8c131af3bdbdc5d70395fdf87e0c |
|
MD5 | 8e0fbdf7b57c4a1e5f50271da18143f7 |
|
BLAKE2b-256 | 313ad547e61dee5682b0e88801a02802fa54b01bfcd813cadac1b3929536eeff |
File details
Details for the file unique_toolkit-0.7.10-py3-none-any.whl
.
File metadata
- Download URL: unique_toolkit-0.7.10-py3-none-any.whl
- Upload date:
- Size: 67.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-1021-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44916a0f358a2d48fdff13c21d9d3fe11157cafc59baa058e118edb094e624d9 |
|
MD5 | 26f8b4d227d2cdadff8e48caf63a7e45 |
|
BLAKE2b-256 | 73e4f1546f8ddc532611855605dca9fce1a09e8b5fbc59850b094b15d184aa8d |