Skip to content

Commit

Permalink
FIX-DEV: Moved the model for code helper to a route called code
Browse files Browse the repository at this point in the history
-- Chat route reserved for the purpose of chats
-- Linked the route for code to code helper
-- Navigation fixed- Now expands on choosing code helper
-- Code controller now controls the code route
-- Cleaned the chat controller
  • Loading branch information
onensensy committed Mar 15, 2023
1 parent c28aa80 commit f994a65
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 150 deletions.
76 changes: 0 additions & 76 deletions app/Http/Controllers/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,4 @@

class ChatController extends Controller
{
public function index()
{
return view('chat');
}

public function sendPrompt(Request $request)
{

$routeName = $request->route()->getName();
if ($request->prompt == null) {
return;
}
$option = $request->option;
$prompt = $request->prompt;

// $client = OpenAI::client(env('OPENAI_API_KEY'));
// /**
// * Optionally use
// *
// * $client = OpenAI::client(config('app.openai_api_key'));
// *
// * if you have done php artisan config:cache
// */
// $result = $client->completions()->create([
// "model" => "text-davinci-003",
// "temperature" => 0.7,
// "top_p" => 1,
// "frequency_penalty" => 0,
// "presence_penalty" => 0,
// 'max_tokens' => 600,
// 'prompt' => sprintf('Write article about: %s', $title),
// ]);

switch ($option) {
case "General":
$result = OpenAI::completions()->create([
"model" => "text-davinci-003",
"temperature" => 0.7,
"top_p" => 1,
"frequency_penalty" => 0,
"presence_penalty" => 0,
'max_tokens' => 600,
'prompt' => sprintf($prompt),
]);
$content = trim($result['choices'][0]['text']);
return view('chat', compact('prompt', 'content', 'option'));


break;
case "Laravel":
$result = OpenAI::completions()->create([
"model" => "text-davinci-003",
"temperature" => 0.7,
"top_p" => 1,
"frequency_penalty" => 0,
"presence_penalty" => 0,
'max_tokens' => 600,
'prompt' => 'As a Laravel-focused AI expert, your role is to provide accurate and insightful information related to Laravel programming. You should be able to answer questions related to Laravel\'s core concepts, such as working with controllers, models, views, routes, middleware, and more. You should also be able to provide expert tips and best practices for optimizing Laravel code and building scalable applications. Your responses should stay in character as a Laravel-focused AI expert, providing clear and concise explanations while also being friendly and approachable.
When asked who you are, please don\'t forget to mention that you were fine-tuned by Onen Sensy and that you are a Laravel Code Helper. However, you should also clarify that you are not Onen Sensy, but rather a specialized AI model trained to assist with Laravel programming.
If asked about any other programming language other than PHP-Laravel, you should inform the user that this specific model is only well-trained in PHP and Laravel-related code. You can then redirect the user\'s question back to the Laravel context, offering a related answer or suggesting a Laravel-specific solution. Let\'s dive into the world of Laravel programming together!. The Users Message Begins Here:
' . sprintf($prompt),
]);
$content = trim($result['choices'][0]['text']);
return view('chat', compact('prompt', 'content', 'option'));


break;

default:
$content = "Help Module for " . $option . " has not yet been implemented. You can contribute to the code via https://github.com/onensensy/myGPT";
return view('chat', compact('prompt', 'content'));
break;
}
}
}
85 changes: 85 additions & 0 deletions app/Http/Controllers/CodeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace App\Http\Controllers;

use OpenAI\Laravel\Facades\OpenAI;

use Illuminate\Http\Request;

class CodeController extends Controller
{
public function index()
{
return view('code');
}

public function sendPrompt(Request $request)
{
$routeName = $request->route()->getName();
if ($request->prompt == null) {
return;
}
$option = $request->option;
$prompt = $request->prompt;

// $client = OpenAI::client(env('OPENAI_API_KEY'));
// /**
// * Optionally use
// *
// * $client = OpenAI::client(config('app.openai_api_key'));
// *
// * if you have done php artisan config:cache
// */
// $result = $client->completions()->create([
// "model" => "text-davinci-003",
// "temperature" => 0.7,
// "top_p" => 1,
// "frequency_penalty" => 0,
// "presence_penalty" => 0,
// 'max_tokens' => 600,
// 'prompt' => sprintf('Write article about: %s', $title),
// ]);

switch ($option) {
case 'General':
$result = OpenAI::completions()->create([
'model' => 'text-davinci-003',
'temperature' => 0.7,
'top_p' => 1,
'frequency_penalty' => 0,
'presence_penalty' => 0,
'max_tokens' => 600,
'prompt' => sprintf($prompt),
]);
$content = trim($result['choices'][0]['text']);
return view('code', compact('prompt', 'content', 'option'));

break;
case 'Laravel':
$result = OpenAI::completions()->create([
'model' => 'text-davinci-003',
'temperature' => 0.7,
'top_p' => 1,
'frequency_penalty' => 0,
'presence_penalty' => 0,
'max_tokens' => 600,
'prompt' =>
'As a Laravel-focused AI expert, your role is to provide accurate and insightful information related to Laravel programming. You should be able to answer questions related to Laravel\'s core concepts, such as working with controllers, models, views, routes, middleware, and more. You should also be able to provide expert tips and best practices for optimizing Laravel code and building scalable applications. Your responses should stay in character as a Laravel-focused AI expert, providing clear and concise explanations while also being friendly and approachable.
When asked who you are, please don\'t forget to mention that you were fine-tuned by Onen Sensy and that you are a Laravel Code Helper. However, you should also clarify that you are not Onen Sensy, but rather a specialized AI model trained to assist with Laravel programming.
If asked about any other programming language other than PHP-Laravel, you should inform the user that this specific model is only well-trained in PHP and Laravel-related code. You can then redirect the user\'s question back to the Laravel context, offering a related answer or suggesting a Laravel-specific solution. Let\'s dive into the world of Laravel programming together!. The Users Message Begins Here:
' . sprintf($prompt),
]);
$content = trim($result['choices'][0]['text']);
return view('code', compact('prompt', 'content', 'option'));

break;

default:
$content = 'Help Module for ' . $option . ' has not yet been implemented. You can contribute to the code via https://github.com/onensensy/myGPT';
return view('code', compact('prompt', 'content'));
break;
}
}
}
6 changes: 3 additions & 3 deletions resources/menu/verticalMenu.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
{
"name": "Modules",
"icon": "menu-icon tf-icons bx bx-layout",
"slug": "layouts",
"slug": "modules",
"submenu": [
{
"url": "/chat",
"url": "modules/code",
"name": "Code Helper",
"slug": "chat"
"slug": "modules-code"
},
{
"url": "/layouts/without-navbar",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion resources/views/layouts/sections/navbar/navbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class="layout-menu-toggle navbar-nav align-items-xl-center me-3 me-xl-0{{ isset(
<div class="navbar-nav align-items-center">
{{-- Chat request form --}}
<div class="nav-item d-flex align-items-center">
<form action="/chat" method="post">
<form action="code" method="post">
@csrf
<input type="text" name="prompt" class="form-control border-0 shadow-none"
placeholder="{{ old('prompt') }}" aria-label="Search..." value="{{ old('prompt') }}">
Expand Down
144 changes: 74 additions & 70 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use App\Http\Controllers\ChatController;
use App\Http\Controllers\CodeController;
use Illuminate\Support\Facades\Route;

/*
Expand All @@ -19,73 +20,76 @@
Route::get('/index', function () {
return view('index ');
});
Route::get('/chat', function () {
$title = '';
$content = '';
return view('chat', compact('title', 'content'));
})->name('chat');
Route::post('/chat', [ChatController::class, 'sendPrompt'])->name('chat');

// Main Page Route
Route::get('/', $controller_path . '\dashboard\Analytics@index')->name('dashboard-analytics');

// layout
Route::get('/layouts/without-menu', $controller_path . '\layouts\WithoutMenu@index')->name('layouts-without-menu');
Route::get('/layouts/without-navbar', $controller_path . '\layouts\WithoutNavbar@index')->name('layouts-without-navbar');
Route::get('/layouts/fluid', $controller_path . '\layouts\Fluid@index')->name('layouts-fluid');
Route::get('/layouts/container', $controller_path . '\layouts\Container@index')->name('layouts-container');
Route::get('/layouts/blank', $controller_path . '\layouts\Blank@index')->name('layouts-blank');

// pages
Route::get('/pages/account-settings-account', $controller_path . '\pages\AccountSettingsAccount@index')->name('pages-account-settings-account');
Route::get('/pages/account-settings-notifications', $controller_path . '\pages\AccountSettingsNotifications@index')->name('pages-account-settings-notifications');
Route::get('/pages/account-settings-connections', $controller_path . '\pages\AccountSettingsConnections@index')->name('pages-account-settings-connections');
Route::get('/pages/misc-error', $controller_path . '\pages\MiscError@index')->name('pages-misc-error');
Route::get('/pages/misc-under-maintenance', $controller_path . '\pages\MiscUnderMaintenance@index')->name('pages-misc-under-maintenance');

// authentication
Route::get('/auth/login-basic', $controller_path . '\authentications\LoginBasic@index')->name('auth-login-basic');
Route::get('/auth/register-basic', $controller_path . '\authentications\RegisterBasic@index')->name('auth-register-basic');
Route::get('/auth/forgot-password-basic', $controller_path . '\authentications\ForgotPasswordBasic@index')->name('auth-reset-password-basic');

// cards
Route::get('/cards/basic', $controller_path . '\cards\CardBasic@index')->name('cards-basic');

// User Interface
Route::get('/ui/accordion', $controller_path . '\user_interface\Accordion@index')->name('ui-accordion');
Route::get('/ui/alerts', $controller_path . '\user_interface\Alerts@index')->name('ui-alerts');
Route::get('/ui/badges', $controller_path . '\user_interface\Badges@index')->name('ui-badges');
Route::get('/ui/buttons', $controller_path . '\user_interface\Buttons@index')->name('ui-buttons');
Route::get('/ui/carousel', $controller_path . '\user_interface\Carousel@index')->name('ui-carousel');
Route::get('/ui/collapse', $controller_path . '\user_interface\Collapse@index')->name('ui-collapse');
Route::get('/ui/dropdowns', $controller_path . '\user_interface\Dropdowns@index')->name('ui-dropdowns');
Route::get('/ui/footer', $controller_path . '\user_interface\Footer@index')->name('ui-footer');
Route::get('/ui/list-groups', $controller_path . '\user_interface\ListGroups@index')->name('ui-list-groups');
Route::get('/ui/modals', $controller_path . '\user_interface\Modals@index')->name('ui-modals');
Route::get('/ui/navbar', $controller_path . '\user_interface\Navbar@index')->name('ui-navbar');
Route::get('/ui/offcanvas', $controller_path . '\user_interface\Offcanvas@index')->name('ui-offcanvas');
Route::get('/ui/pagination-breadcrumbs', $controller_path . '\user_interface\PaginationBreadcrumbs@index')->name('ui-pagination-breadcrumbs');
Route::get('/ui/progress', $controller_path . '\user_interface\Progress@index')->name('ui-progress');
Route::get('/ui/spinners', $controller_path . '\user_interface\Spinners@index')->name('ui-spinners');
Route::get('/ui/tabs-pills', $controller_path . '\user_interface\TabsPills@index')->name('ui-tabs-pills');
Route::get('/ui/toasts', $controller_path . '\user_interface\Toasts@index')->name('ui-toasts');
Route::get('/ui/tooltips-popovers', $controller_path . '\user_interface\TooltipsPopovers@index')->name('ui-tooltips-popovers');
Route::get('/ui/typography', $controller_path . '\user_interface\Typography@index')->name('ui-typography');

// extended ui
Route::get('/extended/ui-perfect-scrollbar', $controller_path . '\extended_ui\PerfectScrollbar@index')->name('extended-ui-perfect-scrollbar');
Route::get('/extended/ui-text-divider', $controller_path . '\extended_ui\TextDivider@index')->name('extended-ui-text-divider');

// icons
Route::get('/icons/boxicons', $controller_path . '\icons\Boxicons@index')->name('icons-boxicons');

// form elements
Route::get('/forms/basic-inputs', $controller_path . '\form_elements\BasicInput@index')->name('forms-basic-inputs');
Route::get('/forms/input-groups', $controller_path . '\form_elements\InputGroups@index')->name('forms-input-groups');

// form layouts
Route::get('/form/layouts-vertical', $controller_path . '\form_layouts\VerticalForm@index')->name('form-layouts-vertical');
Route::get('/form/layouts-horizontal', $controller_path . '\form_layouts\HorizontalForm@index')->name('form-layouts-horizontal');

// tables
Route::get('/tables/basic', $controller_path . '\tables\Basic@index')->name('tables-basic');
Route::prefix('modules')->group(function () {
Route::get('/code', function () {
$title = '';
$content = '';
return view('code', compact('title', 'content'));
})->name('modules-code');

Route::post('/code', [CodeController::class, 'sendPrompt'])->name('modules-code');
});

// // Main Page Route
// Route::get('/', $controller_path . '\dashboard\Analytics@index')->name('dashboard-analytics');

// // layout
// Route::get('/layouts/without-menu', $controller_path . '\layouts\WithoutMenu@index')->name('layouts-without-menu');
// Route::get('/layouts/without-navbar', $controller_path . '\layouts\WithoutNavbar@index')->name('layouts-without-navbar');
// Route::get('/layouts/fluid', $controller_path . '\layouts\Fluid@index')->name('layouts-fluid');
// Route::get('/layouts/container', $controller_path . '\layouts\Container@index')->name('layouts-container');
// Route::get('/layouts/blank', $controller_path . '\layouts\Blank@index')->name('layouts-blank');

// // pages
// Route::get('/pages/account-settings-account', $controller_path . '\pages\AccountSettingsAccount@index')->name('pages-account-settings-account');
// Route::get('/pages/account-settings-notifications', $controller_path . '\pages\AccountSettingsNotifications@index')->name('pages-account-settings-notifications');
// Route::get('/pages/account-settings-connections', $controller_path . '\pages\AccountSettingsConnections@index')->name('pages-account-settings-connections');
// Route::get('/pages/misc-error', $controller_path . '\pages\MiscError@index')->name('pages-misc-error');
// Route::get('/pages/misc-under-maintenance', $controller_path . '\pages\MiscUnderMaintenance@index')->name('pages-misc-under-maintenance');

// // authentication
// Route::get('/auth/login-basic', $controller_path . '\authentications\LoginBasic@index')->name('auth-login-basic');
// Route::get('/auth/register-basic', $controller_path . '\authentications\RegisterBasic@index')->name('auth-register-basic');
// Route::get('/auth/forgot-password-basic', $controller_path . '\authentications\ForgotPasswordBasic@index')->name('auth-reset-password-basic');

// // cards
// Route::get('/cards/basic', $controller_path . '\cards\CardBasic@index')->name('cards-basic');

// // User Interface
// Route::get('/ui/accordion', $controller_path . '\user_interface\Accordion@index')->name('ui-accordion');
// Route::get('/ui/alerts', $controller_path . '\user_interface\Alerts@index')->name('ui-alerts');
// Route::get('/ui/badges', $controller_path . '\user_interface\Badges@index')->name('ui-badges');
// Route::get('/ui/buttons', $controller_path . '\user_interface\Buttons@index')->name('ui-buttons');
// Route::get('/ui/carousel', $controller_path . '\user_interface\Carousel@index')->name('ui-carousel');
// Route::get('/ui/collapse', $controller_path . '\user_interface\Collapse@index')->name('ui-collapse');
// Route::get('/ui/dropdowns', $controller_path . '\user_interface\Dropdowns@index')->name('ui-dropdowns');
// Route::get('/ui/footer', $controller_path . '\user_interface\Footer@index')->name('ui-footer');
// Route::get('/ui/list-groups', $controller_path . '\user_interface\ListGroups@index')->name('ui-list-groups');
// Route::get('/ui/modals', $controller_path . '\user_interface\Modals@index')->name('ui-modals');
// Route::get('/ui/navbar', $controller_path . '\user_interface\Navbar@index')->name('ui-navbar');
// Route::get('/ui/offcanvas', $controller_path . '\user_interface\Offcanvas@index')->name('ui-offcanvas');
// Route::get('/ui/pagination-breadcrumbs', $controller_path . '\user_interface\PaginationBreadcrumbs@index')->name('ui-pagination-breadcrumbs');
// Route::get('/ui/progress', $controller_path . '\user_interface\Progress@index')->name('ui-progress');
// Route::get('/ui/spinners', $controller_path . '\user_interface\Spinners@index')->name('ui-spinners');
// Route::get('/ui/tabs-pills', $controller_path . '\user_interface\TabsPills@index')->name('ui-tabs-pills');
// Route::get('/ui/toasts', $controller_path . '\user_interface\Toasts@index')->name('ui-toasts');
// Route::get('/ui/tooltips-popovers', $controller_path . '\user_interface\TooltipsPopovers@index')->name('ui-tooltips-popovers');
// Route::get('/ui/typography', $controller_path . '\user_interface\Typography@index')->name('ui-typography');

// // extended ui
// Route::get('/extended/ui-perfect-scrollbar', $controller_path . '\extended_ui\PerfectScrollbar@index')->name('extended-ui-perfect-scrollbar');
// Route::get('/extended/ui-text-divider', $controller_path . '\extended_ui\TextDivider@index')->name('extended-ui-text-divider');

// // icons
// Route::get('/icons/boxicons', $controller_path . '\icons\Boxicons@index')->name('icons-boxicons');

// // form elements
// Route::get('/forms/basic-inputs', $controller_path . '\form_elements\BasicInput@index')->name('forms-basic-inputs');
// Route::get('/forms/input-groups', $controller_path . '\form_elements\InputGroups@index')->name('forms-input-groups');

// // form layouts
// Route::get('/form/layouts-vertical', $controller_path . '\form_layouts\VerticalForm@index')->name('form-layouts-vertical');
// Route::get('/form/layouts-horizontal', $controller_path . '\form_layouts\HorizontalForm@index')->name('form-layouts-horizontal');

// // tables
// Route::get('/tables/basic', $controller_path . '\tables\Basic@index')->name('tables-basic');

0 comments on commit f994a65

Please sign in to comment.