Skip to main content

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

Each domain comprises 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.

  • 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.
  • 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.

  • 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.

  • 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_16K) to get the information on the specific language model like the name, version, token limits or retirement date.
  • service.py comprises the LanguageModelService and provides an interface to interact with the language models, e.g., complete or stream_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.

Development instructions

  1. Install poetry on your system (through brew or pipx).

  2. 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.

  3. If you then run python --version in your terminal, you should be able to see python version as specified in .python-version.

  4. 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.5.30] - 2024-10-28

  • Correctly use temperature parameter in LanguageModelService.complete and LanguageModelService.complete_async methods

[0.5.29] - 2024-10-28

  • Allow numbers in LanguageModelTool name

[0.5.28] - 2024-10-23

  • Correctly use temperature parameter in LanguageModelService.stream_complete and LanguageModelService.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 to ContentService

[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 the originalText on the database is populated with the text

[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 and create_assistant_message. This parameter allows the completedAt timestamp on the database to be updated when set to True.

[0.5.22] - 2024-09-17

  • Add LanguageModelToolMessage as additional LanguageModelMessage

[0.5.21] - 2024-09-16

  • Add tool as new role to ChatMessage, as well as tool_calls and tool_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 and metadata_filter to EventPayload.
  • Adds update_debug_info and modify_user_message (and the corresponding async variants) to ChatService.

[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 of LanguageModelName enum for parameter model_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 to LanguageModelToolParameterProperty schema to add support for parameters with list types.
  • Added returns to LanguageModelTool schema to describe the return types of tool calls.

[0.5.12] - 2024-08-7

  • added completedAt datetime to unique_sdk.Message.modify and unique_sdk.Message.modify_async
  • added original_text and language to EventUserMessage

[0.5.11] - 2024-08-6

  • made all domain specific functions and classes directly importable from unique_toolkit.[DOMAIN_NAME]
  • renamed RerankerConfig to ContentRerankerConfig
  • renamed get_cosine_similarity to calculate_cosine_similarity and moved it to unique_toolkit.embedding.utils
  • moved calculate_tokens from unique_toolkit.content.utils to unique_toolkit.embedding.utils
  • disabled deprecation warning in LanguageModel
  • added additional_parameters to event
  • removed ChatState and use Event instead

[0.5.10] - 2024-08-6

  • fix content schema

[0.5.9] - 2024-08-6

  • added created_at and updated_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 and scope_ids attributes from ChatState class
  • Replace AsyncExecutor by simpler utility function run_async_tasks_parallel

[0.5.6] - 2024-07-30

  • Bug fix: ContentService.search_content_chunks and it's async equivalent now accept None as a valid parameter value for scope_ids.

[0.5.5] - 2024-07-30

  • Added parameters to ContentService.search_content_chunks and ContentService.async_search_content_chunks
    • reranker_config to optinally rerank the search results
    • search_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 the ChatState class.
    • service.py containing the ChatService class for managing chat interactions.
    • schemas.py containing relevant schemas such as ChatMessage.
    • utils.py with utility functions for chat interactions.
  • Added unique_toolkit.content module with the following components:

    • service.py containing the ContentService class for interacting with content.
    • schemas.py containing relevant schemas such as Content and ContentChunk.
    • utils.py with utility functions for manipulating content objects.
  • Added unique_toolkit.embedding module with the following components:

    • service.py containing the EmbeddingService class for working with embeddings.
    • schemas.py containing relevant schemas such as Embeddings.
  • 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 the LanguageModelService class for interacting with language models.
    • schemas.py containing relevant schemas such as LanguageModelResponse.
    • utils.py with utility functions for parsing language model output.

[0.0.2] - 2024-07-10

  • Initial release of unique_toolkit.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unique_toolkit-0.5.30.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

unique_toolkit-0.5.30-py3-none-any.whl (44.0 kB view details)

Uploaded Python 3

File details

Details for the file unique_toolkit-0.5.30.tar.gz.

File metadata

  • Download URL: unique_toolkit-0.5.30.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for unique_toolkit-0.5.30.tar.gz
Algorithm Hash digest
SHA256 161753d6943fe4a786568661e99cacf3232894e60072e250a4c8bdd941914ac9
MD5 f9e4634184c1cd50095a7dd47f4aff86
BLAKE2b-256 05f58c145aa5d70c3975cc2cbba8dbca8d3bf95c10694fc11ec48490a0c0f3aa

See more details on using hashes here.

File details

Details for the file unique_toolkit-0.5.30-py3-none-any.whl.

File metadata

  • Download URL: unique_toolkit-0.5.30-py3-none-any.whl
  • Upload date:
  • Size: 44.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for unique_toolkit-0.5.30-py3-none-any.whl
Algorithm Hash digest
SHA256 98f396465363d814f1e69c826795efb932fe8d6f043fc9403c3dedee5fd87362
MD5 b5b6bf5143d29c169c821605b23b074f
BLAKE2b-256 037d2b1442a9e975b1c36b9a3e6ddc7317e1b8bcacf080215e8f7cae3e08db88

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page