最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

OpenAI 函數(shù)調(diào)用 功能入門

2023-06-21 11:39 作者:AI小火箭  | 我要投稿

作者:AI小火箭的HB

我是AI小火箭HB,我探索和寫作人工智能和語言交叉點的所有事物,范圍從LLM,聊天機(jī)器人,語音機(jī)器人,開發(fā)框架,以數(shù)據(jù)為中心的潛在空間等。


范例


圖片


初步體驗

OpenAI新增了“函數(shù)調(diào)用”功能,這是什么呢?

我們先調(diào)用API來體驗下。

下面是發(fā)送到模型的 JSON 文檔。此調(diào)用的目的是生成一個 JSON 文件,該文件可用于發(fā)送到發(fā)送電子郵件的 API。

您可以看到函數(shù)名稱為 send_email,并定義了三個參數(shù), to_address , subjectbody ,即電子郵件正文。

用戶請求為:Send Cobus from humanfirst ai an email asking for the monthly report?






?"model": "gpt-3.5-turbo-0613",
?"messages": [
? ?{"role": "user", "content": "Send Cobus from humanfirst ai an email asking for the monthly report?"}
?],
?"functions": [
? ?{
? ? ?"name": "send_email",
? ? ?"description": "Please send an email.",
? ? ?"parameters": {
? ? ? ?"type": "object",
? ? ? ?"properties": {
? ? ? ? ?"to_address": {
? ? ? ? ? ?"type": "string",
? ? ? ? ? ?"description": "To address for email"
? ? ? ? ?}, ? ? ? ? ?
? ? ? ? ?"subject": {
? ? ? ? ? ?"type": "string",
? ? ? ? ? ?"description": "subject of the email"
? ? ? ? ?},
? ? ? ? ?"body": {
? ? ? ? ? ?"type": "string",
? ? ? ? ? ?"description": "Body of the email"
? ? ? ? ?}
? ? ? ?}
? ? ?}
? ?}
?]
}'

下面是返回的 JSON


{
? ?"id": "chatcmpl-7TQuwzJpQAY470saQM2RPfxwF6DDE",
? ?"object": "chat.completion",
? ?"created": 1687249338,
? ?"model": "gpt-3.5-turbo-0613",
? ?"choices": [
? ? ? ?{
? ? ? ? ? ?"index": 0,
? ? ? ? ? ?"message": {
? ? ? ? ? ? ? ?"role": "assistant",
? ? ? ? ? ? ? ?"content": null,
? ? ? ? ? ? ? ?"function_call": {
? ? ? ? ? ? ? ? ? ?"name": "send_email",
? ? ? ? ? ? ? ? ? ?"arguments": "{\n ?\"to_address\": \"cobus@humanfirst.ai\",\n ?\"subject\": \"Request for Monthly Report\",\n ?\"body\": \"Hi Cobus,\\n\\nI hope you're doing well. Could you please share the monthly report with me? It would be great to have it before the end of the week.\\n\\nThanks,\\n[Your Name]\"\n}"
? ? ? ? ? ? ? ?}
? ? ? ? ? ?},
? ? ? ? ? ?"finish_reason": "function_call"
? ? ? ?}
? ?],
? ?"usage": {
? ? ? ?"prompt_tokens": 86,
? ? ? ?"completion_tokens": 82,
? ? ? ?"total_tokens": 168
? ?}
}

GPT模型會返回需要調(diào)用的函數(shù)名 send_email和對應(yīng)的參數(shù)(放在arguments字段)。


{
?"to_address": "cobus@humanfirst.ai",
?"subject": "Request for Monthly Report",
?"body": "Hi Cobus,\n\nI hope you're doing well. Could you please share the monthly report with me? It would be great to have it before the end of the week.\n\nThanks,\n[Your Name]"
}

這就非常有用,第三方的應(yīng)用可以提供多個函數(shù)/服務(wù)(類似插件),GPT模型可以根據(jù)用戶的指令自動選擇不同的函數(shù)/服務(wù)。


現(xiàn)在再來看示例,就比較清晰了。

圖片


用途

根據(jù)官網(wǎng)文檔,函數(shù)調(diào)用允許您更可靠地從模型中獲取結(jié)構(gòu)化數(shù)據(jù)。例如,您可以:

  • 創(chuàng)建聊天機(jī)器人,通過調(diào)用外部 API 來回答問題(例如 ChatGPT 插件)

    • 例如,定義像 send_email(to: string, body: string)get_current_weather(location: string, unit: 'celsius' | 'fahrenheit') 這樣的函數(shù)

  • 將自然語言轉(zhuǎn)換為 API 調(diào)用

    • 例如,將“誰是我的頂級客戶?”轉(zhuǎn)換為 get_customers(min_revenue: int, created_before: string, limit: int) 并調(diào)用您的內(nèi)部 API

  • 從文本中提取結(jié)構(gòu)化數(shù)據(jù)

    • 例如,定義一個名為 extract_data(name: string, birthday: string)sql_query(query: string) 的函數(shù)


函數(shù)調(diào)用的基本步驟順序如下:

  1. 使用用戶查詢和函數(shù)參數(shù)中定義的一組函數(shù)調(diào)用模型。

  2. 模型可以選擇調(diào)用函數(shù);如果是這樣,內(nèi)容將是符合自定義架構(gòu)的字符串化 JSON 對象(注意:模型可能會生成無效的 JSON 或幻覺參數(shù))。

  3. 在代碼中將字符串解析為 JSON,并使用提供的參數(shù)調(diào)用函數(shù)(如果存在)。

  4. 通過將函數(shù)響應(yīng)追加為新消息來再次調(diào)用模型,并讓模型將結(jié)果匯總回給用戶。


AI小火箭

AI小火箭已經(jīng)支持函數(shù)調(diào)用和gpt-3.5-turbo-16k、gpt-3.5-turbo-0613、gpt-3.5-turbo-16k-0613,大家可以去體驗下。



本文使用 文章同步助手 同步


OpenAI 函數(shù)調(diào)用 功能入門的評論 (共 條)

分享到微博請遵守國家法律
景宁| 东光县| 元江| 宕昌县| 大冶市| 阳江市| 轮台县| 读书| 衢州市| 武夷山市| 盘锦市| 珠海市| 南宫市| 双流县| 博野县| 利津县| 松原市| 安义县| 宝清县| 玉龙| 广河县| 广汉市| 上虞市| 阿巴嘎旗| 章丘市| 高邑县| 馆陶县| 翼城县| 藁城市| 柳河县| 牡丹江市| 共和县| 浠水县| 隆尧县| 库伦旗| 抚宁县| 吕梁市| 太谷县| 波密县| 宝清县| 扎鲁特旗|