From 00910248d2dbc998880d86d7648ecfbf2855597c Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Thu, 12 Sep 2024 21:33:39 +0300 Subject: [PATCH] Add baibot preset for Mistral --- docs/configuring-playbook-bot-baibot.md | 24 ++++++++ .../matrix-bot-baibot/defaults/main.yml | 59 +++++++++++++++++++ .../tasks/validate_config.yml | 3 + .../templates/provider/mistral-config.yml.j2 | 13 ++++ 4 files changed, 99 insertions(+) create mode 100644 roles/custom/matrix-bot-baibot/templates/provider/mistral-config.yml.j2 diff --git a/docs/configuring-playbook-bot-baibot.md b/docs/configuring-playbook-bot-baibot.md index 20dfbb5eb..e39d8ee52 100644 --- a/docs/configuring-playbook-bot-baibot.md +++ b/docs/configuring-playbook-bot-baibot.md @@ -191,6 +191,30 @@ If you'd like to use more than one model, take a look at the [Configuring additi 💡 You may also wish to use this new agent for [🤝 Configuring initial default handlers](#-configuring-initial-default-handlers). +#### Mistral + +You can statically-define a single [🤖 agent](https://github.com/etkecc/baibot/blob/main/docs/agents.md) instance powered by the [🇫🇷 Mistral provider](https://github.com/etkecc/baibot/blob/main/docs/providers.md#mistral) with the help of the playbook's preset variables. + +Here's an example **addition** to your `vars.yml` file: + +```yml +matrix_bot_baibot_config_agents_static_definitions_mistral_enabled: true + +matrix_bot_baibot_config_agents_static_definitions_mistral_config_api_key: "YOUR_API_KEY_HERE" + +# Uncomment and adjust if you're not happy with these defaults: +# matrix_bot_baibot_config_agents_static_definitions_mistral_config_text_generation_model_id: mistral-large-latest + +# See `defaults/main.yml` in the baibot role for more configuration options. +``` + +Because this is a [statically](https://github.com/etkecc/baibot/blob/main/docs/configuration/README.md#static-configuration)-defined agent, it will be given a `static/` ID prefix and will be named `static/mistral`. + +If you'd like to use more than one model, take a look at the [Configuring additional agents (without a preset)](#configuring-additional-agents-without-a-preset) section below. + +💡 You may also wish to use this new agent for [🤝 Configuring initial default handlers](#-configuring-initial-default-handlers). + + #### OpenAI You can statically-define a single [🤖 agent](https://github.com/etkecc/baibot/blob/main/docs/agents.md) instance powered by the [OpenAI provider](https://github.com/etkecc/baibot/blob/main/docs/providers.md#openai) with the help of the playbook's preset variables. diff --git a/roles/custom/matrix-bot-baibot/defaults/main.yml b/roles/custom/matrix-bot-baibot/defaults/main.yml index 58406ca15..b07a2f906 100644 --- a/roles/custom/matrix-bot-baibot/defaults/main.yml +++ b/roles/custom/matrix-bot-baibot/defaults/main.yml @@ -141,6 +141,12 @@ matrix_bot_baibot_config_agents_static_definitions_auto: |- 'config': matrix_bot_baibot_config_agents_static_definitions_groq_config, }] if matrix_bot_baibot_config_agents_static_definitions_groq_enabled else []) + + ([{ + 'id': matrix_bot_baibot_config_agents_static_definitions_mistral_id, + 'provider': matrix_bot_baibot_config_agents_static_definitions_mistral_provider, + 'config': matrix_bot_baibot_config_agents_static_definitions_mistral_config, + }] if matrix_bot_baibot_config_agents_static_definitions_mistral_enabled else []) + + ([{ 'id': matrix_bot_baibot_config_agents_static_definitions_openai_id, 'provider': matrix_bot_baibot_config_agents_static_definitions_openai_provider, @@ -259,6 +265,59 @@ matrix_bot_baibot_config_agents_static_definitions_groq_config_speech_to_text_mo ######################################################################################## +######################################################################################## +# # +# Mistral agent configuration # +# # +######################################################################################## + +matrix_bot_baibot_config_agents_static_definitions_mistral_enabled: false +matrix_bot_baibot_config_agents_static_definitions_mistral_id: mistral +matrix_bot_baibot_config_agents_static_definitions_mistral_provider: mistral + +matrix_bot_baibot_config_agents_static_definitions_mistral_config: "{{ matrix_bot_baibot_config_agents_static_definitions_mistral_config_yaml | from_yaml | combine(matrix_bot_baibot_config_agents_static_definitions_mistral_config_extension, recursive=True)}}" + +matrix_bot_baibot_config_agents_static_definitions_mistral_config_yaml: "{{ lookup('template', 'templates/provider/mistral-config.yml.j2') }}" + +matrix_bot_baibot_config_agents_static_definitions_mistral_config_extension: "{{ matrix_bot_baibot_config_agents_static_definitions_mistral_config_extension_yaml | from_yaml if matrix_bot_baibot_config_agents_static_definitions_mistral_config_extension_yaml | from_yaml is mapping else {} }}" + +matrix_bot_baibot_config_agents_static_definitions_mistral_config_extension_yaml: | + # Your custom YAML configuration for this provider's configuration goes here. + # This configuration extends the default starting configuration (`matrix_bot_baibot_config_agents_static_definitions_mistral_config`). + # + # You can override individual variables from the default configuration, or introduce new ones. + # + # If you need something more special, you can take full control by + # completely redefining `matrix_bot_baibot_config_agents_static_definitions_mistral_config_yaml`. + # + # Example configuration extension follows: + # + # text_generation: + # temperature: 3.5 + +matrix_bot_baibot_config_agents_static_definitions_mistral_config_base_url: https://api.mistral.ai/v1 + +matrix_bot_baibot_config_agents_static_definitions_mistral_config_api_key: "" + +matrix_bot_baibot_config_agents_static_definitions_mistral_config_text_generation_enabled: true +# For valid model choices, see: https://platform.mistral.com/docs/models +matrix_bot_baibot_config_agents_static_definitions_mistral_config_text_generation_model_id: mistral-large-latest +# The prompt text to use (can be null or empty to not use a prompt). +# See: https://huggingface.co/docs/transformers/en/tasks/prompting +matrix_bot_baibot_config_agents_static_definitions_mistral_config_text_generation_prompt: null +# The temperature parameter controls the randomness of the generated text. +# See: https://blogs.novita.ai/what-are-large-language-model-settings-temperature-top-p-and-max-tokens/#what-is-llm-temperature +matrix_bot_baibot_config_agents_static_definitions_mistral_config_text_generation_temperature: 1.0 +matrix_bot_baibot_config_agents_static_definitions_mistral_config_text_generation_max_response_tokens: 4096 +matrix_bot_baibot_config_agents_static_definitions_mistral_config_text_generation_max_context_tokens: 128000 + +######################################################################################## +# # +# /Mistral agent configuration # +# # +######################################################################################## + + ######################################################################################## # # # OpenAI agent configuration # diff --git a/roles/custom/matrix-bot-baibot/tasks/validate_config.yml b/roles/custom/matrix-bot-baibot/tasks/validate_config.yml index 23e2b0922..43e4cb8fc 100644 --- a/roles/custom/matrix-bot-baibot/tasks/validate_config.yml +++ b/roles/custom/matrix-bot-baibot/tasks/validate_config.yml @@ -16,6 +16,9 @@ - {'name': 'matrix_bot_baibot_config_agents_static_definitions_groq_config_api_key', when: "{{ matrix_bot_baibot_config_agents_static_definitions_groq_enabled }}"} - {'name': 'matrix_bot_baibot_config_agents_static_definitions_groq_config_text_generation_model_id', when: "{{ matrix_bot_baibot_config_agents_static_definitions_groq_enabled and matrix_bot_baibot_config_agents_static_definitions_groq_config_text_generation_enabled }}"} + - {'name': 'matrix_bot_baibot_config_agents_static_definitions_mistral_config_api_key', when: "{{ matrix_bot_baibot_config_agents_static_definitions_mistral_enabled }}"} + - {'name': 'matrix_bot_baibot_config_agents_static_definitions_mistral_config_text_generation_model_id', when: "{{ matrix_bot_baibot_config_agents_static_definitions_mistral_enabled and matrix_bot_baibot_config_agents_static_definitions_mistral_config_text_generation_enabled }}"} + - {'name': 'matrix_bot_baibot_config_agents_static_definitions_openai_config_api_key', when: "{{ matrix_bot_baibot_config_agents_static_definitions_openai_enabled }}"} - name: Fail if admin patterns list is empty diff --git a/roles/custom/matrix-bot-baibot/templates/provider/mistral-config.yml.j2 b/roles/custom/matrix-bot-baibot/templates/provider/mistral-config.yml.j2 new file mode 100644 index 000000000..5f97e69fd --- /dev/null +++ b/roles/custom/matrix-bot-baibot/templates/provider/mistral-config.yml.j2 @@ -0,0 +1,13 @@ +#jinja2: lstrip_blocks: "True" +base_url: {{ matrix_bot_baibot_config_agents_static_definitions_mistral_config_base_url | to_json }} + +api_key: {{ matrix_bot_baibot_config_agents_static_definitions_mistral_config_api_key | to_json }} + +{% if matrix_bot_baibot_config_agents_static_definitions_mistral_config_text_generation_enabled %} +text_generation: + model_id: {{ matrix_bot_baibot_config_agents_static_definitions_mistral_config_text_generation_model_id | to_json }} + prompt: {{ matrix_bot_baibot_config_agents_static_definitions_mistral_config_text_generation_prompt | to_json }} + temperature: {{ matrix_bot_baibot_config_agents_static_definitions_mistral_config_text_generation_temperature | to_json }} + max_response_tokens: {{ matrix_bot_baibot_config_agents_static_definitions_mistral_config_text_generation_max_response_tokens | int | to_json }} + max_context_tokens: {{ matrix_bot_baibot_config_agents_static_definitions_mistral_config_text_generation_max_context_tokens | int | to_json }} +{% endif %}