From 35f4e67aa0a465f98db20af1b71ec80b8d269c03 Mon Sep 17 00:00:00 2001 From: Yghore <yhgore@gmail.com> Date: Tue, 7 Feb 2023 15:51:35 +0100 Subject: [PATCH] Test ChatGPT --- composer.json | 4 +++- index.php | 50 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 7f9f5d7..e9ed994 100644 --- a/composer.json +++ b/composer.json @@ -14,5 +14,7 @@ } ], "minimum-stability": "stable", - "require": {} + "require": { + "openai-php/client": "^0.3.0" + } } diff --git a/index.php b/index.php index c68f0bc..44d97b6 100644 --- a/index.php +++ b/index.php @@ -1,17 +1,49 @@ <?php +require('vendor/autoload.php'); -$html; -if(empty($_POST['test'])) +if(!empty($_GET['test'])) { - $html = <<<EOF - <form> - <input type="text" placeholder="Test à demander"/> - <input type="submit" value="Demander un test" /> - </form> - EOF; + + $client = OpenAI::client('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'); + $result = $client->completions()->create([ + 'model' => 'text-davinci-003', + 'prompt' => 'PHP is', + ]); + + var_dump($result); + echo $result['choices'][0]['text']; + +} +else +{ + echo <<<EOF + + <form> + <input type="text" name="test" id="test" placeholder="Test"> + <input type="submit" value="Envoyer"> + </form> + + EOF; + } -echo($html); +/** + * Response + * object(OpenAI\Responses\Completions\CreateResponse)#26 (6) { + * ["id"]=> string(34) "cmpl-6hJMVGw7Zr2wbR0LOaRGbHkSVlYg6" + * ["object"]=> string(15) "text_completion" + * ["created"]=> int(1675780551) + * ["model"]=> string(16) "text-davinci-003" + * ["choices"]=> array(1) { + * [0]=> object(OpenAI\Responses\Completions\CreateResponseChoice)#28 (4) { + * ["text"]=> string(62) " an open source language Yes, PHP is an open source, general-" + * ["index"]=> int(0) ["logprobs"]=> NULL ["finishReason"]=> string(6) "length" } } + * ["usage"]=> object(OpenAI\Responses\Completions\CreateResponseUsage)#27 (3) { + * ["promptTokens"]=> int(3) ["completionTokens"]=> int(16) + * ["totalTokens"]=> int(19) } } an open source language Yes, PHP is an open source, general- + * + * + */ ?> \ No newline at end of file -- GitLab