php调用gpt-3.5-turbo-0613的functions示例代码
代码语言:php
所属分类:其他
代码描述:php调用gpt-3.5-turbo-0613的functions示例代码,通过这个功能,用户可以将prompt和函数的参数及返回结果等信息发送给ChatGPT,让它帮你理解函数的参数并直接调用函数。这个功能非常实用,将改变应用的使用方式。以前,执行用户的指令需要理解用户的意图,容易出错。现在,通过ChatGPT生成函数的参数,执行指令变得更加容易
代码标签: php 调用 chatgpt functions 示例 代码 openai
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.openai.com/v1/chat/completions"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $_postobj = array("model" => "gpt-3.5-turbo-0613", "messages" => array( ["role" => "user", "content" => "东京的天气如何?"], // ["role" => "assistant", "content" => null, "function_call" => ["name" => "get_current_weather", "arguments" => "{ \"location\": \"Tokyo\" }"]], //执行function后再次请求时需要次参数,第一次不需要 [ "role" => "function", "name" => "get_current_weather", "content" => "{\"temperature\": \"52\", \"unit\": \"celsius\", \"description\": \"Sunny\"}" ] ), "functions" => array( array( "name" => "get_current_weather", "description" => "", "parameters" => array( "type" => "object", "properties" => array( "location" => array( "type" => "string", "description" => "The city and state, e.g. San Francisco, CA" ), .........完整代码请登录后点击上方下载按钮下载查看
网友评论0