-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate-domains.php
41 lines (37 loc) · 1.37 KB
/
generate-domains.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
require_once __DIR__ . '/vendor/autoload.php';
function generateDomains(){
$env = parse_ini_file('.env');
$yourApiKey = $env['openai_api_key'];
$client = OpenAI::client($yourApiKey);
$business_description = $_POST['description'];
$domains_count_to_generate = $env['domains_count_to_generate'];
$prompt = "This is a short description of what my business is about: {$business_description}. Generate {$domains_count_to_generate} creative business names. Follow these instructions about result
Dont include any spaces in doamin name.
Append .com as tld with each domain.
Dont include any other thing in the result except domains.
Strictly output the result like 'name1,name2,name3'
";
try{
$result = $client->completions()->create([
'model' => 'text-davinci-003',
'prompt' => $prompt,
'max_tokens' => 500,
]);
$domains = $result['choices'][0]['text'];
$domains = trim($domains);
$domains = trim($domains, "'");
$domains = explode(",", $domains);
$domains = array_map(function($domain){
$domain = trim($domain);
$domain = trim($domain, ".");
//$domain = $domain.".com";
return $domain;
}, $domains);
return $domains;
}
catch(\Exception $e){
echo $e->getMessage();
}
}
?>