From 67e0dae7c25d416bf1ffefce7d87cc2594f9819e Mon Sep 17 00:00:00 2001 From: Luquor <signorellilucas7@gmail.com> Date: Mon, 13 Feb 2023 12:27:08 +0100 Subject: [PATCH] =?UTF-8?q?Refactor=20du=20code=20pour=20une=20meilleure?= =?UTF-8?q?=20conception=20(classe=20=C3=A0=20revoir)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OpenAIClient.php | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 OpenAIClient.php diff --git a/OpenAIClient.php b/OpenAIClient.php new file mode 100644 index 0000000..20e6a91 --- /dev/null +++ b/OpenAIClient.php @@ -0,0 +1,69 @@ +<?php +class OpenAIClient +{ + private string $question; + private string $code; + private string $test; + + + public function __construct(string $question) + { + $this->question = $question; + $this->code = $this->genCode(); + $this->test = $this->genTest(); + } + + + public function genCode(): string + { + $client = OpenAI::client('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'); + $result = $client->completions()->create([ + 'model' => 'text-davinci-003', + 'prompt' => $this->question, + ]); + + return $result['choices'][0]['text']; + } + + public function genTest(): string + { + $client = OpenAI::client('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'); + $result = $client->completions()->create([ + 'model' => 'text-davinci-003', + 'prompt' => $this->question, + ]); + + return $result['choices'][0]['text']; + } + + + public function getQuestion(): string + { + return $this->question; + } + + public function setQuestion(string $question): void + { + $this->question = $question; + } + + public function getCode(): string + { + return $this->code; + } + + public function setCode(string $code): void + { + $this->code = $code; + } + + public function getTest(): string + { + return $this->test; + } + + public function setTest(string $test): void + { + $this->test = $test; + } +} \ No newline at end of file -- GitLab