php调用chatgpt的示例
时间: 2023-03-10 21:39:45 浏览: 216
ChatGPT的实际应用举例
可以使用PHP调用ChatGPT,例如使用Guzzle库,可以使用以下代码:$client = new GuzzleHttp\Client();$response = $client->post('https://api.openai.com/v1/engines/chatgpt/completions',[ 'headers' => [ 'Authorization' => 'Bearer ' . $api_key, ], 'json' => [ 'prompt' => $prompt, 'max_tokens' => $max_tokens, 'temperature' => $temperature, 'top_p' => $top_p, 'n' => $n, 'stream' => $stream, 'logprobs' => $logprobs, ], ]);$response_json = $response->getBody()->getContents();$response_data = json_decode($response_json,true);
阅读全文