網(wǎng)站服務合同范本做設計什么網(wǎng)站可以兼職
鶴壁市浩天電氣有限公司
2026/01/24 10:37:03
網(wǎng)站服務合同范本,做設計什么網(wǎng)站可以兼職,wordpress雙站 中英文,什么網(wǎng)站可以做翻譯兼職文章目錄Function Calling在大模型中的作用Function Calling在大模型中的作用
擴展模型能力 大模型本身無法直接操作外部系統(tǒng)#xff08;如數(shù)據(jù)庫、計算工具#xff09;#xff0c;但通過調用預設函數(shù)#xff0c;可以完成#xff1a; 實時數(shù)據(jù)獲取#xff08;天氣、股價…文章目錄Function Calling在大模型中的作用Function Calling在大模型中的作用擴展模型能力大模型本身無法直接操作外部系統(tǒng)如數(shù)據(jù)庫、計算工具但通過調用預設函數(shù)可以完成實時數(shù)據(jù)獲取天氣、股價、新聞復雜計算數(shù)學運算、代碼執(zhí)行操作外部系統(tǒng)發(fā)送郵件、控制智能設備結構化輸出模型可將用戶自然語言請求轉化為結構化參數(shù)傳遞給函數(shù)。例如用戶說“明天北京天氣如何” → 模型調用 get_weather(location“北京”, date“2025-05-06”)動態(tài)決策流程模型可根據(jù)上下文決定是否/何時調用函數(shù)甚至鏈式調用多個函數(shù)如先查天氣再推薦穿搭。Function Call是大模型與真實世界交互的“橋梁”從語言理解 具體行動Function Calling與MCP的區(qū)別Function Calling的優(yōu)勢開發(fā)快捷無需配置 MCP Server直接通過模型 API 調用預定義函數(shù)。低延遲單次請求-響應無需協(xié)議層開銷。MCP 可能成為主流但 Function Calling 作為底層能力仍將存在importrequestsfromhttpimportHTTPStatusimportdashscope# 設置 DashScope API Keydashscope.api_keysk-**********# 高德天氣 API 的 天氣工具定義JSON 格式weather_tool{type:function,function:{name:get_current_weather,description:Get the current weather in a given location,parameters:{type:object,properties:{location:{type:string,description:The city name, e.g. 北京,},adcode:{type:string,description:The city code, e.g. 110000 (北京),}},required:[location],},},}defget_weather_from_gaode(location:str,adcode:strNone):調用高德地圖API查詢天氣gaode_api_key你的API KEY# 替換成你的高德API Keybase_urlhttps://restapi.amap.com/v3/weather/weatherInfoparams{key:gaode_api_key,city:adcodeifadcodeelselocation,extensions:base,# 可改為 all 獲取預報}responserequests.get(base_url,paramsparams)ifresponse.status_code200:returnresponse.json()else:return{error:fFailed to fetch weather:{response.status_code}}defrun_weather_query():使用 Qwen3 查詢天氣messages[{role:system,content:你是一個智能助手可以查詢天氣信息。},{role:user,content:北京現(xiàn)在天氣怎么樣}]responsedashscope.Generation.call(modelqwen-turbo,# 可使用 Qwen3 最新版本messagesmessages,tools[weather_tool],# 傳入工具定義tool_choiceauto,# 讓模型決定是否調用工具)ifresponse.status_codeHTTPStatus.OK:# 檢查是否需要調用工具iftool_callsinresponse.output.choices[0].message:tool_callresponse.output.choices[0].message.tool_calls[0]iftool_call[function][name]get_current_weather:# 解析參數(shù)并調用高德APIimportjson argsjson.loads(tool_call[function][arguments])locationargs.get(location,北京)adcodeargs.get(adcode,None)weather_dataget_weather_from_gaode(location,adcode)print(f查詢結果{weather_data})else:print(response.output.choices[0].message.content)else:print(f請求失敗:{response.code}-{response.message})if__name____main__:run_weather_query()