
第一章 大模型配置fromopenaiimportOpenAI clientOpenAI(api_key**-***************************************,base_urlhttps://api.moonshot.cn/v1)responseclient.responses.create(modelkimi-k2.6,instructions你是西安**天气查询助手...,input你是谁,# 问题tool_choiceauto,toolsweather_tool,max_tool_calls5)print(response.output_text)第二章 大模型函数调用机制importjsonfromopenaiimportOpenAIfromtools.weather_queryimportget_weather# 函数说明书tools[{type:function,name:get_weather,description:查询指定地点的当前天气。支持国家、省、市、区、县和地点名称。,parameters:{type:object,properties:{location:{type:string,description:要查询的地点例如北京市、深圳市南山区、四川省成都市郫都区、Tokyo}},required:[location],additionalProperties:False},strict:True}]FUNCTIONS{get_weather:get_weather}clientOpenAI(api_key**-*********************************,base_urlhttps://api.moonshot.cn/v1)responseclient.responses.create(modelkimi-k2.6,instructions你是西安**贾维斯...,input你是谁,tool_choiceauto,toolstools,max_tool_calls5)foriteminresponse.output:ifitem.type!function_call:continueargumentsjson.loads(item.arguments)functionFUNCTIONS[item.name]resultfunction(**arguments)print(json.dumps(result,ensure_asciiFalse))