Add support for baibot

Related to https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/3369
This commit is contained in:
Slavi Pantaleev
2024-09-12 15:19:40 +03:00
parent c65ddd649e
commit 1851973734
18 changed files with 1225 additions and 1 deletions

View File

@ -0,0 +1,85 @@
# Default configuration for baibot.
# To extend it, use `matrix_bot_baibot_configuration_extension_yaml`.
homeserver:
# The canonical homeserver domain name
server_name: {{ matrix_bot_baibot_config_homeserver_server_name | to_json }}
url: {{ matrix_bot_baibot_config_homeserver_url | to_json }}
user:
mxid_localpart: {{ matrix_bot_baibot_config_user_mxid_localpart | to_json }}
password: {{ matrix_bot_baibot_config_user_password | to_json }}
# The name the bot uses as a display name and when it refers to itself.
# Leave empty to use the default (baibot).
name: {{ matrix_bot_baibot_config_user_name | to_json }}
encryption:
# An optional passphrase to use for backing up and recovering the bot's encryption keys.
# You can use any string here.
#
# If left empty, the recovery module will not be used and losing your session/database (see persistence)
# will mean you lose access to old messages in encrypted room.
#
# Changing this subsequently will also cause you to lose access to old messages in encrypted rooms.
# If you really need to change this:
# - Set `encryption_recovery_reset_allowed` to `true` and adjust the passphrase
# - Remove your session file and database (see persistence)
# - Restart the bot
# - Then restore `encryption_recovery_reset_allowed` to `false` to prevent accidental resets in the future
recovery_passphrase: {{ matrix_bot_baibot_config_user_encryption_recovery_passphrase | to_json }}
# An optional flag to reset the encryption recovery passphrase.
recovery_reset_allowed: {{ matrix_bot_baibot_config_user_encryption_recovery_reset_allowed | to_json }}
# Command prefix. Leave empty to use the default (!bai).
command_prefix: {{ matrix_bot_baibot_config_command_prefix | to_json }}
access:
# Space-separated list of MXID patterns which specify who is an admin.
admin_patterns: {{ matrix_bot_baibot_config_access_admin_patterns | to_json }}
persistence:
data_dir_path: {{ matrix_bot_baibot_config_persistence_data_dir_path | to_json }}
# An optional secret for encrypting the bot's session data (stored in data_dir_path).
# This must be 32-bytes (64 characters when HEX-encoded).
# Generate it with: `openssl rand -hex 32`
# Leave null or empty to avoid using encryption.
# Changing this subsequently requires that you also throw away all data stored in data_dir_path.
session_encryption_key: {{ matrix_bot_baibot_config_persistence_session_encryption_key | to_json }}
# An optional secret for encrypting bot configuration stored in Matrix's account data.
# This must be 32-bytes (64 characters when HEX-encoded).
# Generate it with: `openssl rand -hex 32`
# Leave null or empty to avoid using encryption.
# Changing this subsequently will make you lose your configuration.
config_encryption_key: {{ matrix_bot_baibot_config_persistence_config_encryption_key | to_json }}
agents:
# A list of statically-defined agents.
static_definitions: {{ matrix_bot_baibot_config_agents_static_definitions | to_json }}
# Initial global configuration. This only affects the first run of the bot.
# Configuration is later managed at runtime.
initial_global_config:
handler:
catch_all: {{ matrix_bot_baibot_config_initial_global_config_handler_catch_all | to_json }}
text_generation: {{ matrix_bot_baibot_config_initial_global_config_handler_text_generation | to_json }}
text_to_speech: {{ matrix_bot_baibot_config_initial_global_config_handler_text_to_speech | to_json }}
speech_to_text: {{ matrix_bot_baibot_config_initial_global_config_handler_speech_to_text | to_json }}
image_generation: {{ matrix_bot_baibot_config_initial_global_config_handler_image_generation | to_json }}
# Space-separated list of MXID patterns which specify who can use the bot.
# By default, we let anyone on the homeserver use the bot.
user_patterns: {{ matrix_bot_baibot_config_initial_global_config_user_patterns | to_json}}
# Controls logging.
#
# Sets all tracing targets (external crates) to warn, and our own logs to debug.
# For even more verbose logging, one may also use trace.
#
# matrix_sdk_crypto may be chatty and could be added with an error level.
#
# Learn more here: https://stackoverflow.com/a/73735203
logging: {{ matrix_bot_baibot_config_logging | to_json }}

View File

@ -0,0 +1 @@
{{ matrix_bot_baibot_environment_variables_extension }}

View File

@ -0,0 +1,13 @@
#jinja2: lstrip_blocks: "True"
base_url: {{ matrix_bot_baibot_config_agents_static_definitions_anthropic_config_base_url | to_json }}
api_key: {{ matrix_bot_baibot_config_agents_static_definitions_anthropic_config_api_key | to_json }}
{% if matrix_bot_baibot_config_agents_static_definitions_anthropic_config_text_generation_enabled %}
text_generation:
model_id: {{ matrix_bot_baibot_config_agents_static_definitions_anthropic_config_text_generation_model_id | to_json }}
prompt: {{ matrix_bot_baibot_config_agents_static_definitions_anthropic_config_text_generation_prompt | to_json }}
temperature: {{ matrix_bot_baibot_config_agents_static_definitions_anthropic_config_text_generation_temperature | to_json }}
max_response_tokens: {{ matrix_bot_baibot_config_agents_static_definitions_anthropic_config_text_generation_max_response_tokens | int | to_json }}
max_context_tokens: {{ matrix_bot_baibot_config_agents_static_definitions_anthropic_config_text_generation_max_context_tokens | int | to_json }}
{% endif %}

View File

@ -0,0 +1,18 @@
#jinja2: lstrip_blocks: "True"
base_url: {{ matrix_bot_baibot_config_agents_static_definitions_groq_config_base_url | to_json }}
api_key: {{ matrix_bot_baibot_config_agents_static_definitions_groq_config_api_key | to_json }}
{% if matrix_bot_baibot_config_agents_static_definitions_groq_config_text_generation_enabled %}
text_generation:
model_id: {{ matrix_bot_baibot_config_agents_static_definitions_groq_config_text_generation_model_id | to_json }}
prompt: {{ matrix_bot_baibot_config_agents_static_definitions_groq_config_text_generation_prompt | to_json }}
temperature: {{ matrix_bot_baibot_config_agents_static_definitions_groq_config_text_generation_temperature | to_json }}
max_response_tokens: {{ matrix_bot_baibot_config_agents_static_definitions_groq_config_text_generation_max_response_tokens | int | to_json }}
max_context_tokens: {{ matrix_bot_baibot_config_agents_static_definitions_groq_config_text_generation_max_context_tokens | int | to_json }}
{% endif %}
{% if matrix_bot_baibot_config_agents_static_definitions_groq_config_speech_to_text_enabled %}
speech_to_text:
model_id: {{ matrix_bot_baibot_config_agents_static_definitions_groq_config_speech_to_text_model_id | to_json }}
{% endif %}

View File

@ -0,0 +1,33 @@
#jinja2: lstrip_blocks: "True"
base_url: {{ matrix_bot_baibot_config_agents_static_definitions_openai_config_base_url | to_json }}
api_key: {{ matrix_bot_baibot_config_agents_static_definitions_openai_config_api_key | to_json }}
{% if matrix_bot_baibot_config_agents_static_definitions_openai_config_text_generation_enabled %}
text_generation:
model_id: {{ matrix_bot_baibot_config_agents_static_definitions_openai_config_text_generation_model_id | to_json }}
prompt: {{ matrix_bot_baibot_config_agents_static_definitions_openai_config_text_generation_prompt | to_json }}
temperature: {{ matrix_bot_baibot_config_agents_static_definitions_openai_config_text_generation_temperature | to_json }}
max_response_tokens: {{ matrix_bot_baibot_config_agents_static_definitions_openai_config_text_generation_max_response_tokens | int | to_json }}
max_context_tokens: {{ matrix_bot_baibot_config_agents_static_definitions_openai_config_text_generation_max_context_tokens | int | to_json }}
{% endif %}
{% if matrix_bot_baibot_config_agents_static_definitions_openai_config_speech_to_text_enabled %}
speech_to_text:
model_id: {{ matrix_bot_baibot_config_agents_static_definitions_openai_config_speech_to_text_model_id | to_json }}
{% endif %}
{% if matrix_bot_baibot_config_agents_static_definitions_openai_config_text_to_speech_enabled %}
text_to_speech:
model_id: {{ matrix_bot_baibot_config_agents_static_definitions_openai_config_text_to_speech_model_id | to_json }}
voice: {{ matrix_bot_baibot_config_agents_static_definitions_openai_config_text_to_speech_voice | to_json }}
speed: {{ matrix_bot_baibot_config_agents_static_definitions_openai_config_text_to_speech_speed | float }}
response_format: {{ matrix_bot_baibot_config_agents_static_definitions_openai_config_text_to_speech_response_format | to_json }}
{% endif %}
{% if matrix_bot_baibot_config_agents_static_definitions_openai_config_image_generation_enabled %}
image_generation:
model_id: {{ matrix_bot_baibot_config_agents_static_definitions_openai_config_image_generation_model_id | to_json }}
style: {{ matrix_bot_baibot_config_agents_static_definitions_openai_config_image_generation_style | to_json }}
size: {{ matrix_bot_baibot_config_agents_static_definitions_openai_config_image_generation_size | to_json }}
{% endif %}

View File

@ -0,0 +1,53 @@
#jinja2: lstrip_blocks: "True"
[Unit]
Description=Matrix baibot bot
{% for service in matrix_bot_baibot_systemd_required_services_list %}
Requires={{ service }}
After={{ service }}
{% endfor %}
{% for service in matrix_bot_baibot_systemd_wanted_services_list %}
Wants={{ service }}
{% endfor %}
DefaultDependencies=no
[Service]
Type=simple
Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}"
ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop --time={{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-bot-baibot 2>/dev/null || true'
ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-bot-baibot 2>/dev/null || true'
{#
We mount a tmpfs at /tmp, because the bot may write temporary files there
(see its `src/agent/provider/openai_compat/controller.rs`).
#}
ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \
--rm \
--name=matrix-bot-baibot \
--log-driver=none \
--user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
--cap-drop=ALL \
--read-only \
--network={{ matrix_bot_baibot_container_network }} \
--env-file={{ matrix_bot_baibot_config_path }}/env \
--mount type=bind,src={{ matrix_bot_baibot_config_path }}/config.yml,dst=/app/config.yml,ro \
--mount type=bind,src={{ matrix_bot_baibot_data_path }},dst=/data \
--tmpfs=/tmp:rw,noexec,nosuid,size=1024m \
{% for arg in matrix_bot_baibot_container_extra_arguments %}
{{ arg }} \
{% endfor %}
{{ matrix_bot_baibot_container_image }}
{% for network in matrix_bot_baibot_container_additional_networks %}
ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} network connect {{ network }} matrix-bot-baibot
{% endfor %}
ExecStart={{ devture_systemd_docker_base_host_command_docker }} start --attach matrix-bot-baibot
ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop --time={{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-bot-baibot 2>/dev/null || true'
ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-bot-baibot 2>/dev/null || true'
Restart=always
RestartSec=30
SyslogIdentifier=matrix-bot-baibot
[Install]
WantedBy=multi-user.target