Skip to main content

Package with templates for AI-driven chatbots using Anthropic's Claude models

Project description



Sinapsis Anthropic

Templates for text-to-text and image-to-text conversational chatbots using Anthropic's Claude models.

🐍 Installation🚀 Features📚 Usage example🌐 Webapps 📙 Documentation🔍 License

The sinapsis-anthropic module provides a suite of templates for building text-to-text, image-to-text and mcp conversational chatbots using Anthropic's Claude models.

🐍 Installation

Install using your preferred package manager. We strongly recommend using uv. To install uv, refer to the official documentation.

Install with uv:

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

Or with raw pip:

pip install sinapsis-anthropic --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-anthropic[all] --extra-index-url https://pypi.sinapsis.tech

Or with raw pip:

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

🚀 Features

Templates Supported

  • AnthropicTextGeneration: Template for text and code generation with Claude models using the Anthropic API.

    Attributes
    • init_args(LLMInitArgs, required): Model arguments.
      • llm_model_name(str, required): The name of the Claude model to be used. To see the list of all available Claude models visit the official documentation.
    • completion_args(LLMCompletionArgs, required): Generation arguments to pass to the selected model.
      • temperature(float, optional): Controls randomness. 0.0 = deterministic, >0.0 = random. Defaults to 0.2.
      • top_p(float, optional): Nucleus sampling. Considers tokens with cumulative probability >= top_p. Defaults to 0.95.
      • top_k(int, optional): Top-k sampling. Considers the top 'k' most probable tokens. Defaults to 40.
      • max_tokens(int, required): The maximum number of new tokens to generate.
      • service_tier(Literal["auto", "standard_only"], optional): Specifies the service tier for the request. Defaults to 'standard_only'.
      • stop_sequences(list[str], optional): Custom text sequences that will cause the model to stop generating.
    • 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.
    • extended_thinking(AnthropicThinkingArgs, optional): Configuration for enabling or disabling the extended "thinking" feature.
      • type(Literal["enabled", "disabled"], optional): To disable or enable extended thinking. Defaults to 'disabled'.
      • budget_tokens(int, optional): The max tokens to use for internal reasoning. Must be ≥1024 and less than max_tokens. Defaults to 2048.
  • AnthropicMultiModal: Template for multimodal chat processing using Anthropic's Claude models.

    Attributes
    • init_args(LLMInitArgs, required): Model arguments.
      • llm_model_name(str, required): The name of the Claude model to be used. To see the list of all available Claude models visit the official documentation.
    • completion_args(LLMCompletionArgs, required): Generation arguments to pass to the selected model.
      • temperature(float, optional): Controls randomness. 0.0 = deterministic, >0.0 = random. Defaults to 0.2.
      • top_p(float, optional): Nucleus sampling. Considers tokens with cumulative probability >= top_p. Defaults to 0.95.
      • top_k(int, optional): Top-k sampling. Considers the top 'k' most probable tokens. Defaults to 40.
      • max_tokens(int, required): The maximum number of new tokens to generate.
      • service_tier(Literal["auto", "standard_only"], optional): Specifies the service tier for the request. Defaults to 'standard_only'.
      • stop_sequences(list[str], optional): Custom text sequences that will cause the model to stop generating.
    • 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.
    • extended_thinking(AnthropicThinkingArgs, optional): Configuration for enabling or disabling the extended "thinking" feature.
      • type(Literal["enabled", "disabled"], optional): To disable or enable extended thinking. Defaults to 'disabled'.
      • budget_tokens(int, optional): The max tokens to use for internal reasoning. Must be ≥1024 and less than max_tokens. Defaults to 2048.
  • AnthropicWithMCP: Template for chat processing using Anthropic's Claude models with MCP tool support.

    Attributes
    • init_args(LLMInitArgs, required): Model arguments.
      • llm_model_name(str, required): The name of the Claude model to be used. To see the list of all available Claude models visit the official documentation.
    • completion_args(LLMCompletionArgs, required): Generation arguments to pass to the selected model.
      • temperature(float, optional): Controls randomness. 0.0 = deterministic, >0.0 = random. Defaults to 0.2.
      • top_p(float, optional): Nucleus sampling. Considers tokens with cumulative probability >= top_p. Defaults to 0.95.
      • top_k(int, optional): Top-k sampling. Considers the top 'k' most probable tokens. Defaults to 40.
      • max_tokens(int, required): The maximum number of new tokens to generate.
      • service_tier(Literal["auto", "standard_only"], optional): Specifies the service tier for the request. Defaults to 'standard_only'.
      • stop_sequences(list[str], optional): Custom text sequences that will cause the model to stop generating.
    • 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.
    • extended_thinking(AnthropicThinkingArgs, optional): Configuration for enabling or disabling the extended "thinking" feature.
      • type(Literal["enabled", "disabled"], optional): To disable or enable extended thinking. Defaults to 'disabled'.
      • budget_tokens(int, optional): The max tokens to use for internal reasoning. Must be ≥1024 and less than max_tokens. Defaults to 2048.
    • tools_key (str, optional): Key used to extract the raw tools from the data container. Defaults to "".

[!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 AnthropicTextGeneration use sinapsis info --example-template-config AnthropicTextGeneration to produce the following example config:

agent:
  name: my_test_agent
templates:
- template_name: InputTemplate
  class_name: InputTemplate
  attributes: {}
- template_name: AnthropicTextGeneration
  class_name: AnthropicTextGeneration
  template_input: InputTemplate
  attributes:
    init_args:
      llm_model_name: 'claude-3-7-sonnet-latest'
    completion_args:
      temperature: 0.2
      top_p: 0.95
      top_k: 40
      max_tokens: 4000
      service_tier: standard_only
      stop_sequences: null
    chat_history_key: null
    rag_context_key: null
    system_prompt: null
    pattern: null
    keep_before: true
    extended_thinking:
      budget_tokens: 2048
      type: disabled
    web_search: false

📚 Usage example

This example shows how to use the AnthropicMultiModal template to process both text and image inputs to generate text responses. The following agent passes a text message through a TextPacket and an image though an ImagePacket and retrieves a response from a Claude model.

Config
agent:
  name: my_claude_agent
  description: Agent with support for text-to-text and image-to-text conversational chatbots using Anthropic's Claude models

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

- template_name: TextInput
  class_name: TextInput
  template_input: InputTemplate
  attributes:
    text: Describe this image in two sentences.

- template_name: FolderImageDatasetCV2
  class_name: FolderImageDatasetCV2
  template_input: TextInput
  attributes:
    load_on_init : True
    data_dir: './artifacts'
    pattern : 'sunset.jpeg'

- template_name: AnthropicMultiModal
  class_name: AnthropicMultiModal
  template_input: FolderImageDatasetCV2
  attributes:
    init_args:
      llm_model_name: claude-3-opus-20240229
    completion_args:
      max_tokens: 4000
      temperature: 1
      service_tier: standard_only

This configuration defines an agent and a sequence of templates for a multimodal conversational chatbot using an Anthropic's Claude model.

[!IMPORTANT] The TextInput and FolderImageDatasetCV2 templates correspond to sinapsis-data-readers. If you want to use the example, please make sure you install the package.

To run the config, use the CLI:

sinapsis run name_of_config.yml

🌐 Webapp

This module includes a webapp to interact with the model

[!IMPORTANT] To run the app you first need to clone this repository:

git clone git@github.com:Sinapsis-ai/sinapsis-chatbots.git
cd sinapsis-chatbots

[!NOTE] If you'd like to enable external app sharing in Gradio, export GRADIO_SHARE_APP=True

[!IMPORTANT] Anthropic requires an API key to interact with the API. To get started, visit the official website to create an account. If you already have an account, go to the API keys page to generate a token.

[!IMPORTANT] Set your API key env var using export ANTHROPIC_API_KEY='your-api-key'

🐳 Docker

IMPORTANT This docker image depends on the sinapsis-nvidia:base image. Please refer to the official sinapsis instructions to Build with Docker.

  1. Build the sinapsis-chatbots image:
docker compose -f docker/compose.yaml build
  1. Start app the container
docker compose -f docker/compose_apps.yaml up sinapsis-claude-chatbot -d
  1. Check the logs
docker logs -f sinapsis-claude-chatbot
  1. The logs will display the URL to access the webapp, e.g.,::
Running on local URL:  http://127.0.0.1:7860

NOTE: The url may be different, check the output of logs.

  1. To stop the app:
docker compose -f docker/compose_apps.yaml down
💻 UV

To run the webapp using the uv package manager, follow these steps:

  1. Export the environment variable to install the python bindings for llama-cpp:
export CMAKE_ARGS="-DGGML_CUDA=on"
export FORCE_CMAKE="1"
  1. Export CUDACXX:
export CUDACXX=$(command -v nvcc)
  1. Sync the virtual environment:
uv sync --frozen
  1. Install the wheel:
uv pip install sinapsis-chatbots[all] --extra-index-url https://pypi.sinapsis.tech
  1. Set your API key:
export ANTHROPIC_API_KEY=your_api_key
  1. Run the webapp:
uv run webapps/claude_chatbot.py
  1. The terminal will display the URL to access the webapp (e.g.):
Running on local URL:  http://127.0.0.1:7860

NOTE: The URL may vary; check the terminal output for the correct address.

📙 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_anthropic-0.1.6.tar.gz (28.9 kB view details)

Uploaded Source

Built Distribution

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

sinapsis_anthropic-0.1.6-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

Details for the file sinapsis_anthropic-0.1.6.tar.gz.

File metadata

  • Download URL: sinapsis_anthropic-0.1.6.tar.gz
  • Upload date:
  • Size: 28.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.16

File hashes

Hashes for sinapsis_anthropic-0.1.6.tar.gz
Algorithm Hash digest
SHA256 14a1376392a941e22086ed5d5ac81ebbcbe17cf1df652e3dc04a8f401a0bdfec
MD5 81d9db52923c32be6b0b019db3c32794
BLAKE2b-256 b4dbb9a71ef203db1be8ef67d07eb3862aeef6571566fcc8996d9a0757108003

See more details on using hashes here.

File details

Details for the file sinapsis_anthropic-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for sinapsis_anthropic-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 feceeb2b16dd7227296a7163ec09b47247c907d1baadf56476c04964dce09bd3
MD5 a0eb4a2d8f9c3c1cc782565dd5f8aeee
BLAKE2b-256 68f97102977abbd029a53c63aa590b347cea5d3e63bc24fbdb82a19d1ae15d52

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