{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "69f61d65-6362-48e5-b1a7-4bd149113849", "metadata": {}, "outputs": [], "source": [ "from transformers import AutoTokenizer\n", "\n", "tokenizer = AutoTokenizer.from_pretrained(\"meta-llama/Meta-Llama-3.1-8B-Instruct\")" ] }, { "cell_type": "code", "execution_count": 23, "id": "2f479e79-8e3d-4734-9884-ba5854a2b007", "metadata": {}, "outputs": [], "source": [ "tokenizer.chat_template = open(\"tool_calling.jinja\").read()" ] }, { "cell_type": "code", "execution_count": 24, "id": "c727dc18-9ba5-4e97-af89-697195de207a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "128009\n", "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n", "\n", "Cutting Knowledge Date: December 2023\n", "Today Date: 23 Jul 2024\n", "\n", "<|eot_id|><|start_header_id|>user<|end_header_id|>\n", "\n", "Hi<|eot_id|>\n" ] } ], "source": [ "test_chat = [{\"role\": \"user\", \"content\": \"Hi\"}]\n", "\n", "print(tokenizer.eos_token_id)\n", "\n", "print(tokenizer.apply_chat_template(test_chat, tokenize=False))" ] }, { "cell_type": "code", "execution_count": 25, "id": "928288d2-8ff3-4c69-9dbe-393b27b322cf", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n", "\n", "Cutting Knowledge Date: December 2023\n", "Today Date: 23 Jul 2024\n", "\n", "sysmsg<|eot_id|><|start_header_id|>user<|end_header_id|>\n", "\n", "Hi<|eot_id|>\n" ] } ], "source": [ "test_chat = [{\"role\": \"system\", \"content\": \"sysmsg\"}, {\"role\": \"user\", \"content\": \"Hi\"}]\n", "\n", "print(tokenizer.apply_chat_template(test_chat, tokenize=False))" ] }, { "cell_type": "code", "execution_count": 26, "id": "48c73766-3d04-4582-9784-2f1f0b9ef978", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n", "\n", "Environment: ipython\n", "Tools: brave_search\n", "\n", "Cutting Knowledge Date: December 2023\n", "Today Date: 23 Jul 2024\n", "\n", "sysmsg<|eot_id|><|start_header_id|>user<|end_header_id|>\n", "\n", "Hi<|eot_id|>\n" ] } ], "source": [ "test_chat = [{\"role\": \"system\", \"content\": \"sysmsg\"}, {\"role\": \"user\", \"content\": \"Hi\"}]\n", "\n", "\n", "print(tokenizer.apply_chat_template(test_chat, tokenize=False, builtin_tools=[\"brave_search\"]))" ] }, { "cell_type": "code", "execution_count": 8, "id": "dc73761d-a1e6-4a13-86b7-d877c81555e6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n", "\n", "Environment: ipython\n", "Tools: brave_search, wolfram_alpha\n", "\n", "Cutting Knowledge Date: December 2023\n", "Today Date: 23 Jul 2024\n", "\n", "sysmsg<|eot_id|><|start_header_id|>user<|end_header_id|>\n", "\n", "Hi<|eot_id|>\n" ] } ], "source": [ "test_chat = [{\"role\": \"system\", \"content\": \"sysmsg\"}, {\"role\": \"user\", \"content\": \"Hi\"}]\n", "\n", "\n", "print(tokenizer.apply_chat_template(test_chat, tokenize=False, builtin_tools=[\"brave_search\", \"wolfram_alpha\"]))" ] }, { "cell_type": "code", "execution_count": 27, "id": "cff52d85-189a-4f0d-9371-d10644f6db89", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n", "\n", "Environment: ipython\n", "Tools: brave_search\n", "\n", "Cutting Knowledge Date: December 2023\n", "Today Date: 23 Jul 2024\n", "\n", "sysmsg<|eot_id|><|start_header_id|>user<|end_header_id|>\n", "\n", "Given the following functions, please respond with a JSON for a function call with its proper arguments that best answers the given prompt.\n", "\n", "Respond in the format {\"name\": function name, \"parameters\": dictionary of argument name and its value}.Do not use variables.\n", "\n", "{\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"get_current_weather\",\n", " \"description\": \"Gets the current weather.\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", " \"location\": {\n", " \"type\": \"string\",\n", " \"description\": \"The location to get the weather for\"\n", " }\n", " },\n", " \"required\": [\n", " \"location\"\n", " ]\n", " }\n", " }\n", "}\n", "\n", "{\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"get_current_weather2\",\n", " \"description\": \"Gets the current weather.\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", " \"location\": {\n", " \"type\": \"string\",\n", " \"description\": \"The location to get the weather for\"\n", " }\n", " },\n", " \"required\": [\n", " \"location\"\n", " ]\n", " }\n", " }\n", "}\n", "\n", "Question: Hi<|eot_id|>\n" ] } ], "source": [ "test_chat = [\n", " {\"role\": \"system\", \"content\": \"sysmsg\"}, \n", " {\"role\": \"user\", \"content\": \"Hi\"}\n", "]\n", "\n", "\n", "def get_current_weather(location: str):\n", " \"\"\"\n", " Gets the current weather.\n", "\n", " Args:\n", " location: The location to get the weather for\n", " \"\"\"\n", " pass\n", "\n", "def get_current_weather2(location: str):\n", " \"\"\"\n", " Gets the current weather.\n", "\n", " Args:\n", " location: The location to get the weather for\n", " \"\"\"\n", " pass\n", "\n", "\n", "print(tokenizer.apply_chat_template(test_chat, tokenize=False, builtin_tools=[\"brave_search\"], tools=[get_current_weather, get_current_weather2]))" ] }, { "cell_type": "code", "execution_count": 28, "id": "1ff3837c-e618-4359-9223-80d00aebf06d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n", "\n", "Cutting Knowledge Date: December 2023\n", "Today Date: 23 Jul 2024\n", "\n", "sysmsg<|eot_id|><|start_header_id|>user<|end_header_id|>\n", "\n", "Given the following functions, please respond with a JSON for a function call with its proper arguments that best answers the given prompt.\n", "\n", "Respond in the format {\"name\": function name, \"parameters\": dictionary of argument name and its value}.Do not use variables.\n", "\n", "{\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"get_current_weather\",\n", " \"description\": \"Gets the current weather.\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", " \"location\": {\n", " \"type\": \"string\",\n", " \"description\": \"The location to get the weather for\"\n", " }\n", " },\n", " \"required\": [\n", " \"location\"\n", " ]\n", " }\n", " }\n", "}\n", "\n", "{\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"get_current_weather2\",\n", " \"description\": \"Gets the current weather.\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", " \"location\": {\n", " \"type\": \"string\",\n", " \"description\": \"The location to get the weather for\"\n", " }\n", " },\n", " \"required\": [\n", " \"location\"\n", " ]\n", " }\n", " }\n", "}\n", "\n", "Question: Hi<|eot_id|>\n" ] } ], "source": [ "test_chat = [\n", " {\"role\": \"system\", \"content\": \"sysmsg\"}, \n", " {\"role\": \"user\", \"content\": \"Hi\"}\n", "]\n", "\n", "\n", "def get_current_weather(location: str):\n", " \"\"\"\n", " Gets the current weather.\n", "\n", " Args:\n", " location: The location to get the weather for\n", " \"\"\"\n", " pass\n", "\n", "def get_current_weather2(location: str):\n", " \"\"\"\n", " Gets the current weather.\n", "\n", " Args:\n", " location: The location to get the weather for\n", " \"\"\"\n", " pass\n", "\n", "\n", "print(tokenizer.apply_chat_template(test_chat, tokenize=False, tools=[get_current_weather, get_current_weather2]))" ] }, { "cell_type": "code", "execution_count": 11, "id": "8c2a3cbf-aa5e-4a1e-a86a-68c8fc370681", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n", "\n", "Cutting Knowledge Date: December 2023\n", "Today Date: 23 Jul 2024\n", "\n", "<|eot_id|><|start_header_id|>user<|end_header_id|>\n", "\n", "Given the following functions, please respond with a JSON for a function call with its proper arguments that best answers the given prompt.\n", "\n", "Respond in the format {\"name\": function name, \"parameters\": dictionary of argument name and its value}.Do not use variables.\n", "\n", "{\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"get_current_weather\",\n", " \"description\": \"Gets the current weather.\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", " \"location\": {\n", " \"type\": \"string\",\n", " \"description\": \"The location to get the weather for\"\n", " }\n", " },\n", " \"required\": [\n", " \"location\"\n", " ]\n", " }\n", " }\n", "}\n", "\n", "{\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"get_current_weather2\",\n", " \"description\": \"Gets the current weather.\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", " \"location\": {\n", " \"type\": \"string\",\n", " \"description\": \"The location to get the weather for\"\n", " }\n", " },\n", " \"required\": [\n", " \"location\"\n", " ]\n", " }\n", " }\n", "}\n", "\n", "Question: Hi<|eot_id|>\n" ] } ], "source": [ "test_chat = [\n", " {\"role\": \"user\", \"content\": \"Hi\"}\n", "]\n", "\n", "\n", "def get_current_weather(location: str):\n", " \"\"\"\n", " Gets the current weather.\n", "\n", " Args:\n", " location: The location to get the weather for\n", " \"\"\"\n", " pass\n", "\n", "def get_current_weather2(location: str):\n", " \"\"\"\n", " Gets the current weather.\n", "\n", " Args:\n", " location: The location to get the weather for\n", " \"\"\"\n", " pass\n", "\n", "\n", "print(tokenizer.apply_chat_template(test_chat, tokenize=False, tools=[get_current_weather, get_current_weather2]))" ] }, { "cell_type": "code", "execution_count": 12, "id": "19467ecf-7e4b-4b83-92ed-abe6a85d97f4", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n", "\n", "Environment: ipython\n", "Tools: brave_search\n", "\n", "Cutting Knowledge Date: December 2023\n", "Today Date: 23 Jul 2024\n", "\n", "<|eot_id|><|start_header_id|>user<|end_header_id|>\n", "\n", "Given the following functions, please respond with a JSON for a function call with its proper arguments that best answers the given prompt.\n", "\n", "Respond in the format {\"name\": function name, \"parameters\": dictionary of argument name and its value}.Do not use variables.\n", "\n", "{\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"spotify_trending_songs\",\n", " \"description\": \"Get top trending songs on Spotify\",\n", " \"parameters\": {\n", " \"n\": {\n", " \"param_type\": \"int\",\n", " \"description\": \"Number of trending songs to get\",\n", " \"required\": \"true\"\n", " }\n", " }\n", " }\n", "}\n", "\n", "{\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"get_current_temperature\",\n", " \"description\": \"Get the current temperature for a specific location\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", " \"location\": {\n", " \"type\": \"string\",\n", " \"description\": \"The city and state, e.g., San Francisco, CA\"\n", " },\n", " \"unit\": {\n", " \"type\": \"string\",\n", " \"enum\": [\n", " \"Celsius\",\n", " \"Fahrenheit\"\n", " ],\n", " \"description\": \"The temperature unit to use. Infer this from the user's location.\"\n", " }\n", " },\n", " \"required\": [\n", " \"location\",\n", " \"unit\"\n", " ]\n", " }\n", " }\n", "}\n", "\n", "{\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"get_rain_probability\",\n", " \"description\": \"Get the probability of rain for a specific location\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", " \"location\": {\n", " \"type\": \"string\",\n", " \"description\": \"The city and state, e.g., San Francisco, CA\"\n", " }\n", " },\n", " \"required\": [\n", " \"location\"\n", " ]\n", " }\n", " }\n", "}\n", "\n", "{\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"get_current_weather\",\n", " \"description\": \"Gets the current weather.\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", " \"location\": {\n", " \"type\": \"string\",\n", " \"description\": \"The location to get the weather for\"\n", " }\n", " },\n", " \"required\": [\n", " \"location\"\n", " ]\n", " }\n", " }\n", "}\n", "\n", "{\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"get_current_weather2\",\n", " \"description\": \"Gets the current weather.\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", " \"location\": {\n", " \"type\": \"string\",\n", " \"description\": \"The location to get the weather for\"\n", " }\n", " },\n", " \"required\": [\n", " \"location\"\n", " ]\n", " }\n", " }\n", "}\n", "\n", "Question: Hi<|eot_id|>\n" ] } ], "source": [ "json_tools = [ \n", " { \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"spotify_trending_songs\",\n", " \"description\": \"Get top trending songs on Spotify\",\n", " \"parameters\": {\n", " \"n\": {\n", " \"param_type\": \"int\",\n", " \"description\": \"Number of trending songs to get\",\n", " \"required\": \"true\"\n", " }\n", " }\n", " }\n", " },\n", " {\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"get_current_temperature\",\n", " \"description\": \"Get the current temperature for a specific location\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", " \"location\": {\n", " \"type\": \"string\",\n", " \"description\": \"The city and state, e.g., San Francisco, CA\"\n", " },\n", " \"unit\": {\n", " \"type\": \"string\",\n", " \"enum\": [\"Celsius\", \"Fahrenheit\"],\n", " \"description\": \"The temperature unit to use. Infer this from the user's location.\"\n", " }\n", " },\n", " \"required\": [\"location\", \"unit\"]\n", " }\n", " }\n", " },\n", " {\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"get_rain_probability\",\n", " \"description\": \"Get the probability of rain for a specific location\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", " \"location\": {\n", " \"type\": \"string\",\n", " \"description\": \"The city and state, e.g., San Francisco, CA\"\n", " }\n", " },\n", " \"required\": [\"location\"]\n", " }\n", " }\n", " }\n", "]\n", "\n", "json_tools.extend([get_current_weather, get_current_weather2])\n", "\n", "print(tokenizer.apply_chat_template(test_chat, tokenize=False, builtin_tools=[\"brave_search\"], tools=json_tools))" ] }, { "cell_type": "code", "execution_count": 20, "id": "3258c966-11f9-462e-a99d-15969289b630", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n", "\n", "Environment: ipython\n", "Tools: brave_search\n", "\n", "Cutting Knowledge Date: December 2023\n", "Today Date: 23 Jul 2024\n", "\n", "sysmsg<|eot_id|><|start_header_id|>user<|end_header_id|>\n", "\n", "Given the following functions, please respond with a JSON for a function call with its proper arguments that best answers the given prompt.\n", "\n", "Respond in the format {\"name\": function name, \"parameters\": dictionary of argument name and its value}.Do not use variables.\n", "\n", "{\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"get_current_weather\",\n", " \"description\": \"Gets the current weather.\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", " \"location\": {\n", " \"type\": \"string\",\n", " \"description\": \"The location to get the weather for\"\n", " }\n", " },\n", " \"required\": [\n", " \"location\"\n", " ]\n", " }\n", " }\n", "}\n", "\n", "{\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"get_current_weather2\",\n", " \"description\": \"Gets the current weather.\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", " \"location\": {\n", " \"type\": \"string\",\n", " \"description\": \"The location to get the weather for\"\n", " }\n", " },\n", " \"required\": [\n", " \"location\"\n", " ]\n", " }\n", " }\n", "}\n", "\n", "Question: Hi<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n", "\n", "{\"name\": \"get_current_weather\", \"parameters\": {\"location\": \"Paris, France\"}}<|eom_id|><|start_header_id|>ipython<|end_header_id|>\n", "\n", "\"22.0\"<|eot_id|>\n" ] } ], "source": [ "tool_call = {\"name\": \"get_current_weather\", \"arguments\": {\"location\": \"Paris, France\"}}\n", "test_chat = [\n", " {\"role\": \"system\", \"content\": \"sysmsg\"},\n", " {\"role\": \"user\", \"content\": \"Hi\"},\n", " {\"role\": \"assistant\", \"tool_calls\": [{\"type\": \"function\", \"function\": tool_call}]},\n", " {\"role\": \"tool\", \"name\": \"get_current_weather\", \"content\": \"22.0\"}\n", "]\n", "\n", "\n", "print(tokenizer.apply_chat_template(test_chat, tokenize=False, builtin_tools=[\"brave_search\"], tools=[get_current_weather, get_current_weather2]))" ] }, { "cell_type": "code", "execution_count": 21, "id": "492fbc6a-2708-4712-bbd1-f7ae7e62846d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n", "\n", "Environment: ipython\n", "Tools: brave_search\n", "\n", "Cutting Knowledge Date: December 2023\n", "Today Date: 23 Jul 2024\n", "\n", "sysmsg<|eot_id|><|start_header_id|>user<|end_header_id|>\n", "\n", "Given the following functions, please respond with a JSON for a function call with its proper arguments that best answers the given prompt.\n", "\n", "Respond in the format {\"name\": function name, \"parameters\": dictionary of argument name and its value}.Do not use variables.\n", "\n", "{\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"get_current_weather\",\n", " \"description\": \"Gets the current weather.\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", " \"location\": {\n", " \"type\": \"string\",\n", " \"description\": \"The location to get the weather for\"\n", " }\n", " },\n", " \"required\": [\n", " \"location\"\n", " ]\n", " }\n", " }\n", "}\n", "\n", "{\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"get_current_weather2\",\n", " \"description\": \"Gets the current weather.\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", " \"location\": {\n", " \"type\": \"string\",\n", " \"description\": \"The location to get the weather for\"\n", " }\n", " },\n", " \"required\": [\n", " \"location\"\n", " ]\n", " }\n", " }\n", "}\n", "\n", "Question: Hi<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n", "\n", "{\"name\": \"get_current_weather\", \"parameters\": {\"location\": \"Paris, France\"}}<|eom_id|><|start_header_id|>ipython<|end_header_id|>\n", "\n", "{\"location\": \"Paris, France\", \"temperature\": \"22.0\"}<|eot_id|>\n" ] } ], "source": [ "tool_call = {\"name\": \"get_current_weather\", \"arguments\": {\"location\": \"Paris, France\"}}\n", "test_chat = [\n", " {\"role\": \"system\", \"content\": \"sysmsg\"},\n", " {\"role\": \"user\", \"content\": \"Hi\"},\n", " {\"role\": \"assistant\", \"tool_calls\": [{\"type\": \"function\", \"function\": tool_call}]},\n", " {\"role\": \"tool\", \"content\": {\n", " \"location\": \"Paris, France\", \n", " \"temperature\": \"22.0\"\n", " }}\n", "]\n", "\n", "\n", "print(tokenizer.apply_chat_template(test_chat, tokenize=False, builtin_tools=[\"brave_search\"], tools=[get_current_weather, get_current_weather2]))" ] }, { "cell_type": "code", "execution_count": 22, "id": "ecc701c0-e364-40e9-a745-0ef07eeee3bb", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n", "\n", "Environment: ipython\n", "Tools: brave_search\n", "\n", "Cutting Knowledge Date: December 2023\n", "Today Date: 23 Jul 2024\n", "\n", "sysmsg<|eot_id|><|start_header_id|>user<|end_header_id|>\n", "\n", "Given the following functions, please respond with a JSON for a function call with its proper arguments that best answers the given prompt.\n", "\n", "Respond in the format {\"name\": function name, \"parameters\": dictionary of argument name and its value}.Do not use variables.\n", "\n", "{\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"get_current_weather\",\n", " \"description\": \"Gets the current weather.\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", " \"location\": {\n", " \"type\": \"string\",\n", " \"description\": \"The location to get the weather for\"\n", " }\n", " },\n", " \"required\": [\n", " \"location\"\n", " ]\n", " }\n", " }\n", "}\n", "\n", "{\n", " \"type\": \"function\",\n", " \"function\": {\n", " \"name\": \"get_current_weather2\",\n", " \"description\": \"Gets the current weather.\",\n", " \"parameters\": {\n", " \"type\": \"object\",\n", " \"properties\": {\n", " \"location\": {\n", " \"type\": \"string\",\n", " \"description\": \"The location to get the weather for\"\n", " }\n", " },\n", " \"required\": [\n", " \"location\"\n", " ]\n", " }\n", " }\n", "}\n", "\n", "Question: Hi<|eot_id|><|python_tag|>\n", "brave_search.call(query=\"weather in Paris, France\")<|eom_id|><|start_header_id|>ipython<|end_header_id|>\n", "\n", "{\"location\": \"Paris, France\", \"temperature\": \"22.0\"}<|eot_id|>\n" ] } ], "source": [ "tool_call = {\"name\": \"brave_search\", \"arguments\": {\"query\": \"weather in Paris, France\"}}\n", "test_chat = [\n", " {\"role\": \"system\", \"content\": \"sysmsg\"},\n", " {\"role\": \"user\", \"content\": \"Hi\"},\n", " {\"role\": \"assistant\", \"tool_calls\": [{\"type\": \"function\", \"function\": tool_call}]},\n", " {\"role\": \"tool\", \"content\": {\n", " \"location\": \"Paris, France\", \n", " \"temperature\": \"22.0\"\n", " }}\n", "]\n", "\n", "\n", "print(tokenizer.apply_chat_template(test_chat, tokenize=False, builtin_tools=[\"brave_search\"], tools=[get_current_weather, get_current_weather2]))" ] }, { "cell_type": "code", "execution_count": null, "id": "de97fe82-135f-4dfe-99be-8008383f1f9f", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.9" } }, "nbformat": 4, "nbformat_minor": 5 }