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 and image-to-text 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
    • llm_model_name(Required): The name of the Claude model to be used. To see the list of all available Claude models visit the official documentation.
    • role(Optional): The role in the conversation, such as system, user, or assistant (default: assistant).
    • prompt(Optional): A set of instructions provided to the LLM to guide how to respond. (default: empty string).
    • system_prompt(Optional): The prompt that indicates the LLM how to behave (default: None).
    • context_max_len(Optional): The maximum length for the conversation context (default: 6).
    • budget_tokens(Optional): The maximum number of tokens to allocate for intermediate thinking steps when extended_thinking is enabled (default: 2000).
    • extended_thinking(Optional): A flag indicating whether to display "thinking" content blocks in the response (default: False).
    • max_tokens(Optional): Maximum number of tokens to generate (default: 4000).
    • temperature(Optional): Sampling temperature for the model (default: 1.0).
    • web_search(Optional): A boolean flag indicating whether web search should be enabled (default: False).
  • AnthropicMultiModal: Template for multimodal chat processing using Anthropic's Claude models.

    Attributes
    • llm_model_name(Required): The name of the Claude model to be used. To see the list of all available Claude models visit the official documentation.
    • role(Optional): The role in the conversation, such as system, user, or assistant (default: assistant).
    • prompt(Optional): A set of instructions provided to the LLM to guide how to respond. (default: empty string).
    • system_prompt(Optional): The prompt that indicates the LLM how to behave (default: None).
    • context_max_len(Optional): The maximum length for the conversation context (default: 6).
    • budget_tokens(Optional): The maximum number of tokens to allocate for intermediate thinking steps when extended_thinking is enabled (default: 2000).
    • extended_thinking(Optional): A flag indicating whether to display "thinking" content blocks in the response (default: False).
    • max_tokens(Optional): Maximum number of tokens to generate (default: 4000).
    • temperature(Optional): Sampling temperature for the model (default: 1.0).
    • web_search(Optional): A boolean flag indicating whether web search should be enabled (default: False).

[!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:
    llm_model_name: claude-3-7-sonnet-latest
    n_ctx: 9000
    role: assistant
    prompt: ''
    system_prompt: null
    chat_format: chatml
    context_max_len: 6
    pattern: null
    keep_before: true
    budget_tokens: 2000
    extended_thinking: false
    max_tokens: 4000
    temperature: 1.0
    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: ImageReader
  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: ImageReader
  attributes:
    llm_model_name: claude-3-opus-20240229
    max_tokens: 4000
    temperature: 1

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.2.tar.gz (26.3 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.2-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for sinapsis_anthropic-0.1.2.tar.gz
Algorithm Hash digest
SHA256 698688182e856839b8c8c7576a1bf38d2a8b47499c81fc8ff8b4dc33ec60882f
MD5 6c86ab4bf95a3e08cbf91561193868f7
BLAKE2b-256 194b920209f3d682bc3958ba62966ebeaa53e0312d99caccd7ffeedf565aa433

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sinapsis_anthropic-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 32b2a8b5a15001c29724515957567e75ed330b76516fa89aeba105d183d59856
MD5 c1898f390657c42f526faca7d1b1458d
BLAKE2b-256 613717f88ccd003c8e91aa461173f3762e50ba9aed8a78bb36bfd6ce7cad9988

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