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 to0.2.top_p(float, optional): Nucleus sampling. Considers tokens with cumulative probability >= top_p. Defaults to0.95.top_k(int, optional): Top-k sampling. Considers the top 'k' most probable tokens. Defaults to40.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 thanmax_tokens. Defaults to2048.
-
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 to0.2.top_p(float, optional): Nucleus sampling. Considers tokens with cumulative probability >= top_p. Defaults to0.95.top_k(int, optional): Top-k sampling. Considers the top 'k' most probable tokens. Defaults to40.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 thanmax_tokens. Defaults to2048.
-
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 to0.2.top_p(float, optional): Nucleus sampling. Considers tokens with cumulative probability >= top_p. Defaults to0.95.top_k(int, optional): Top-k sampling. Considers the top 'k' most probable tokens. Defaults to40.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 thanmax_tokens. Defaults to2048.
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_NAMEto 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.
- Build the sinapsis-chatbots image:
docker compose -f docker/compose.yaml build
- Start app the container
docker compose -f docker/compose_apps.yaml up sinapsis-claude-chatbot -d
- Check the logs
docker logs -f sinapsis-claude-chatbot
- 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.
- 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:
- Export the environment variable to install the python bindings for llama-cpp:
export CMAKE_ARGS="-DGGML_CUDA=on"
export FORCE_CMAKE="1"
- Export CUDACXX:
export CUDACXX=$(command -v nvcc)
- Sync the virtual environment:
uv sync --frozen
- Install the wheel:
uv pip install sinapsis-chatbots[all] --extra-index-url https://pypi.sinapsis.tech
- Set your API key:
export ANTHROPIC_API_KEY=your_api_key
- Run the webapp:
uv run webapps/claude_chatbot.py
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sinapsis_anthropic-0.1.5.tar.gz.
File metadata
- Download URL: sinapsis_anthropic-0.1.5.tar.gz
- Upload date:
- Size: 28.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9581c564c248b9adec6669bab619d32e0476ecb9c981fdb757afe0a6ee09f5db
|
|
| MD5 |
97c19eef02e0c5b0e4fa9970baa2571c
|
|
| BLAKE2b-256 |
63ba648bd7cc0a0aa2e24c9124b1d9b1cab0f652ef7272dc0f53ab731d88ffc8
|
File details
Details for the file sinapsis_anthropic-0.1.5-py3-none-any.whl.
File metadata
- Download URL: sinapsis_anthropic-0.1.5-py3-none-any.whl
- Upload date:
- Size: 29.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a99ca6d2193ac1bc994946cccd1e2c74bc76eb39123a866db33f983053e1603d
|
|
| MD5 |
1cb824dfbd769cdaf52848c5ebdc2fd1
|
|
| BLAKE2b-256 |
a032058688c0296ef51a1afcf0ec3a916d05b466714b822df7f975dcbc1efe0f
|