Skip to content

Commit 4d6c10e

Browse files
Merge pull request #9 from lightbulbheaduk/lightbulbheaduk-patch-1
Update custom_bible_passage.php
2 parents be1b40d + bc57295 commit 4d6c10e

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

custom_bible_passage.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
<?php
2-
3-
$API_KEY = 'your_api_key_here';
4-
52
// Function to call chatGPT endpoint with prompt
63
// Returns response, time taken and number of tokens for request and response
74
if(!function_exists("callchatgpt")) {
85
function callchatgpt($prompt,$temp) {
96
// Set the API endpoint and parameters
10-
$url = 'https://api.openai.com/v1/completions';
7+
$url = 'https://api.openai.com/v1/chat/completions';
118
$parameters = array(
12-
'model' => 'text-davinci-003',
13-
'prompt' => $prompt,
9+
'model' => 'gpt-3.5-turbo-1106',
10+
'messages' => array(
11+
array('role' => 'user',
12+
'content' => $prompt)),
1413
'max_tokens' => 500, // each token is about 3/4 of a word and costs around $0.02 per thousand tokens
1514
'temperature' => $temp, // 0 = most deterministic, 1 is most creative
1615
'presence_penalty' => 1 // -2 = encourage repetition, 2 is avoid repetition
1716
);
1817

19-
// Set the API key in the header of the request
18+
// Set the API key
2019
$headers = array(
2120
'Content-Type: application/json',
22-
'Authorization: Bearer ' . $API_KEY
21+
'Authorization: Bearer <YOUR_API_KEY>'
2322
);
2423

2524
// Send the request to the API
@@ -39,7 +38,7 @@ function callchatgpt($prompt,$temp) {
3938
$duration = $end_time - $start_time;
4039

4140
$chatgpt_output = [
42-
"response" => json_decode($response, true)['choices'][0]['text'],
41+
"response" => json_decode($response, true)['choices'][0]['message']['content'],
4342
"time" => $duration,
4443
"request_token" => json_decode($response, true)['usage']['prompt_tokens'],
4544
"response_token" => json_decode($response, true)['usage']['completion_tokens']
@@ -65,7 +64,7 @@ function calldalle($prompt) {
6564
// Set the API key
6665
$headers = array(
6766
'Content-Type: application/json',
68-
'Authorization: Bearer ' . $API_KEY
67+
'Authorization: Bearer <YOUR_API_KEY>'
6968
);
7069

7170
// Send the request to the API
@@ -221,7 +220,7 @@ function calldalle($prompt) {
221220
$limerick_text .= "<p><em>Generated in " . $limerick_response['time'] . " seconds ";
222221
$limerick_text .= "using " . $limerick_response['request_token'] . " request tokens ";
223222
$limerick_text .= "and " . $limerick_response['response_token'] . " response tokens ";
224-
$limerick_text .= "and the text-davinci-003 model from OpenAI with a temperature of 0.5.";
223+
$limerick_text .= "and the gpt-3.5-turbo-1106 model from OpenAI with a temperature of 0.5.";
225224
$limerick_text .= "</em></p>";
226225
// TODO: Add in the monetary cost of this
227226

@@ -240,7 +239,7 @@ function calldalle($prompt) {
240239
$action_text .= "<p><em>Generated in " . $action_response['time'] . " seconds ";
241240
$action_text .= "using " . $action_response['request_token'] . " request tokens ";
242241
$action_text .= "and " . $action_response['response_token'] . " response tokens ";
243-
$action_text .= "and the text-davinci-003 model from OpenAI with a temperature of 0.7. ";
242+
$action_text .= "and the gpt-3.5-turbo-1106 model from OpenAI with a temperature of 0.7. ";
244243
$action_text .= "</em></p>";
245244
// TODO: Add in the monetary cost of this
246245

@@ -259,7 +258,7 @@ function calldalle($prompt) {
259258
$passages_text .= "<p><em>Generated in " . $passages_response['time'] . " seconds ";
260259
$passages_text .= "using " . $passages_response['request_token'] . " request tokens ";
261260
$passages_text .= "and " . $passages_response['response_token'] . " response tokens ";
262-
$passages_text .= "and the text-davinci-003 model from OpenAI with a temperature of 0.5. ";
261+
$passages_text .= "and the gpt-3.5-turbo-1106 model from OpenAI with a temperature of 0.5. ";
263262
$passages_text .= "</em></p>";
264263
// TODO: Add in the monetary cost of this
265264

0 commit comments

Comments
 (0)