diff --git a/OpenAIGenerator.php b/OpenAIGenerator.php index 3f3105a9fc636b08ccc8abc6c460021b1e0c437f..fcc1a43690da10fbd41e1e1233000e1c92c79be5 100644 --- a/OpenAIGenerator.php +++ b/OpenAIGenerator.php @@ -4,10 +4,13 @@ class OPenAIGenerator private string $question; private string $code; private string $test; + private string $usefaker; + private $faker; - public function __construct(string $question, bool $generateCode = true) + public function __construct(string $question, bool $generateCode = true, bool $useFaker = false) { + $this->usefaker = $useFaker; $this->question = $question; if($generateCode) { @@ -16,28 +19,53 @@ class OPenAIGenerator $this->test = $this->genTest(); } + public function setFaker($faker) // SPECIFY CLASS OF FAKER FOR RETURN TYPE + { + // TO DOO SET FAKER CLASSE + $this->faker = $faker; + } public function genCode(): string { - $client = OpenAI::client('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'); - $result = $client->completions()->create([ - 'model' => 'text-davinci-003', - 'prompt' => "Create code for". $this->question . " in the java development language", - 'max_tokens' => 10, - ]); - - return $result['choices'][0]['text']; + if(!$this->usefaker) + { + $client = OpenAI::client('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'); + $result = $client->completions()->create([ + 'model' => 'text-davinci-003', + 'prompt' => "Create code for". $this->question . " in the java development language", + 'max_tokens' => 10, + ]); + return $result['choices'][0]['text']; + + } + else + { + // TO DOO + // USE CLASS FAKER FOR RETURN STRING + return ""; + } + } public function genTest(): string { - $client = OpenAI::client('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'); - $result = $client->completions()->create([ - 'model' => 'text-davinci-003', - 'prompt' => "Create test for this code :" . $this->code . ", without import", - ]); - - return $result['choices'][0]['text']; + if(!$this->usefaker) + { + $client = OpenAI::client('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'); + $result = $client->completions()->create([ + 'model' => 'text-davinci-003', + 'prompt' => "Create test for this code :" . $this->code . ", without import", + ]); + + return $result['choices'][0]['text']; + } + else + { + // TO DOO + // USE CLASS FAKER FOR RETURN STRING + return ""; + } + }