久久精品水蜜桃av综合天堂,久久精品丝袜高跟鞋,精品国产肉丝袜久久,国产一区二区三区色噜噜,黑人video粗暴亚裔

DeepSeek Function Calling

2025-02-20 158
DeepSeek

類(lèi)型:人工智能

簡(jiǎn)介:一款基于深度學(xué)習(xí)和自然語(yǔ)言處理技術(shù)的產(chǎn)品,人氣趕超ChatGPT。

DeepSeek Function Calling功能允許模型調(diào)用外部工具,從而增強(qiáng)其能力,執(zhí)行一些超出模型本身的任務(wù)。

提示:當(dāng)前版本的 Deepseek-Chat 模型的 Function Calling 功能效果不穩(wěn)定,可能會(huì)出現(xiàn)循環(huán)調(diào)用或空回復(fù)等問(wèn)題。我們正在積極進(jìn)行修復(fù),預(yù)計(jì)下一個(gè)版本將解決這些問(wèn)題。

以下是一個(gè)示例代碼,展示如何使用 Function Calling 獲取用戶(hù)當(dāng)前位置的天氣信息。

一、Function Calling示例代碼

假設(shè)我們想獲取用戶(hù)詢(xún)問(wèn)的某個(gè)地點(diǎn)的天氣情況,以下是使用 Function Calling 的完整 Python 代碼:

from openai import OpenAI
def send_messages(messages):
response = client.chat.completions.create(
model="deepseek-chat",
messages=messages,
tools=tools
)
return response.choices[0].message
client = OpenAI(
api_key="<your api key>",
base_url="https://api.deepseek.com",
)
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather of an location, the user should supply a location first",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
}
},
"required": ["location"]
},
}
},
]
messages = [{"role": "user", "content": "How's the weather in Hangzhou?"}]
message = send_messages(messages)
print(f"User>\t {messages[0]['content']}")
tool = message.tool_calls[0]
messages.append(message)
messages.append({"role": "tool", "tool_call_id": tool.id, "content": "24℃"})
message = send_messages(messages)
print(f"Model>\t {message.content}")

二、Function Calling執(zhí)行流程

1、用戶(hù)提問(wèn)當(dāng)前天氣情況,例如:“Hangzhou 的天氣怎么樣?”

2、模型返回調(diào)用函數(shù) get_weather({location: ‘Hangzhou’}) 的請(qǐng)求。

3、用戶(hù)調(diào)用 get_weather 函數(shù),提供必要的參數(shù)(例如,返回 Hangzhou 的天氣數(shù)據(jù)),并傳回模型。

4、模型最終返回自然語(yǔ)言的響應(yīng),例如:“Hangzhou 當(dāng)前的溫度是 24°C?!?/p>

說(shuō)明:

  • 在上述代碼中,get_weather 函數(shù)是用戶(hù)提供的功能,模型本身并不執(zhí)行該函數(shù);
  • 這段代碼使用了 Function Calling 功能,通過(guò)外部工具提供的天氣信息來(lái)增強(qiáng)模型的回答能力。
  • 廣告合作

  • QQ群號(hào):4114653

溫馨提示:
1、本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享網(wǎng)絡(luò)內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。郵箱:2942802716#qq.com(#改為@)。 2、本站原創(chuàng)內(nèi)容未經(jīng)允許不得轉(zhuǎn)裁,轉(zhuǎn)載請(qǐng)注明出處“站長(zhǎng)百科”和原文地址。