Skip to content
Snippets Groups Projects
Commit 53123413 authored by Yghore's avatar Yghore
Browse files

Refractor

parent 96428e77
No related branches found
No related tags found
No related merge requests found
......@@ -84,10 +84,7 @@ class Faker
public int $number;
public function __construct()
{
$this->number = rand(0, sizeof($this->code)-1);
}
public function __construct(){}
......
<?php
require_once('Faker.php');
class OPenAIGenerator
{
private string $question;
private string $code;
private string $test;
private string $usefaker;
private $faker;
public function __construct(string $question, bool $generateCode = true, bool $useFaker = false)
public function __construct(string $question)
{
$this->usefaker = $useFaker;
$this->question = $question;
if($useFaker)
{
$fakerClasse = new Faker();
$this->setFaker($fakerClasse);
}
if($generateCode)
{
$this->code = $this->genCode();
}
$this->test = $this->genTest();
}
public function setFaker($fakerClasse) // SPECIFY CLASS OF FAKER FOR RETURN TYPE
public function generate()
{
// TO DOO SET FAKER CLASSE
$this->faker = $fakerClasse;
$this->code = $this->genCode();
$this->test = $this->genTest();
}
public function genCode(): string
{
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 $this->faker->getCode();
}
$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'];
}
public function genTest(): string
{
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 $this->faker->getTest();
}
$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'];
}
......
......@@ -3,6 +3,7 @@
require('vendor/autoload.php');
require_once('OpenAIGenerator.php');
require_once('Faker.php');
echo <<<HTMLEOF
<head>
......@@ -21,7 +22,19 @@ HTMLEOF;
if(!empty($_POST['question']))
{
$gen = new OpenAIGenerator($_POST['question'], true ,true);
$gen = new OpenAIGenerator($_POST['question'], true);
echo $faker;
$faker = (!empty($_GET['faker'])) ? $_GET['faker'] : false;
if(!$faker){
$gen->generate();
}
else {
$faker = new Faker();
$faker->regenerateCode();
$gen->setCode($faker->getCode());
$gen->setTest($faker->getTest());
}
echo $gen;
}
else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment