Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
APIChatGPT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SIGNORELLI Lucas
APIChatGPT
Commits
53123413
Commit
53123413
authored
2 years ago
by
Yghore
Browse files
Options
Downloads
Patches
Plain Diff
Refractor
parent
96428e77
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Faker.php
+1
-4
1 addition, 4 deletions
Faker.php
OpenAIGenerator.php
+24
-51
24 additions, 51 deletions
OpenAIGenerator.php
index.php
+14
-1
14 additions, 1 deletion
index.php
with
39 additions
and
56 deletions
Faker.php
+
1
−
4
View file @
53123413
...
...
@@ -84,10 +84,7 @@ class Faker
public
int
$number
;
public
function
__construct
()
{
$this
->
number
=
rand
(
0
,
sizeof
(
$this
->
code
)
-
1
);
}
public
function
__construct
(){}
...
...
This diff is collapsed.
Click to expand it.
OpenAIGenerator.php
+
24
−
51
View file @
53123413
<?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'
];
}
...
...
This diff is collapsed.
Click to expand it.
index.php
+
14
−
1
View file @
53123413
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment