From d5b015902276a77cbf00b559e4b6e87e17d803f8 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 25 Mar 2024 19:57:15 +0000 Subject: [PATCH 1/3] Added role_for_select_speaker_messages for setting role name --- autogen/agentchat/groupchat.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/autogen/agentchat/groupchat.py b/autogen/agentchat/groupchat.py index 3db9b72cce34..195adb1cc20e 100644 --- a/autogen/agentchat/groupchat.py +++ b/autogen/agentchat/groupchat.py @@ -61,6 +61,7 @@ def custom_speaker_selection_func( "clear history" phrase in user prompt. This is experimental feature. See description of GroupChatManager.clear_agents_history function for more info. - send_introductions: send a round of introductions at the start of the group chat, so agents know who they can speak to (default: False) + - role_for_select_speaker_messages: sets the role name for speaker selection when in 'auto' mode, typically 'user' or 'system'. (default: 'system') """ agents: List[Agent] @@ -74,6 +75,7 @@ def custom_speaker_selection_func( speaker_transitions_type: Literal["allowed", "disallowed", None] = None enable_clear_history: Optional[bool] = False send_introductions: bool = False + role_for_select_speaker_messages: Optional[str] = "system" _VALID_SPEAKER_SELECTION_METHODS = ["auto", "manual", "random", "round_robin"] _VALID_SPEAKER_TRANSITIONS_TYPE = ["allowed", "disallowed", None] @@ -407,7 +409,7 @@ def _prepare_and_select_agents( selected_agent = self.next_agent(last_speaker, graph_eligible_agents) elif speaker_selection_method.lower() == "random": selected_agent = self.random_select_speaker(graph_eligible_agents) - else: + else: # auto selected_agent = None select_speaker_messages = self.messages.copy() # If last message is a tool call or function call, blank the call so the api doesn't throw @@ -416,7 +418,10 @@ def _prepare_and_select_agents( if select_speaker_messages[-1].get("tool_calls", False): select_speaker_messages[-1] = dict(select_speaker_messages[-1], tool_calls=None) select_speaker_messages = select_speaker_messages + [ - {"role": "system", "content": self.select_speaker_prompt(graph_eligible_agents)} + { + "role": self.role_for_select_speaker_messages, + "content": self.select_speaker_prompt(graph_eligible_agents), + } ] return selected_agent, graph_eligible_agents, select_speaker_messages From bb5d52c245207dcee3690304523c3efb97bfcba6 Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Tue, 26 Mar 2024 21:41:26 +1100 Subject: [PATCH 2/3] Added Mistral AI link and notebook (thanks ekzhu), tips for non-OpenAI models --- .../about-using-nonopenai-models.md | 5 +- .../best-tips-for-nonopenai-models.md | 50 + .../non-openai-models/cloud-mistralai.ipynb | 1009 +++++++++++++++++ .../cell-11-output-2.svg | 8 + .../cell-11-output-3.svg | 8 + .../cell-11-output-4.svg | 8 + .../cell-11-output-5.svg | 8 + .../cell-11-output-6.svg | 8 + .../cell-11-output-7.svg | 8 + .../cell-11-output-8.svg | 8 + 10 files changed, 1118 insertions(+), 2 deletions(-) create mode 100644 website/docs/topics/non-openai-models/best-tips-for-nonopenai-models.md create mode 100644 website/docs/topics/non-openai-models/cloud-mistralai.ipynb create mode 100644 website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-2.svg create mode 100644 website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-3.svg create mode 100644 website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-4.svg create mode 100644 website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-5.svg create mode 100644 website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-6.svg create mode 100644 website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-7.svg create mode 100644 website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-8.svg diff --git a/website/docs/topics/non-openai-models/about-using-nonopenai-models.md b/website/docs/topics/non-openai-models/about-using-nonopenai-models.md index e202679f29e1..0abea2764152 100644 --- a/website/docs/topics/non-openai-models/about-using-nonopenai-models.md +++ b/website/docs/topics/non-openai-models/about-using-nonopenai-models.md @@ -21,8 +21,8 @@ These proxy servers can be cloud-based or running locally within your environmen By using cloud-based proxy servers, you are able to use models without requiring the hardware and software to run them. -These providers can host open source/weight models, like [Hugging Face](https://huggingface.co/), -or their own closed models. +These providers can host open source/weight models, like [Hugging Face](https://huggingface.co/) +and [Mistral AI](https://mistral.ai/), or their own closed models. When cloud-based proxy servers provide an OpenAI-compatible API, using them in AutoGen is straightforward. With [LLM Configuration](/docs/topics/llm_configuration) done in @@ -33,6 +33,7 @@ Examples of using cloud-based proxy servers providers that have an OpenAI-compat are provided below: - [together.ai example](/docs/topics/non-openai-models/cloud-togetherai) +- [Mistral AI example](/docs/topics/non-openai-models/cloud-mistralai) ### Locally run proxy servers diff --git a/website/docs/topics/non-openai-models/best-tips-for-nonopenai-models.md b/website/docs/topics/non-openai-models/best-tips-for-nonopenai-models.md new file mode 100644 index 000000000000..6dbda16e7238 --- /dev/null +++ b/website/docs/topics/non-openai-models/best-tips-for-nonopenai-models.md @@ -0,0 +1,50 @@ +# Tips for Non-OpenAI Models + +Here are some tips for using non-OpenAI Models with AutoGen. + +## Finding the right model +Every model will perform differently across the operations within your AutoGen +setup, such as speaker selection, coding, function calling, content creation, +etc. On the whole, larger models (13B+) perform better with following directions +and providing more cohesive responses. + +Content creation can be performed by most models. + +Fine-tuned models can be great for very specific tasks, such as function calling +and coding. + +Specific tasks, such as speaker selection in a Group Chat scenario, that require +very accurate outputs can be a challenge with most open source/weight models. The +use of chain-on-thought and/or few-shot prompting can help guide the LLM to provide +the output in the format you want. + +## Validating your program +Testing your AutoGen setup against a very large LLM, such as OpenAI's ChatGPT or +Anthropic's Claude 3, can help validate your agent setup and configuration. + +Once a setup is performing as you want, you can replace the models for your agents +with non-OpenAI models and iteratively tweak system messages, prompts, and model +selection. + +## Chat template +AutoGen utilises a set of chat messages for the conversation between AutoGen/user +and LLMs. Each chat message has a role attribute that is typically "user", +"assistant", or "system". + +A chat template is applied during inference and some chat templates implement rules about +what roles can be used in specific sequences of messages. + +For example, when using Mistral AI's API the last chat message cannot have a role of +'system'. In a Group Chat scenario the message used to select the next speaker will +have a role of 'system' by default and the API will throw an exception for this step. To +overcome this the GroupChat's constructor has a parameter called 'role_for_select_speaker_messages' +that can be used to change the role name to 'user'. See this demonstrated in the +[Mistral AI example](/docs/topics/non-openai-models/cloud-mistralai). + +If the chat template associated with a model you want to use doesn't support the role +sequence and names used in AutoGen you can modify the chat template. See an example of +this on our [vLLM page](/docs/topics/non-openai-models/local-vllm#chat-template). + +## Discord +Join AutoGen's [#alt-models](https://discord.com/channels/1153072414184452236/1201369716057440287) +channel on their Discord and discuss non-OpenAI models and configurations. \ No newline at end of file diff --git a/website/docs/topics/non-openai-models/cloud-mistralai.ipynb b/website/docs/topics/non-openai-models/cloud-mistralai.ipynb new file mode 100644 index 000000000000..883cd46db663 --- /dev/null +++ b/website/docs/topics/non-openai-models/cloud-mistralai.ipynb @@ -0,0 +1,1009 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Mistral AI\n", + "\n", + "[Mistral AI](https://mistral.ai/) is a cloud based platform\n", + "serving Mistral's own LLMs.\n", + "You can use AutoGen with Mistral AI's API directly." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "First you need to install the `pyautogen` package to use AutoGen." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "! pip install pyautogen" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now you can set up the Mistral model you want to use. See the list of [models here](https://docs.mistral.ai/platform/endpoints/)." + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "\n", + "config_list = [\n", + " {\n", + " # Choose your model name.\n", + " \"model\": \"mistral-large-latest\",\n", + " \"base_url\": \"https://api.mistral.ai/v1\",\n", + " # You need to provide your API key here.\n", + " \"api_key\": os.environ.get(\"MISTRAL_API_KEY\"),\n", + " }\n", + "]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Two-Agent Coding Example\n", + "\n", + "In this example, we run a two-agent chat to count the number of prime numbers between 1 and 10,000 using coding." + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "from pathlib import Path\n", + "from autogen import AssistantAgent, UserProxyAgent\n", + "from autogen.coding import LocalCommandLineCodeExecutor\n", + "\n", + "# Setting up the code executor.\n", + "workdir = Path(\"coding\")\n", + "workdir.mkdir(exist_ok=True)\n", + "code_executor = LocalCommandLineCodeExecutor(work_dir=workdir)\n", + "\n", + "# Setting up the agents.\n", + "user_proxy_agent = UserProxyAgent(\n", + " name=\"User\",\n", + " code_execution_config={\"executor\": code_executor},\n", + " is_termination_msg=lambda msg: \"TERMINATE\" in msg.get(\"content\"),\n", + ")\n", + "\n", + "assistant_agent = AssistantAgent(\n", + " name=\"Mistral Assistant\",\n", + " llm_config={\"config_list\": config_list},\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33mUser\u001b[0m (to Mistral Assistant):\n", + "\n", + "Count how many prime numbers from 1 to 10000.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[33mMistral Assistant\u001b[0m (to User):\n", + "\n", + "Sure, I can help with that. Here's a Python code snippet that counts the number of prime numbers from 1 to 10000.\n", + "\n", + "```python\n", + "# filename: prime_counter.py\n", + "\n", + "def is_prime(n):\n", + " if n <= 1:\n", + " return False\n", + " if n <= 3:\n", + " return True\n", + " if n % 2 == 0 or n % 3 == 0:\n", + " return False\n", + " i = 5\n", + " while i * i <= n:\n", + " if n % i == 0 or n % (i + 2) == 0:\n", + " return False\n", + " i += 6\n", + " return True\n", + "\n", + "count = 0\n", + "for num in range(1, 10001):\n", + " if is_prime(num):\n", + " count += 1\n", + "\n", + "print(count)\n", + "```\n", + "\n", + "Please save this code in a file named `prime_counter.py` and run it. The output will be the count of prime numbers from 1 to 10000.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[31m\n", + ">>>>>>>> EXECUTING CODE BLOCK (inferred language is python)...\u001b[0m\n", + "\u001b[33mUser\u001b[0m (to Mistral Assistant):\n", + "\n", + "exitcode: 0 (execution succeeded)\n", + "Code output: 1229\n", + "\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[33mMistral Assistant\u001b[0m (to User):\n", + "\n", + "Based on the output, the code I provided earlier has successfully executed and found that there are 1229 prime numbers between 1 and 10000. Here's how I approached this task step by step:\n", + "\n", + "1. I wrote a Python function `is_prime(n)` to check if a given number `n` is prime. This function returns `True` if `n` is prime and `False` otherwise.\n", + "\n", + "2. I used a for loop to iterate through numbers from 1 to 10000, then called the `is_prime` function to determine if the current number is prime. If it is, I incremented a counter variable `count` by 1.\n", + "\n", + "3. I printed the value of `count` after the loop to display the total number of prime numbers in the given range.\n", + "\n", + "The output `1229` confirms that there are indeed 1229 prime numbers between 1 and 10000.\n", + "\n", + "TERMINATE\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n" + ] + } + ], + "source": [ + "chat_result = user_proxy_agent.initiate_chat(\n", + " assistant_agent,\n", + " message=\"Count how many prime numbers from 1 to 10000.\",\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Tool Call Example\n", + "\n", + "In this example, instead of writing code, we will have two agents playing chess against each other using tool calling to make moves.\n", + "\n", + "First install the `chess` package by running the following command:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "! pip install chess" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Write the function for making a move." + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [], + "source": [ + "import chess\n", + "import chess.svg\n", + "from IPython.display import display\n", + "import random\n", + "from typing_extensions import Annotated\n", + "\n", + "board = chess.Board()\n", + "\n", + "\n", + "def make_move() -> Annotated[str, \"A move in UCI format\"]:\n", + " moves = list(board.legal_moves)\n", + " move = random.choice(moves)\n", + " board.push(move)\n", + " # Display the board.\n", + " display(chess.svg.board(board, size=400))\n", + " return str(move)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's create the agents. We have three different agents:\n", + "- `player_white` is the agent that plays white.\n", + "- `player_black` is the agent that plays black.\n", + "- `board_proxy` is the agent that moves the pieces on the board." + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [], + "source": [ + "from autogen import ConversableAgent, register_function\n", + "\n", + "player_white = ConversableAgent(\n", + " name=\"Player White\",\n", + " system_message=\"You are a chess player and you play as white. \" \"Always call make_move() to make a move\",\n", + " llm_config={\"config_list\": config_list, \"cache_seed\": None},\n", + ")\n", + "\n", + "player_black = ConversableAgent(\n", + " name=\"Player Black\",\n", + " system_message=\"You are a chess player and you play as black. \" \"Always call make_move() to make a move\",\n", + " llm_config={\"config_list\": config_list, \"cache_seed\": None},\n", + ")\n", + "\n", + "board_proxy = ConversableAgent(\n", + " name=\"Board Proxy\",\n", + " llm_config=False,\n", + " # The board proxy will only respond to the make_move function.\n", + " is_termination_msg=lambda msg: \"tool_calls\" not in msg,\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Register tools for the agents. See the [tutorial chapter on tool use](/docs/tutorial/tool-use) \n", + "for more information." + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [], + "source": [ + "register_function(\n", + " make_move,\n", + " caller=player_white,\n", + " executor=board_proxy,\n", + " name=\"make_move\",\n", + " description=\"Make a move.\",\n", + ")\n", + "\n", + "register_function(\n", + " make_move,\n", + " caller=player_black,\n", + " executor=board_proxy,\n", + " name=\"make_move\",\n", + " description=\"Make a move.\",\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Register nested chats for the player agents.\n", + "Nested chats allows each player agent to chat with the board proxy agent\n", + "to make a move, before communicating with the other player agent.\n", + "See the [nested chats tutorial chapter](/docs/tutorial/conversation-patterns#nested-chats)\n", + "for more information." + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [], + "source": [ + "player_white.register_nested_chats(\n", + " trigger=player_black,\n", + " chat_queue=[\n", + " {\n", + " \"sender\": board_proxy,\n", + " \"recipient\": player_white,\n", + " }\n", + " ],\n", + ")\n", + "\n", + "player_black.register_nested_chats(\n", + " trigger=player_white,\n", + " chat_queue=[\n", + " {\n", + " \"sender\": board_proxy,\n", + " \"recipient\": player_black,\n", + " }\n", + " ],\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Start the chess game." + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33mPlayer White\u001b[0m (to Player Black):\n", + "\n", + "Let's play chess! Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[34m\n", + "********************************************************************************\u001b[0m\n", + "\u001b[34mStarting a new chat....\n", + "\n", + "Message:\n", + "Let's play chess! Your move.\n", + "\n", + "Carryover: \n", + "\u001b[0m\n", + "\u001b[34m\n", + "********************************************************************************\u001b[0m\n", + "\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n", + "\n", + "Let's play chess! Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[33mPlayer Black\u001b[0m (to Board Proxy):\n", + "\n", + "\n", + "\u001b[32m***** Suggested tool call (No tool call id found): make_move *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m******************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION make_move...\u001b[0m\n" + ] + }, + { + "data": { + "image/svg+xml": [ + "
r n b q k b n r\n",
+       "p p p p p p p p\n",
+       ". . . . . . . .\n",
+       ". . . . . . . .\n",
+       ". . . . . . . .\n",
+       "P . . . . . . .\n",
+       ". P P P P P P P\n",
+       "R N B Q K B N R
" + ], + "text/plain": [ + "'
r n b q k b n r\\np p p p p p p p\\n. . . . . . . .\\n. . . . . . . .\\n. . . . . . . .\\nP . . . . . . .\\n. P P P P P P P\\nR N B Q K B N R
'" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n", + "\n", + "\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n", + "\n", + "\u001b[32m***** Response from calling tool (No id found) *****\u001b[0m\n", + "a2a3\n", + "\u001b[32m****************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[33mPlayer Black\u001b[0m (to Board Proxy):\n", + "\n", + "You made a move: a2a3. It's my turn now.\n", + "\n", + "e2e4\n", + "\n", + "Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n", + "\u001b[33mPlayer Black\u001b[0m (to Player White):\n", + "\n", + "You made a move: a2a3. It's my turn now.\n", + "\n", + "e2e4\n", + "\n", + "Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[34m\n", + "********************************************************************************\u001b[0m\n", + "\u001b[34mStarting a new chat....\n", + "\n", + "Message:\n", + "You made a move: a2a3. It's my turn now.\n", + "\n", + "e2e4\n", + "\n", + "Your move.\n", + "\n", + "Carryover: \n", + "\u001b[0m\n", + "\u001b[34m\n", + "********************************************************************************\u001b[0m\n", + "\u001b[33mBoard Proxy\u001b[0m (to Player White):\n", + "\n", + "You made a move: a2a3. It's my turn now.\n", + "\n", + "e2e4\n", + "\n", + "Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[33mPlayer White\u001b[0m (to Board Proxy):\n", + "\n", + "\n", + "\u001b[32m***** Suggested tool call (No tool call id found): make_move *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m******************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION make_move...\u001b[0m\n" + ] + }, + { + "data": { + "image/svg+xml": [ + "
r n b q k b n r\n",
+       "p p p p . p p p\n",
+       ". . . . . . . .\n",
+       ". . . . p . . .\n",
+       ". . . . . . . .\n",
+       "P . . . . . . .\n",
+       ". P P P P P P P\n",
+       "R N B Q K B N R
" + ], + "text/plain": [ + "'
r n b q k b n r\\np p p p . p p p\\n. . . . . . . .\\n. . . . p . . .\\n. . . . . . . .\\nP . . . . . . .\\n. P P P P P P P\\nR N B Q K B N R
'" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33mBoard Proxy\u001b[0m (to Player White):\n", + "\n", + "\u001b[33mBoard Proxy\u001b[0m (to Player White):\n", + "\n", + "\u001b[32m***** Response from calling tool (No id found) *****\u001b[0m\n", + "e7e5\n", + "\u001b[32m****************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[33mPlayer White\u001b[0m (to Board Proxy):\n", + "\n", + "I made a move: e7e5. It's your turn now.\n", + "\n", + "Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n", + "\u001b[33mPlayer White\u001b[0m (to Player Black):\n", + "\n", + "I made a move: e7e5. It's your turn now.\n", + "\n", + "Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[34m\n", + "********************************************************************************\u001b[0m\n", + "\u001b[34mStarting a new chat....\n", + "\n", + "Message:\n", + "I made a move: e7e5. It's your turn now.\n", + "\n", + "Your move.\n", + "\n", + "Carryover: \n", + "\u001b[0m\n", + "\u001b[34m\n", + "********************************************************************************\u001b[0m\n", + "\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n", + "\n", + "I made a move: e7e5. It's your turn now.\n", + "\n", + "Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[33mPlayer Black\u001b[0m (to Board Proxy):\n", + "\n", + "\n", + "\u001b[32m***** Suggested tool call (No tool call id found): make_move *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m******************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION make_move...\u001b[0m\n" + ] + }, + { + "data": { + "image/svg+xml": [ + "
r n b q k b n r\n",
+       "p p p p . p p p\n",
+       ". . . . . . . .\n",
+       ". . . . p . . .\n",
+       ". . . . . . . P\n",
+       "P . . . . . . .\n",
+       ". P P P P P P .\n",
+       "R N B Q K B N R
" + ], + "text/plain": [ + "'
r n b q k b n r\\np p p p . p p p\\n. . . . . . . .\\n. . . . p . . .\\n. . . . . . . P\\nP . . . . . . .\\n. P P P P P P .\\nR N B Q K B N R
'" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n", + "\n", + "\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n", + "\n", + "\u001b[32m***** Response from calling tool (No id found) *****\u001b[0m\n", + "h2h4\n", + "\u001b[32m****************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[33mPlayer Black\u001b[0m (to Board Proxy):\n", + "\n", + "I made a move: h2h4. It's your turn now.\n", + "\n", + "Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n", + "\u001b[33mPlayer Black\u001b[0m (to Player White):\n", + "\n", + "I made a move: h2h4. It's your turn now.\n", + "\n", + "Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[34m\n", + "********************************************************************************\u001b[0m\n", + "\u001b[34mStarting a new chat....\n", + "\n", + "Message:\n", + "I made a move: h2h4. It's your turn now.\n", + "\n", + "Your move.\n", + "\n", + "Carryover: \n", + "\u001b[0m\n", + "\u001b[34m\n", + "********************************************************************************\u001b[0m\n", + "\u001b[33mBoard Proxy\u001b[0m (to Player White):\n", + "\n", + "I made a move: h2h4. It's your turn now.\n", + "\n", + "Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[33mPlayer White\u001b[0m (to Board Proxy):\n", + "\n", + "\n", + "\u001b[32m***** Suggested tool call (No tool call id found): make_move *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m******************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION make_move...\u001b[0m\n" + ] + }, + { + "data": { + "image/svg+xml": [ + "
r n b q k b . r\n",
+       "p p p p . p p p\n",
+       ". . . . . . . n\n",
+       ". . . . p . . .\n",
+       ". . . . . . . P\n",
+       "P . . . . . . .\n",
+       ". P P P P P P .\n",
+       "R N B Q K B N R
" + ], + "text/plain": [ + "'
r n b q k b . r\\np p p p . p p p\\n. . . . . . . n\\n. . . . p . . .\\n. . . . . . . P\\nP . . . . . . .\\n. P P P P P P .\\nR N B Q K B N R
'" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33mBoard Proxy\u001b[0m (to Player White):\n", + "\n", + "\u001b[33mBoard Proxy\u001b[0m (to Player White):\n", + "\n", + "\u001b[32m***** Response from calling tool (No id found) *****\u001b[0m\n", + "g8h6\n", + "\u001b[32m****************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[33mPlayer White\u001b[0m (to Board Proxy):\n", + "\n", + "You moved g8h6. I made a move: g1g3. It's your turn now.\n", + "\n", + "Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n", + "\u001b[33mPlayer White\u001b[0m (to Player Black):\n", + "\n", + "You moved g8h6. I made a move: g1g3. It's your turn now.\n", + "\n", + "Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[34m\n", + "********************************************************************************\u001b[0m\n", + "\u001b[34mStarting a new chat....\n", + "\n", + "Message:\n", + "You moved g8h6. I made a move: g1g3. It's your turn now.\n", + "\n", + "Your move.\n", + "\n", + "Carryover: \n", + "\u001b[0m\n", + "\u001b[34m\n", + "********************************************************************************\u001b[0m\n", + "\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n", + "\n", + "You moved g8h6. I made a move: g1g3. It's your turn now.\n", + "\n", + "Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[33mPlayer Black\u001b[0m (to Board Proxy):\n", + "\n", + "\n", + "\u001b[32m***** Suggested tool call (No tool call id found): make_move *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m******************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION make_move...\u001b[0m\n" + ] + }, + { + "data": { + "image/svg+xml": [ + "
r n b q k b . r\n",
+       "p p p p . p p p\n",
+       ". . . . . . . n\n",
+       ". . . . p . . .\n",
+       ". . . . . . . P\n",
+       "P . . . . . . N\n",
+       ". P P P P P P .\n",
+       "R N B Q K B . R
" + ], + "text/plain": [ + "'
r n b q k b . r\\np p p p . p p p\\n. . . . . . . n\\n. . . . p . . .\\n. . . . . . . P\\nP . . . . . . N\\n. P P P P P P .\\nR N B Q K B . R
'" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n", + "\n", + "\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n", + "\n", + "\u001b[32m***** Response from calling tool (No id found) *****\u001b[0m\n", + "g1h3\n", + "\u001b[32m****************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[33mPlayer Black\u001b[0m (to Board Proxy):\n", + "\n", + "You moved g8h6. I made a move: g1h3. You moved g1h3. It's my turn now.\n", + "\n", + "I made a move: d2d4. Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n", + "\u001b[33mPlayer Black\u001b[0m (to Player White):\n", + "\n", + "You moved g8h6. I made a move: g1h3. You moved g1h3. It's my turn now.\n", + "\n", + "I made a move: d2d4. Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[34m\n", + "********************************************************************************\u001b[0m\n", + "\u001b[34mStarting a new chat....\n", + "\n", + "Message:\n", + "You moved g8h6. I made a move: g1h3. You moved g1h3. It's my turn now.\n", + "\n", + "I made a move: d2d4. Your move.\n", + "\n", + "Carryover: \n", + "\u001b[0m\n", + "\u001b[34m\n", + "********************************************************************************\u001b[0m\n", + "\u001b[33mBoard Proxy\u001b[0m (to Player White):\n", + "\n", + "You moved g8h6. I made a move: g1h3. You moved g1h3. It's my turn now.\n", + "\n", + "I made a move: d2d4. Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[33mPlayer White\u001b[0m (to Board Proxy):\n", + "\n", + "\n", + "\u001b[32m***** Suggested tool call (No tool call id found): make_move *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m******************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION make_move...\u001b[0m\n" + ] + }, + { + "data": { + "image/svg+xml": [ + "
r n b . k b . r\n",
+       "p p p p . p p p\n",
+       ". . . . . . . n\n",
+       ". . . . p . . .\n",
+       ". . . . . . . q\n",
+       "P . . . . . . N\n",
+       ". P P P P P P .\n",
+       "R N B Q K B . R
" + ], + "text/plain": [ + "'
r n b . k b . r\\np p p p . p p p\\n. . . . . . . n\\n. . . . p . . .\\n. . . . . . . q\\nP . . . . . . N\\n. P P P P P P .\\nR N B Q K B . R
'" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33mBoard Proxy\u001b[0m (to Player White):\n", + "\n", + "\u001b[33mBoard Proxy\u001b[0m (to Player White):\n", + "\n", + "\u001b[32m***** Response from calling tool (No id found) *****\u001b[0m\n", + "d8h4\n", + "\u001b[32m****************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[33mPlayer White\u001b[0m (to Board Proxy):\n", + "\n", + "You moved d8h4. I made a move: d4d5. Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n", + "\u001b[33mPlayer White\u001b[0m (to Player Black):\n", + "\n", + "You moved d8h4. I made a move: d4d5. Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[34m\n", + "********************************************************************************\u001b[0m\n", + "\u001b[34mStarting a new chat....\n", + "\n", + "Message:\n", + "You moved d8h4. I made a move: d4d5. Your move.\n", + "\n", + "Carryover: \n", + "\u001b[0m\n", + "\u001b[34m\n", + "********************************************************************************\u001b[0m\n", + "\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n", + "\n", + "You moved d8h4. I made a move: d4d5. Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[33mPlayer Black\u001b[0m (to Board Proxy):\n", + "\n", + "\n", + "\u001b[32m***** Suggested tool call (No tool call id found): make_move *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m******************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION make_move...\u001b[0m\n" + ] + }, + { + "data": { + "image/svg+xml": [ + "
r n b . k b . r\n",
+       "p p p p . p p p\n",
+       ". . . . . . . n\n",
+       ". . . . p . . .\n",
+       ". . . . P . . q\n",
+       "P . . . . . . N\n",
+       ". P P P . P P .\n",
+       "R N B Q K B . R
" + ], + "text/plain": [ + "'
r n b . k b . r\\np p p p . p p p\\n. . . . . . . n\\n. . . . p . . .\\n. . . . P . . q\\nP . . . . . . N\\n. P P P . P P .\\nR N B Q K B . R
'" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n", + "\n", + "\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n", + "\n", + "\u001b[32m***** Response from calling tool (No id found) *****\u001b[0m\n", + "e2e4\n", + "\u001b[32m****************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[33mPlayer Black\u001b[0m (to Board Proxy):\n", + "\n", + "You made a move: e2e4. I made a move: d5e4. Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n", + "\u001b[33mPlayer Black\u001b[0m (to Player White):\n", + "\n", + "You made a move: e2e4. I made a move: d5e4. Your move.\n", + "\n", + "--------------------------------------------------------------------------------\n" + ] + } + ], + "source": [ + "# Clear the board.\n", + "board = chess.Board()\n", + "\n", + "chat_result = player_white.initiate_chat(\n", + " player_black,\n", + " message=\"Let's play chess! Your move.\",\n", + " max_turns=4,\n", + ")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "autogen", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-2.svg b/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-2.svg new file mode 100644 index 000000000000..8e39984fc25e --- /dev/null +++ b/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-2.svg @@ -0,0 +1,8 @@ +
r n b q k b n r
+p p p p p p p p
+. . . . . . . .
+. . . . . . . .
+. . . . . . . .
+P . . . . . . .
+. P P P P P P P
+R N B Q K B N R
\ No newline at end of file diff --git a/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-3.svg b/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-3.svg new file mode 100644 index 000000000000..3f2f472f1f30 --- /dev/null +++ b/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-3.svg @@ -0,0 +1,8 @@ +
r n b q k b n r
+p p p p . p p p
+. . . . . . . .
+. . . . p . . .
+. . . . . . . .
+P . . . . . . .
+. P P P P P P P
+R N B Q K B N R
\ No newline at end of file diff --git a/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-4.svg b/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-4.svg new file mode 100644 index 000000000000..7a2cbb2f1ab7 --- /dev/null +++ b/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-4.svg @@ -0,0 +1,8 @@ +
r n b q k b n r
+p p p p . p p p
+. . . . . . . .
+. . . . p . . .
+. . . . . . . P
+P . . . . . . .
+. P P P P P P .
+R N B Q K B N R
\ No newline at end of file diff --git a/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-5.svg b/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-5.svg new file mode 100644 index 000000000000..5474081b7ea6 --- /dev/null +++ b/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-5.svg @@ -0,0 +1,8 @@ +
r n b q k b . r
+p p p p . p p p
+. . . . . . . n
+. . . . p . . .
+. . . . . . . P
+P . . . . . . .
+. P P P P P P .
+R N B Q K B N R
\ No newline at end of file diff --git a/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-6.svg b/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-6.svg new file mode 100644 index 000000000000..4b6b553f7679 --- /dev/null +++ b/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-6.svg @@ -0,0 +1,8 @@ +
r n b q k b . r
+p p p p . p p p
+. . . . . . . n
+. . . . p . . .
+. . . . . . . P
+P . . . . . . N
+. P P P P P P .
+R N B Q K B . R
\ No newline at end of file diff --git a/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-7.svg b/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-7.svg new file mode 100644 index 000000000000..f3c70212296b --- /dev/null +++ b/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-7.svg @@ -0,0 +1,8 @@ +
r n b . k b . r
+p p p p . p p p
+. . . . . . . n
+. . . . p . . .
+. . . . . . . q
+P . . . . . . N
+. P P P P P P .
+R N B Q K B . R
\ No newline at end of file diff --git a/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-8.svg b/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-8.svg new file mode 100644 index 000000000000..4cda0352da61 --- /dev/null +++ b/website/docs/topics/non-openai-models/cloud-mistralai_files/figure-markdown_strict/cell-11-output-8.svg @@ -0,0 +1,8 @@ +
r n b . k b . r
+p p p p . p p p
+. . . . . . . n
+. . . . p . . .
+. . . . P . . q
+P . . . . . . N
+. P P P . P P .
+R N B Q K B . R
\ No newline at end of file From cc512d19f16f724c859f6cd597dc0be3fc8e3aaa Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Wed, 27 Mar 2024 22:21:47 +1100 Subject: [PATCH 3/3] Added example of role setting in tips page and adding info to Group Chat in conversation patterns --- .../best-tips-for-nonopenai-models.md | 25 +++++++++++++------ .../docs/tutorial/conversation-patterns.ipynb | 23 +++++++++++++++++ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/website/docs/topics/non-openai-models/best-tips-for-nonopenai-models.md b/website/docs/topics/non-openai-models/best-tips-for-nonopenai-models.md index 6dbda16e7238..875ef81b7d8c 100644 --- a/website/docs/topics/non-openai-models/best-tips-for-nonopenai-models.md +++ b/website/docs/topics/non-openai-models/best-tips-for-nonopenai-models.md @@ -28,18 +28,27 @@ selection. ## Chat template AutoGen utilises a set of chat messages for the conversation between AutoGen/user -and LLMs. Each chat message has a role attribute that is typically "user", -"assistant", or "system". +and LLMs. Each chat message has a role attribute that is typically `user`, +`assistant`, or `system`. A chat template is applied during inference and some chat templates implement rules about what roles can be used in specific sequences of messages. -For example, when using Mistral AI's API the last chat message cannot have a role of -'system'. In a Group Chat scenario the message used to select the next speaker will -have a role of 'system' by default and the API will throw an exception for this step. To -overcome this the GroupChat's constructor has a parameter called 'role_for_select_speaker_messages' -that can be used to change the role name to 'user'. See this demonstrated in the -[Mistral AI example](/docs/topics/non-openai-models/cloud-mistralai). +For example, when using Mistral AI's API the last chat message must have a role of `user`. +In a Group Chat scenario the message used to select the next speaker will have a role of +`system` by default and the API will throw an exception for this step. To overcome this the +GroupChat's constructor has a parameter called `role_for_select_speaker_messages` that can +be used to change the role name to `user`. + +```python +groupchat = autogen.GroupChat( + agents=[user_proxy, coder, pm], + messages=[], + max_round=12, + # Role for select speaker message will be set to 'user' instead of 'system' + role_for_select_speaker_messages='user', +) +``` If the chat template associated with a model you want to use doesn't support the role sequence and names used in AutoGen you can modify the chat template. See an example of diff --git a/website/docs/tutorial/conversation-patterns.ipynb b/website/docs/tutorial/conversation-patterns.ipynb index 25b66da9374c..51e537a47064 100644 --- a/website/docs/tutorial/conversation-patterns.ipynb +++ b/website/docs/tutorial/conversation-patterns.ipynb @@ -1182,6 +1182,29 @@ "This time, the agents are selected following the constraints we have specified." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Changing the select speaker role name\n", + "\n", + "As part of the Group chat process, a select speaker message is sent to the LLM\n", + "to determine the next speaker.\n", + "\n", + "Each message in the chat sequence has a `role` attribute that is typically `user`,\n", + "`assistant`, or `system`. The select speaker message is the last in the chat\n", + "sequence when used and, by default, has a role of `system`.\n", + "\n", + "When using some models, such as Mistral through Mistral.AI's API, the role on\n", + "the last message in the chat sequence has to be `user`.\n", + "\n", + "To change the default behaviour, Autogen provides a way to set the value of the\n", + "select speaker message's role to any string value by setting the\n", + "`role_for_select_speaker_messages` parameter in the GroupChat's constructor. The\n", + "default value is `system` and by setting it to `user` you can accommodate the\n", + "last message role requirement of Mistral.AI's API." + ] + }, { "cell_type": "markdown", "metadata": {},