Function Calling === ###### tags: `LLM / datasets` ###### tags: `LLM`, `datasets`, `資料集`, `AFS`, `FFM`, `model` `LLaMA`, `LLaMA3`, `Mistral 8x22B`, `OpenAI`, `function calling`, `function_calling`, `tool calls` <br> [TOC] <br> ## AFS ### Function Calling > https://docs.twcc.ai/docs/user-guides/twcc/afs/afs-modelspace/api-and-parameters/function-calling <br> <hr> <br> ## AFS / LLaMA2 ### Function-Calling 訓練資料集 - [marclove/llama_functions](https://huggingface.co/datasets/marclove/llama_functions) [![](https://hackmd.io/_uploads/ByeRdlsf0.png)](https://huggingface.co/datasets/marclove/llama_functions) ### record2 > `[INST] <<SYS>> <<API>> You may answer by calling one of the following functions. If you can infer a function's required arguments, respond with a the function name and arguments. If multiple functions can be called, pick the one that best answers the question. ``` {"functions":[{"name":"generate_statistical_report","description":"Generates a statistical report for a given data set based on the specified type of analysis.","parameters":[{"description":"An array of numbers representing the data set.","items":{"description":"A single number from the data set.","type":"number"},"name":"dataSet","type":"array"},{"description":"The type of statistical analysis to perform on the data set. Valid values are 'mean', 'median', 'mode', 'range', and 'standard deviation'.","name":"type","type":"string"}]},{"name":"accountPlanAddonCreate","description":"Add an additional plan for sub account <aside>Can only add an Additional plan for the sub account which is a paid account and paid by master account</aside>","parameters":{"properties":{"accountId":{"description":null,"type":null},"body":{"description":"Account plan object","type":"object"}},"required":"accountId","type":"object"}},{"name":"userSettings","description":"Retrieve a user's settings","parameters":{"properties":{"login_type":{"description":null,"type":null},"userId":{"description":null,"type":null}},"required":"userId","type":"object"}}]} ``` <</API>> <</SYS>> Hey there! Can we create a new basic plan for account 90123456? It should be active from October 10th until November 10th, and we don't need any extra seats. [/INST]` ```json= { "functions":[ { "name":"generate_statistical_report", "description":"Generates a statistical report for a given data set based on the specified type of analysis.", "parameters":[ { "description":"An array of numbers representing the data set.", "items":{ "description":"A single number from the data set.", "type":"number" }, "name":"dataSet", "type":"array" }, { "description":"The type of statistical analysis to perform on the data set. Valid values are 'mean', 'median', 'mode', 'range', and 'standard deviation'.", "name":"type", "type":"string" } ] }, { "name":"accountPlanAddonCreate", "description":"Add an additional plan for sub account <aside>Can only add an Additional plan for the sub account which is a paid account and paid by master account</aside>", "parameters":{ "properties":{ "accountId":{ "description":null, "type":null }, "body":{ "description":"Account plan object", "type":"object" } }, "required":"accountId", "type":"object" } }, { "name":"userSettings", "description":"Retrieve a user's settings", "parameters":{ "properties":{ "login_type":{ "description":null, "type":null }, "userId":{ "description":null, "type":null } }, "required":"userId", "type":"object" } } ] } ``` <br> ### Playground - ### 舊版格式 ```= [INST] <<SYS>> You are a helpful research assistant. The following functions are available for you to fetch further data to answer user questions, if relevant: { "functions": [ { "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA" } } } } ] } To call a function, response - immediately and only - with a JSON object of the following format: { "function_call": { "arguments": {"parameter_name": "parameter value"}, "name": "function name" } } <</SYS>> What's the weather like in Tainan? [/INST] ``` ![](https://hackmd.io/_uploads/BJ4OJGszC.png) --- - 新竹的天氣如何? ![](https://hackmd.io/_uploads/BJB9-GofA.png =40%x) --- - 新竹和桃園的天氣如何? ![image](https://hackmd.io/_uploads/SJVZNfjM0.png =40%x) - `<|func_end|>` -> 錯亂 --- - 未來一週的天氣如何? ![](https://hackmd.io/_uploads/ByVuHzofC.png =40%x) --- - 變更 function 的 description ![](https://hackmd.io/_uploads/BJDyIzjGC.png =40%x) - 結果如下 ![](https://hackmd.io/_uploads/H16e8foGR.png =40%x) --- - 我想要去北海道小樽旅遊~ ![](https://hackmd.io/_uploads/ByaTuGoG0.png =40%x) --- - 我想要去北海道小樽旅遊,有什麼推薦行程?(答非所問) ![](https://hackmd.io/_uploads/rycBYfif0.png =40%x) - ### 新版格式(2024/05/10) - ### Step1 ```= <s>[INST] <<FUNC>> [ { "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA" } } } } ] <</FUNC>> <<SYS>> 你是氣象兼旅遊達人。 <</SYS>> 北海道小樽在下雪嗎?[/INST] ``` - 執行結果: ![](https://hackmd.io/_uploads/BJlrxLjf0.png =50%x) - ### Step2:假設從第三方取得資料 ``` ... 北海道小樽在下雪嗎?[/INST]<|func_start|> { "name": "get_current_weather", "arguments": { "location": "北海道小樽" } }<|func_end|> </s> <s> <<RET>> name="get_current_weather" {"Temperature": -10, "temp_min":-15, "temp_max":2, "pressure":1009, "humidity":45} <</RET>> ``` - 執行結果: ![](https://hackmd.io/_uploads/Hy2UGIjGA.png) ### FFM / curl test - ### 2024/05/10 - endpoint - `https://api-ffm-stg.twcc.ai/api/models/conversation` -> OK - `https://api-ffm-stg.twcc.ai/text-generation/api/models/conversation` -> OK (多了`text-generation`) - ### DEMO - phase1 ```bash= export API_KEY="********-****-****-****-************" export API_URL="https://api-ffm-stg.twcc.ai" echo ${API_KEY} echo ${API_URL} curl -X POST "${API_URL}/api/models/conversation" \ -H "accept: application/json" \ -H "X-API-KEY:${API_KEY}" \ -H "content-type: application/json" \ -d '{ "model": "llama2-70b-chat-36k-zhenv3-ft-0225", "messages": [ { "role": "user", "content": "北海道小樽的天氣如何?" }], "functions": [ { "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA" }, "unit": { "type": "string", "enum": ["celsius", "fahrenheit"] } }, "required": ["location"] } }], "parameters": { "show_probabilities": false, "max_new_tokens": 50, "frequence_penalty": 1, "temperature": 0.5, "top_k": 100, "top_p": 0.93 }, "stream": false }' ``` - 執行結果 > `{"generated_text":"","function_call":{"name":"get_current_weather","arguments":{"location":"北海道小樽","unit":"celsius"}},"details":null,"total_time_taken":"4.43 sec","prompt_tokens":184,"generated_tokens":50,"total_tokens":234,"finish_reason":"function_call"}` 結構化表示: ```json= { "generated_text":"", "function_call":{ "name":"get_current_weather", "arguments":{ "location":"北海道小樽" } }, "details":null, "total_time_taken":"3.34 sec", "prompt_tokens":181, "generated_tokens":37, "total_tokens":218, "finish_reason":"function_call" } ``` - ### DEMO - phase2 ```bash= export API_KEY="${API_KEY}" export API_URL="https://api-ffm-stg.twcc.ai" echo ${API_KEY} echo ${API_URL} curl -X POST "${API_URL}/api/models/conversation" \ -H "accept: application/json" \ -H "X-API-KEY:${API_KEY}" \ -H "content-type: application/json" \ -d '{ "model": "llama2-70b-chat-36k-zhenv3-ft-0225", "messages": [ { "role": "system", "content": "你是氣象專家兼旅遊達人。" }, { "role": "user", "content": "北海道小樽的天氣如何?" }, { "role": "assistant", "content": null, "tool_calls": [ { "id":"call_1a2b3c4d", "type":"function", "function":{ "name": "get_current_weather", "arguments": "{\n\"location\": \"北海道小樽\"\n}" } } ], "finish_reason": "function_calls" }, { "role": "function", "tool_call_id":"call_1a2b3c4d", "name":"xxx", "content": "{\"Temperature\": \"-10℃\", \"Condition\": \"Snowing\"}" } ], "functions": [ { "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA" }, "unit": { "type": "string", "enum": ["celsius", "fahrenheit"] } }, "required": ["location"] } }], "parameters": { "show_probabilities": false, "max_new_tokens": 50, "frequence_penalty": 1, "temperature": 0.5, "top_k": 100, "top_p": 0.93 }, "stream": false }' ``` <br> <br> <hr> <br> ## Mistral > Mixtral 8x22B 有支援 > https://docs.mistral.ai/capabilities/function_calling/ <br> <hr> <br> ## OpenAI > - github: https://github.com/openai/openai-python > - 使用版本 openai==1.25.2 <br> ### Usages - [Function calling(Beta)](https://platform.openai.com/docs/guides/function-calling) - [[cookbook] How to call functions with chat models](https://cookbook.openai.com/examples/how_to_call_functions_with_chat_models) <br> ### DEMO-1: 呼叫 function_call ```python= from openai import OpenAI import os import json client = OpenAI(api_key=os.environ.get('API_KEY')) response = client.chat.completions.create( model='gpt-4', messages=[ {'role': 'system', 'content': '你是氣象專家'}, {'role': 'user', 'content':'台南的天氣如何?'}, ], functions=[{ "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA", }, }, "required": ["location"], }, }], function_call="auto", ) print(f"response:\n{response}") ``` - `print(f"response:\n{response}")` > ChatCompletion(id='chatcmpl-9MVSzxeu6gVjU0z6qOmPEzZ0VkIF1', choices=[Choice(finish_reason='function_call', index=0, logprobs=None, message=ChatCompletionMessage(++**content=None**++, role='assistant', ++**function_call=FunctionCall(arguments='{\n "location": "台南"\n}', name='get_current_weather')**++, tool_calls=None))], created=1715151201, model='gpt-4-0613', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=17, prompt_tokens=81, total_tokens=98)) - `print(f"response:\n{response.dict()['choices'][0]}")` > response: > {'finish_reason': 'function_call', 'index': 0, 'logprobs': None, 'message': {'content': None, 'role': 'assistant', 'function_call': {'arguments': '{\n "location": "台南"\n}', 'name': 'get_current_weather'}, 'tool_calls': None}} - `print(f"function_call:\n{response.dict()['choices'][0]['message']['function_call']}")` > function_call: > {'arguments': '{\n "location": "台南"\n}', 'name': 'get_current_weather'} - ### [參數] 缺 type 會有錯誤 ```python= functions=[{ "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "properties": { "location": { "description": "The city and state, e.g. San Francisco, CA", }, }, "required": ["location"], }, }], ``` ``` BadRequestError: Error code: 400 - { 'error': { 'message': 'Invalid schema for function \'get_current_weather\': schema must be a JSON Schema of \'type: "object"\', got \'type: "None"\'.', 'type': 'invalid_request_error', 'param': 'functions[0].parameters', 'code': 'invalid_function_parameters' } } ``` <br> ### DEMO-2: 攜帶從第三方查詢到的資料 ```python= from openai import OpenAI import os import json client = OpenAI(api_key=os.environ.get('API_KEY')) function_response = {'corrd': {'lon': 120.2133, 'lat':22.9908}, 'weather': [{'id':802, 'main':'clouds', 'description':'多雲', 'icon':'03d'}], 'base':'stations', 'main':{'temp':31.95, 'feels_like':36.37, 'temp_min':31.6, 'temp_max':32.88, 'pressure':1009, 'humidity':58}, 'visibility':10000, 'wind': {'speed':5.14, 'deg':280}, 'clouds':{'all':40}, 'dt':168757688, 'sys':{'type':1, 'id':7945, 'country':'TW', 'sunrise':1687727728, 'sunset': 1687776482}, 'timezoe':28800, 'id':1668355, 'name':'Tainan City', 'cod':200} function_response = json.dumps(function_response) function_response response = client.chat.completions.create( model='gpt-4', messages=[ {'role': 'system', 'content': '你是氣象專家'}, {'role': 'user', 'content':'台南的天氣如何?'}, {'role': 'assistant', 'content': '', 'function_call': { 'name': 'get_current_weather', 'arguments': '{"location": "台南"}' } }, {"role": "function", "name": "get_current_weather", "content": function_response}, ], functions=[{ "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA", }, }, "required": ["location"], }, }], function_call="auto", ) print(f"response:\n{response}") ``` > response: ChatCompletion(id='chatcmpl-9MVdluBpoWgMMxKDos2iQYLfvKrSG', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(++**content='目前台南市的天氣狀況為多雲,氣溫為31.95度,體感溫度約為36.37度。相對溼度為58%,風速約為5.14公尺/秒,風向為280度。能見度為10公里。'**++, role='assistant', ++**function_call=None**++, tool_calls=None))], created=1715151869, model='gpt-4-0613', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=98, prompt_tokens=337, total_tokens=435)) <br> <hr> <br> ### 測試反應 - ### 正常情況-1:中文問,回傳中文 ```python= messages=[ {'role': 'system', 'content': '你是氣象專家'}, {'role': 'user', 'content':'台南的天氣如何?'}, ], functions=[{ ... }], ``` > ChatCompletion(id='chatcmpl-9M46Q3NilyJbomJSbsRtXXnnNXwRU', choices=[Choice(finish_reason='function_call', index=0, logprobs=None, message=ChatCompletionMessage(++**content=None**++, role='assistant', ++**function_call=FunctionCall(arguments='{\n "location": "台南"\n}', name='get_current_weather')**++, tool_calls=None))], created=1715046014, model='gpt-4-0613', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=17, prompt_tokens=81, total_tokens=98)) - ### 正常情況-2:日文問,回傳英文(!!) ```python= messages=[ {'role': 'system', 'content': 'あなたは気象専門家です。'}, {'role': 'user', 'content':'台南の天気はどうですか?'}, ], functions=[{ ... }], ``` > ChatCompletion(id='chatcmpl-9MW5aS1DzTiwaYeTKWjyajEHs9zGs', choices=[Choice(finish_reason='function_call', index=0, logprobs=None, message=ChatCompletionMessage(++**content=None**++, role='assistant', ++**function_call=FunctionCall(arguments='{\n "location": "Tainan"\n}', name='get_current_weather')**++, tool_calls=None))], created=1715153594, model='gpt-4-0613', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=18, prompt_tokens=87, total_tokens=105)) - ### 故意移除 function 定義:Case1 - 等同於一般問答 ```python= completion = client.chat.completions.create( model='gpt-4', messages=[ {'role': 'system', 'content': '你是氣象專家'}, {'role': 'user', 'content':'台南的天氣如何?'}, ], # functions=[{ # "name": "get_current_weather", # "description": "Get the current weather in a given location", # "parameters": { # "type": "object", # "properties": { # "location": { # "type": "string", # "description": "The city and state, e.g. San Francisco, CA", # }, # }, # "required": ["location"], # }, # }], # function_call="auto", ) completion ``` > ChatCompletion(id='chatcmpl-9LqNCPq9zKrHzgMxswYnEKDCUpMPd', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(++**content='抱歉,由於我是一個AI,我無法提供實時的天氣資訊,請您查詢相關網站或APP獲取最新的天氣狀況。'**++, role='assistant', ++**function_call=None**++, tool_calls=None))], created=1714993238, model='gpt-4-0613', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=64, prompt_tokens=28, total_tokens=92)) - ### 故意移除 function 定義:Case2 - 但,有攜帶從第三方查詢到的資料 ```python= completion = client.chat.completions.create( model='gpt-4', messages=[ {'role': 'system', 'content': 'あなたは気象専門家です。'}, {'role': 'user', 'content':'台南の天気はどうですか?'}, {'role': 'assistant', 'content': '', 'function_call': { 'name': 'get_current_weather', 'arguments': '{"location": "Tainan"}' } }, {"role": "function", "name": "get_current_weather", "content": function_response }, ] ) completion ``` - `completion.dict()['choices'][0]['message']['content']` > '現在の台南市の天気は多云で、温度は31.95℃、体感温度は36.37℃です。最低温度は31.6℃、最高温度は32.88℃です。風速は5.14 km/h、風向は280度です。湿度は58%で、気圧は1009 hPaです。視界は10000メートルです。' - ### 故意移除 assistant 的 function all 回答 (等於 assistant 是空白回應?) > - assistant 是空白回應,還是能根據 function_response 內容正常回應! > - 即使 function name 隨便定義,還是能根據 function_response 內容正常回應! ```python= completion = client.chat.completions.create( model='gpt-4', messages=[ {'role': 'system', 'content': '你是氣象專家'}, {'role': 'user', 'content':'台南的天氣如何?'}, {"role": "function", "name": "get_current_weather", "content": function_response}, ], ) completion ``` > ChatCompletion(id='chatcmpl-9MWHXcY3BZgzwcefE6A7yZ7W4TgKf', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(++**content='目前台南市的天氣狀況為多雲,溫度約為31.95度,體感溫度為36.37度。最低溫度為31.6度,最高溫度為32.88度。氣壓為1009,濕度為58%。風速為5.14,風向為280度。能見度為10000公尺。'**++, role='assistant', ++**function_call=None**++, tool_calls=None))], created=1715154335, model='gpt-4-0613', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=127, prompt_tokens=266, total_tokens=393)) --- > name 隨便定義,不影響推論... ```python= completion = client.chat.completions.create( model='gpt-4', messages=[ {'role': 'system', 'content': '你是氣象專家'}, {'role': 'user', 'content':'台南的天氣如何?'}, {"role": "function", "name": "xxx", "content": function_response}, ], ) completion ``` > ChatCompletion(id='chatcmpl-9MWMhfhL7HIURmTojoZLeulbQ5SRx', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(++**content='目前台南的天氣為多雲,氣溫約為31.95度,體感溫度約為36.37度。最低氣溫為31.6度,最高氣溫為32.88度。氣壓為1009百帕,濕度為58%。風速為每秒5.14公尺,風向為280度。可見度為10000公尺。'**++, role='assistant', ++**function_call=None**++, tool_calls=None))], created=1715154655, model='gpt-4-0613', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=135, prompt_tokens=264, total_tokens=399)) - name 參數是必要的,且長度 > 0 - BadRequestError: Error code: 400 - {'error': {'message': **"Missing parameter 'name': messages with role 'function' must have a 'name'."**, 'type': 'invalid_request_error', 'param': 'messages.[2].name', 'code': None}} - BadRequestError: Error code: 400 - {'error': {'message': **"Invalid 'messages[2].name': empty string. Expected a string with minimum length 1, but got an empty string instead."**, 'type': 'invalid_request_error', 'param': 'messages[2].name', 'code': 'empty_string'}} --- > 把 functions 定義補回來: ```python= completion = client.chat.completions.create( model='gpt-4', messages=[ {'role': 'system', 'content': '你是氣象專家'}, {'role': 'user', 'content':'台南的天氣如何?'}, {"role": "function", "name": "get_current_weather", "content": function_response }, ], functions=[{ "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA", }, }, "required": ["location"], }, }], function_call="auto", ) completion ``` > ChatCompletion(id='chatcmpl-9MWZGGlXyZ8yUzRQUFQI12F4pIG4i', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(++**content='目前台南的天氣狀況是多雲,氣溫約為31.95攝氏度,感覺舒適度約為36.37攝氏度。最低氣溫為31.6攝氏度,最高氣溫為32.88攝氏度。氣壓為1009百帕斯卡,濕度為58%。能見度為10000公尺,風速為每秒5.14公尺,風向為280度。雲量為40%。'**++, role='assistant', ==++**function_call=None**++==, tool_calls=None))], created=1715155434, model='gpt-4-0613', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=169, prompt_tokens=319, total_tokens=488)) - ### 您好! ``` messages=[ {'role': 'system', 'content': '你是氣象專家'}, {'role': 'user', 'content':'您好!'}, ], ``` > ChatCompletion(id='chatcmpl-9LqEXZjaUbthNCIbjo7G6YfSLJFQ7', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(++**content='您好!請問有什麼可以幫助您的?'**++, role='assistant', ++**function_call=None**++, tool_calls=None))], created=1714992701, model='gpt-4-0613', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=22, prompt_tokens=75, total_tokens=97)) - ### 我想要去北海道小樽旅遊~ > location=北海道小樽 > intent=與旅遊目的地的天氣有關 ``` messages=[ {'role': 'system', 'content': '你是氣象專家'}, {'role': 'user', 'content':'我想要去北海道小樽旅遊~'}, ], ``` > ChatCompletion(id='chatcmpl-9LqE92OMiFsuk6oUF7uR4uMzFiQDW', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(++**content='了解,讓我幫您查詢一下北海道小樽的當前天氣狀況。'**++, role='assistant', ++**function_call=None**++, tool_calls=None))], created=1714992677, model='gpt-4-0613', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=35, prompt_tokens=89, total_tokens=124)) - ### 為什麼會有很多人想去東京迪士尼?到底有什麼有趣的? > location=北海道小樽 > intent=與天氣無關 ``` messages=[ {'role': 'system', 'content': '你是氣象專家'}, {'role': 'user', 'content':'為什麼會有很多人想去東京迪士尼?到底有什麼有趣的?'}, ], ``` > ChatCompletion(id='chatcmpl-9LqFPSYzxNHn5G8akOPbrFok67Yeo', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(++**content='東京迪士尼樂園是許多人心中一個夢幻的遊樂聖地,以下列出了一些讓人嚮往的原因:\n\n1. 豐富的主題區域:東京迪士尼樂園有七大主題區,每個區域都有獨特的主題,例如冒險世界、西部樂園、未來世界等等,各具特色。\n\n2. 獨特的遊樂設施:除了著名的「小小世界」和「海盜船」等經典遊樂設施之外,東京迪士尼也有許多獨特的設施,如小飛俠空中飛行和阿拉丁的魔法飛毯等。\n\n3. 多樣化的節目與表演:東京迪士尼每日都有各種不同的戲劇表演、節慶活動和夜間煙火表演,保證遊客一整天豐富的娛樂體驗。\n\n4. 迪士尼魔法:迪士尼的角色與故事是許多人童年的回憶,走進迪士尼樂園就像走進了童話世界。與迪士尼角色的見面會、專屬的商品店等也是吸引人的一部分。\n\n5. 細膩的服務與環境:東京迪士尼以它完善的服務與乾淨的環境而著名,讓遊客在遊玩的同時也能享受到舒適的環境。\n\n6. 傳統與現代的交融:東京迪士尼不僅擁有迪士尼的經典風貌,還將日本的文化和風情融入其中,形成一種獨特的風格。\n\n總而言之,東京迪士尼把夢幻、冒險、驚喜、愉快與讚歎完美糅合在一起,這讓這座樂園成為全球人們心中至高無上的夢之地。'**++, role='assistant', ++**function_call=None**++, tool_calls=None))], created=1714992755, model='gpt-4-0613', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=710, prompt_tokens=114, total_tokens=824)) <br> <hr> <br> ## Google - [Function Calling API](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/function-calling#curl_1) ```curl= curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ https://${REGION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${REGION}/publishers/google/models/${MODEL_ID}:generateContent \ -d '{ "contents": [{ "role": "user", "parts": [{ "text": "What is the weather in Boston?" }] }], "tools": [{ "function_declarations": [ { "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616" } }, "required": [ "location" ] } } ] }] }' ``` <br> <hr> <br> ## vLLM ### 相關議題 - [OpenAI Tools / function calling #2488](https://github.com/vllm-project/vllm/pull/2488) - [OpenAI Tools / function calling v2 #3237](https://github.com/vllm-project/vllm/pull/3237) - [Support eos_token_id from generation_config.json #4182](https://github.com/vllm-project/vllm/pull/4182)