Resource function

This commit is contained in:
CHIEFSOFT\ameye
2024-10-17 14:21:20 -04:00
parent 749b4da1b7
commit 1dc7402c8f
+203 -54
View File
@@ -10,23 +10,24 @@ use Orhanerday\OpenAi\OpenAi;
class WrenchResources extends BaseController class WrenchResources extends BaseController
{ {
use ResponseTrait; use ResponseTrait;
public function generatives(){
public function generatives()
{
$raw_json = file_get_contents('php://input'); $raw_json = file_get_contents('php://input');
$in = json_decode($raw_json, true); $in = json_decode($raw_json, true);
$a = rand(1,20); $a = rand(1, 20);
$b = rand(1,30); $b = rand(1, 30);
$c= $a+$b; $c = $a + $b;
$ansPos = rand(1,4); $ansPos = rand(1, 4);
$option_mix=[]; $option_mix = [];
for ($ii=1; $ii<=4; $ii++){ for ($ii = 1; $ii <= 4; $ii++) {
if ($ii== $ansPos){ if ($ii == $ansPos) {
$option_mix[]= $c; $option_mix[] = $c;
}else } else {
{ $ansRand = rand(1000, 9999);
$ansRand = rand(1000,9999); $option_mix[] = ($ansRand == $c) ? $ansRand + rand(1, 5) : $ansRand;
$option_mix[]= ($ansRand == $c)? $ansRand+rand(1,5) : $ansRand;
} }
} }
@@ -44,9 +45,11 @@ class WrenchResources extends BaseController
"next_question" => $next_question "next_question" => $next_question
]; ];
log_message('critical', "***** ***** WrenchResources::generatives Ret "); log_message('critical', "***** ***** WrenchResources::generatives Ret ");
return $this->respond( $this->summaryReturnData($in,$out), 200); return $this->respond($this->summaryReturnData($in, $out), 200);
} }
public function blogTopics(){
public function blogTopics()
{
$open_ai_key = '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'; $open_ai_key = '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';
@@ -56,7 +59,7 @@ class WrenchResources extends BaseController
// text-davinci-003 davinci-instruct-beta-v3 // text-davinci-003 davinci-instruct-beta-v3
$complete = $open_ai->completion([ $complete = $open_ai->completion([
'model' => 'gpt-3.5-turbo-instruct', 'model' => 'gpt-3.5-turbo-instruct',
'prompt' => 'Generate blog topics on: '. $prompt, 'prompt' => 'Generate blog topics on: ' . $prompt,
'temperature' => 0.9, 'temperature' => 0.9,
'max_tokens' => 150, 'max_tokens' => 150,
'frequency_penalty' => 0, 'frequency_penalty' => 0,
@@ -69,7 +72,8 @@ class WrenchResources extends BaseController
return $response; return $response;
} }
public function aigate(){ public function aigate()
{
$open_ai_key = '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'; $open_ai_key = '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';
@@ -80,7 +84,7 @@ class WrenchResources extends BaseController
$complete = $open_ai->completion([ $complete = $open_ai->completion([
'model' => 'gpt-3.5-turbo-instruct', 'model' => 'gpt-3.5-turbo-instruct',
'prompt' => 'Writing 3 marketing Facebook caption for '. $prompt, 'prompt' => 'Writing 3 marketing Facebook caption for ' . $prompt,
'temperature' => 0.9, 'temperature' => 0.9,
'max_tokens' => 150, 'max_tokens' => 150,
'frequency_penalty' => 0, 'frequency_penalty' => 0,
@@ -92,8 +96,10 @@ class WrenchResources extends BaseController
$response["other_topic"] = $this->blogTopics(); $response["other_topic"] = $this->blogTopics();
return $this->response->setJson($response); return $this->response->setJson($response);
} }
public function website(){
log_message('critical', "WrenchResources-> " ); public function website()
{
log_message('critical', "WrenchResources-> ");
$res1['tab_categories'] = $this->CategoryData(); $res1['tab_categories'] = $this->CategoryData();
$res1['ask_categories'] = $this->AskCategoryData(); $res1['ask_categories'] = $this->AskCategoryData();
$res1['upload_types'] = $this->uploadTypes(); $res1['upload_types'] = $this->uploadTypes();
@@ -104,9 +110,11 @@ class WrenchResources extends BaseController
return $this->response->setJson($res1); return $this->response->setJson($res1);
} }
private function getBlogData(){ private function getBlogData()
return ( new \App\Models\BlogDataModel() )->blogData(100); {
return (new \App\Models\BlogDataModel())->blogData(100);
} }
//************************ //************************
private function AskCategoryData(): array private function AskCategoryData(): array
{ {
@@ -172,6 +180,7 @@ class WrenchResources extends BaseController
return $arrayVar; return $arrayVar;
} }
private function CategoryData(): array private function CategoryData(): array
{ {
@@ -224,6 +233,7 @@ class WrenchResources extends BaseController
*/ */
return $arrayVar; return $arrayVar;
} }
//************************************ //************************************
public function index() public function index()
@@ -231,9 +241,10 @@ class WrenchResources extends BaseController
} }
public function familyresources(){ public function familyresources()
{
log_message('critical', "WrenchResources-> " ); log_message('critical', "WrenchResources-> ");
log_message('critical', "0001"); log_message('critical', "0001");
header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Origin: *');
@@ -251,10 +262,9 @@ class WrenchResources extends BaseController
$ip_loc = $this->getIpData(); $ip_loc = $this->getIpData();
if ($method == "OPTIONS") { if ($method == "OPTIONS") {
header("HTTP/1.1 200 OK CORS"); header("HTTP/1.1 200 OK CORS");
log_message('critical', " WrenchJobs()-> OPTIONS DIE*****" ); log_message('critical', " WrenchJobs()-> OPTIONS DIE*****");
die(); die();
} }
@@ -266,12 +276,12 @@ class WrenchResources extends BaseController
if ($pos > 5) { if ($pos > 5) {
$uri = substr($uri, 0, $pos); $uri = substr($uri, 0, $pos);
} }
log_message('critical', "API-GATE URI -> ".$uri ); log_message('critical', "API-GATE URI -> " . $uri);
$pieces = explode('/', $uri); $pieces = explode('/', $uri);
$psc = count($pieces); $psc = count($pieces);
$endpoint = $psc > 0 ? $pieces[$psc - 1] : ''; $endpoint = $psc > 0 ? $pieces[$psc - 1] : '';
log_message('critical', "Enpoint-> ".$endpoint ); log_message('critical', "Enpoint-> " . $endpoint);
$endpoints = $this->endPointList(); $endpoints = $this->endPointList();
$out = array(); $out = array();
@@ -294,11 +304,11 @@ class WrenchResources extends BaseController
// echo "EXYTACT INPUT DATA HERE"; // echo "EXYTACT INPUT DATA HERE";
$raw_json = file_get_contents('php://input'); $raw_json = file_get_contents('php://input');
$raw_array = json_decode($raw_json, true); $raw_array = json_decode($raw_json, true);
$local_out =[]; $local_out = [];
if ($_SERVER['REQUEST_METHOD'] == 'GET') { if ($_SERVER['REQUEST_METHOD'] == 'GET') {
log_message('critical', "Enpoint LOC2 HERE -> ".$endpoint ); log_message('critical', "Enpoint LOC2 HERE -> " . $endpoint);
$get_param = $_GET['reqData'] ?? null; $get_param = $_GET['reqData'] ?? null;
$raw_array = ($get_param!=null) ? json_decode($get_param, true):[]; $raw_array = ($get_param != null) ? json_decode($get_param, true) : [];
} }
$in = $raw_array; $in = $raw_array;
@@ -313,9 +323,10 @@ class WrenchResources extends BaseController
return $this->response->setJson($res1); return $this->response->setJson($res1);
} }
public function commonmedia(){ public function commonmedia()
{
log_message('critical', "WrenchResources-> " ); log_message('critical', "WrenchResources-> ");
log_message('critical', "0001"); log_message('critical', "0001");
header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Origin: *');
@@ -333,10 +344,9 @@ class WrenchResources extends BaseController
$ip_loc = $this->getIpData(); $ip_loc = $this->getIpData();
if ($method == "OPTIONS") { if ($method == "OPTIONS") {
header("HTTP/1.1 200 OK CORS"); header("HTTP/1.1 200 OK CORS");
log_message('critical', " WrenchJobs()-> OPTIONS DIE*****" ); log_message('critical', " WrenchJobs()-> OPTIONS DIE*****");
die(); die();
} }
@@ -348,12 +358,12 @@ class WrenchResources extends BaseController
if ($pos > 5) { if ($pos > 5) {
$uri = substr($uri, 0, $pos); $uri = substr($uri, 0, $pos);
} }
log_message('critical', "API-GATE URI -> ".$uri ); log_message('critical', "API-GATE URI -> " . $uri);
$pieces = explode('/', $uri); $pieces = explode('/', $uri);
$psc = count($pieces); $psc = count($pieces);
$endpoint = $psc > 0 ? $pieces[$psc - 1] : ''; $endpoint = $psc > 0 ? $pieces[$psc - 1] : '';
log_message('critical', "Enpoint-> ".$endpoint ); log_message('critical', "Enpoint-> " . $endpoint);
$endpoints = $this->endPointList(); $endpoints = $this->endPointList();
$out = array(); $out = array();
@@ -368,11 +378,11 @@ class WrenchResources extends BaseController
// echo "EXYTACT INPUT DATA HERE"; // echo "EXYTACT INPUT DATA HERE";
$raw_json = file_get_contents('php://input'); $raw_json = file_get_contents('php://input');
$raw_array = json_decode($raw_json, true); $raw_array = json_decode($raw_json, true);
$local_out =[]; $local_out = [];
if ($_SERVER['REQUEST_METHOD'] == 'GET') { if ($_SERVER['REQUEST_METHOD'] == 'GET') {
log_message('critical', "Enpoint LOC2 HERE -> ".$endpoint ); log_message('critical', "Enpoint LOC2 HERE -> " . $endpoint);
$get_param = $_GET['reqData'] ?? null; $get_param = $_GET['reqData'] ?? null;
$raw_array = ($get_param!=null) ? json_decode($get_param, true):[]; $raw_array = ($get_param != null) ? json_decode($get_param, true) : [];
} }
$in = $raw_array; $in = $raw_array;
@@ -385,34 +395,37 @@ class WrenchResources extends BaseController
return $this->response->setJson($res1); return $this->response->setJson($res1);
} }
private function getFamilyResourceCategory($in){
private function getFamilyResourceCategory($in)
{
log_message('critical', "WrenchResources Path GATE 006"); log_message('critical', "WrenchResources Path GATE 006");
try { try {
$micro_service_net1 = $this->getSiteConfigurations("system.micro_service_net1"); //"10.10.10.120"; $micro_service_net1 = $this->getSiteConfigurations("system.micro_service_net1"); //"10.10.10.120";
$local_url = "http://".$micro_service_net1.":3034/famresourcecat"; $local_url = "http://" . $micro_service_net1 . ":3034/famresourcecat";
log_message('critical', "WrenchResources Path GATE 00666 -> ".$local_url); log_message('critical', "WrenchResources Path GATE 00666 -> " . $local_url);
return $this->APIcall('GET', $local_url, $in); return $this->APIcall('GET', $local_url, $in);
} catch (Exception $e) { } catch (Exception $e) {
log_message('critical', "WrenchResources Path GATE 007 - ".$e->getMessage()); log_message('critical', "WrenchResources Path GATE 007 - " . $e->getMessage());
return []; return [];
} }
} }
private function getCommonMediaList($in){ private function getCommonMediaList($in)
{
log_message('critical', "WrenchResources Path GATE 006"); log_message('critical', "WrenchResources Path GATE 006");
try { try {
$micro_service_net1 = $this->getSiteConfigurations("system.micro_service_net1"); //"10.10.10.120"; $micro_service_net1 = $this->getSiteConfigurations("system.micro_service_net1"); //"10.10.10.120";
$local_url = "http://".$micro_service_net1.":3034/commonmedia"; $local_url = "http://" . $micro_service_net1 . ":3034/commonmedia";
log_message('critical', "WrenchResources Path GATE 00-commonmedia-> ".$local_url); log_message('critical', "WrenchResources Path GATE 00-commonmedia-> " . $local_url);
return $this->APIcall('GET', $local_url, $in); return $this->APIcall('GET', $local_url, $in);
} catch (Exception $e) { } catch (Exception $e) {
log_message('critical', "WrenchResources Path GATE 007 commonmedia - ".$e->getMessage()); log_message('critical', "WrenchResources Path GATE 007 commonmedia - " . $e->getMessage());
return []; return [];
} }
} }
private function CollectionData(){ private function CollectionData()
{
$arrayVar = [ $arrayVar = [
"data" => [ "data" => [
[ [
@@ -534,9 +547,11 @@ class WrenchResources extends BaseController
], ],
], ],
]; ];
return $arrayVar; return $arrayVar;
} }
private function ProductData(){
private function ProductData()
{
$arrayVar = [ $arrayVar = [
@@ -618,7 +633,9 @@ return $arrayVar;
return $arrayVar; return $arrayVar;
} }
private function MarketData(){
private function MarketData()
{
$arrayVar = [ $arrayVar = [
"data" => [ "data" => [
@@ -742,9 +759,141 @@ return $arrayVar;
], ],
]; ];
return $arrayVar ; return $arrayVar;
} }
public function getCountryStates(){
$raw_json = file_get_contents('php://input');
$in = json_decode($raw_json, true);
$out =[];
$in["action"] = -1; //
$out["country_state"]['US'] = $this->usStates();
$out["country_state"]['NG'] = $this->ngStates();
$out["country_state"]['CA'] = $this->caStates();
return $this->summaryReturnData($in,$out); //json_encode( $final_out );
}
private function usStates()
{
return [
'AL' => 'Alabama',
'AK' => 'Alaska',
'AZ' => 'Arizona',
'AR' => 'Arkansas',
'CA' => 'California',
'CO' => 'Colorado',
'CT' => 'Connecticut',
'DE' => 'Delaware',
'DC' => 'District Of Columbia',
'FL' => 'Florida',
'GA' => 'Georgia',
'HI' => 'Hawaii',
'ID' => 'Idaho',
'IL' => 'Illinois',
'IN' => 'Indiana',
'IA' => 'Iowa',
'KS' => 'Kansas',
'KY' => 'Kentucky',
'LA' => 'Louisiana',
'ME' => 'Maine',
'MD' => 'Maryland',
'MA' => 'Massachusetts',
'MI' => 'Michigan',
'MN' => 'Minnesota',
'MS' => 'Mississippi',
'MO' => 'Missouri',
'MT' => 'Montana',
'NE' => 'Nebraska',
'NV' => 'Nevada',
'NH' => 'New Hampshire',
'NJ' => 'New Jersey',
'NM' => 'New Mexico',
'NY' => 'New York',
'NC' => 'North Carolina',
'ND' => 'North Dakota',
'OH' => 'Ohio',
'OK' => 'Oklahoma',
'OR' => 'Oregon',
'PA' => 'Pennsylvania',
'RI' => 'Rhode Island',
'SC' => 'South Carolina',
'SD' => 'South Dakota',
'TN' => 'Tennessee',
'TX' => 'Texas',
'UT' => 'Utah',
'VT' => 'Vermont',
'VA' => 'Virginia',
'WA' => 'Washington',
'WV' => 'West Virginia',
'WI' => 'Wisconsin',
'WY' => 'Wyoming',
];
}
private function ngStates()
{
return [
'FC' => 'Abuja',
'AB' => 'Abia',
'AD' => 'Adamawa',
'AK' => 'Akwa Ibom',
'AN' => 'Anambra',
'BA' => 'Bauchi',
'BY' => 'Bayelsa',
'BE' => 'Benue',
'BO' => 'Borno',
'CR' => 'Cross River',
'DE' => 'Delta',
'EB' => 'Ebonyi',
'ED' => 'Edo',
'EK' => 'Ekiti',
'EN' => 'Enugu',
'GO' => 'Gombe',
'IM' => 'Imo',
'JI' => 'Jigawa',
'KD' => 'Kaduna',
'KN' => 'Kano',
'KT' => 'Katsina',
'KE' => 'Kebbi',
'KO' => 'Kogi',
'KW' => 'Kwara',
'LA' => 'Lagos',
'NA' => 'Nassarawa',
'NI' => 'Niger',
'OG' => 'Ogun',
'ON' => 'Ondo',
'OS' => 'Osun',
'OY' => 'Oyo',
'PL' => 'Plateau',
'RI' => 'Rivers',
'SO' => 'Sokoto',
'TA' => 'Taraba',
'YO' => 'Yobe',
'ZA' => 'Zamfara',
];
}
private function caStates()
{
return [
'AB' => 'Alberta',
'BC' => 'British Columbia',
'MB' => 'Manitoba',
'NB' => 'New Brunswick',
'NL' => 'Newfoundland and Labrador',
'NS' => 'Nova Scotia',
'ON' => 'Ontario',
'PE' => 'Prince Edward Island',
'QC' => 'Quebec',
'SK' => 'Saskatchewan',
'NT' => 'Northwest Territories',
'NU' => 'Nunavut',
'YT' => 'Yukon',
];
}
} }