Updates on Function Calling were a major highlight at OpenAI DevDay.
In another world,原来的function call都不再正常工作了,必须全部重写。
function和function call全部由tool和tool_choice取代。2023年11月之前关于function call的代码都准备翘翘。
干嘛要整个tool出来取代function呢?原因有很多,不再赘述。作为程序员,我们真正关心的是:怎么改?
简单来说,就是整合chatgpt的能力和你个人的能力通过这个tools。怎么做呢?
第一步,定义function和parameters
import json
import openai
#step 1: Define 2 functions: self-defined function and text completions
def get_weather(location, unit="fahrenheit"):
if "beijing" in location.lower():
return json.dumps({
"location": location, "temperature": "11", "unit": "celsius"})
elif "tokyo" in location.lower():
return json.dumps({
"location": location, "temperature": "33", "unit": "celsius"})
else:
return json.dumps