Skip to main content

Sinapsis base templates for LLM text completion.

Project description



Sinapsis Chatbots Base

Package with base support for chat completion tasks

🐍 Installation🚀 Features📚 Usage example📙 Documentation🔍 License

The sinapsis-chatbots-base module provides core functionality for llm chat completion tasks

🐍 Installation

Install using your package manager of choice. We encourage the use of uv

Example with uv:

  uv pip install sinapsis-chatbots-base --extra-index-url https://pypi.sinapsis.tech

or with raw pip:

  pip install sinapsis-chatbots-base --extra-index-url https://pypi.sinapsis.tech

[!IMPORTANT] Templates may require extra dependencies. For development, we recommend installing the package with all the optional dependencies:

with uv:

  uv pip install sinapsis-chatbots-base[all] --extra-index-url https://pypi.sinapsis.tech

or with raw pip:

  pip install sinapsis-chatbots-base[all] --extra-index-url https://pypi.sinapsis.tech

🚀 Features

LLMTextCompletionBase

Base class for all templates intended to perform chat (text) completion tasks.

These attributes apply to LLMTextCompletionBase:

  • init_args(LLMInitArgs, required): Base model arguments, including the 'llm_model_name'.
  • completion_args(LLMCompletionArgs, optional): Base generation arguments, including 'max_tokens', 'temperature', 'top_p', and 'top_k'.
  • chat_history_key(str, optional): Key in the packet's generic_data to find the conversation history.
  • rag_context_key(str, optional): Key in the packet's generic_data to find RAG context to inject.
  • system_prompt(str | Path, optional): The system prompt (or path to one) to instruct the model.
  • pattern(dict, optional): A regex pattern used to post-process the model's response.
  • keep_before(bool, optional): If True, keeps text before the 'pattern' match; otherwise, keeps text after.
QueryContextualize

A base class for contextualizing queries based on certain keywords.

These attributes apply to QueryContextualize:

  • keywords(list[str], required): A list of keywords to be used for retrieving context.
QueryContextualizeFromFile

A subclass of QueryContextualize that retrieves context from files loaded into the generic_data.

These attributes apply to QueryContextualizeFromFile:

  • keywords(list[str], required): A list of keywords to be used for retrieving context.
  • generic_keys(list[str], required): A list of keywords that can be used to retrieve specific context data from the generic_data of the container.

[!TIP] Use CLI command sinapsis info --all-template-names to show a list with all the available Template names installed with Sinapsis Data Tools.

[!TIP] Use CLI command sinapsis info --example-template-config TEMPLATE_NAME to produce an example Agent config for the Template specified in TEMPLATE_NAME.

For example, for QueryContextualizeFromFile use sinapsis info --example-template-config QueryContextualizeFromFile to produce the following example config:

agent:
  name: my_test_agent
templates:
- template_name: InputTemplate
  class_name: InputTemplate
  attributes: {}
- template_name: QueryContextualizeFromFile
  class_name: QueryContextualizeFromFile
  template_input: InputTemplate
  attributes:
    keywords: '`replace_me:list[str]`'
    generic_keys: '`replace_me:list[str]`'

📚 Usage example

The following agent passes a text message through a TextPacket and checks if there is context with the chosen keyword
Config
agent:
  name: chat_completion
  description: Agent with a chatbot that makes a call to the LLM model using a context uploaded from a file

templates:
- template_name: InputTemplate
  class_name: InputTemplate
  attributes: {}

- template_name: PyPDFLoaderWrapper
  class_name: PyPDFLoaderWrapper
  template_input: InputTemplate
  attributes:
    add_document_as_text_packet: false
    pypdfloader_init:
      file_path: '/path/to/a/file.pdf'

- template_name: TextInput
  class_name: TextInput
  template_input: PyPDFLoaderWrapper
  attributes:
    text: what is AI?

- template_name: QueryContextualizeFromFile
  class_name: QueryContextualizeFromFile
  template_input: TextInput
  attributes:
    keywords: 'Artificial Intelligence'
    generic_keys: 'PyPDFLoaderWrapper'

📙 Documentation

Documentation for this and other sinapsis packages is available on the sinapsis website

Tutorials for different projects within sinapsis are available at sinapsis tutorials page

🔍 License

This project is licensed under the AGPLv3 license, which encourages open collaboration and sharing. For more details, please refer to the LICENSE file.

For commercial use, please refer to our official Sinapsis website for information on obtaining a commercial license.

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

sinapsis_chatbots_base-0.1.10.tar.gz (25.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sinapsis_chatbots_base-0.1.10-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

Details for the file sinapsis_chatbots_base-0.1.10.tar.gz.

File metadata

File hashes

Hashes for sinapsis_chatbots_base-0.1.10.tar.gz
Algorithm Hash digest
SHA256 24ec0d84f969b20059b2ecd6abe66f2cb0d3975d2dff1440bac61ea105d8dc00
MD5 2c05c7ca49a000339a67aced2b0c473a
BLAKE2b-256 89fff09ee8134f8fb2f19bb17651b739b7a852943a1fe4d12d9da792cd2162e4

See more details on using hashes here.

File details

Details for the file sinapsis_chatbots_base-0.1.10-py3-none-any.whl.

File metadata

File hashes

Hashes for sinapsis_chatbots_base-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 9b385a3ee49fc6f9440d1dd1d7875168edc27b5f6a2cd27d709e8303a0e5d2a9
MD5 1f588fd0528962eed60b049985eded30
BLAKE2b-256 7d2bba4ce5b9027ae7d96c6f882967536217c1d91948ad418a3567a3506e61ae

See more details on using hashes here.

Supported by

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