Add (inspector)

Add (openai): debugging points for inspector
This commit is contained in:
2023-09-25 20:30:36 +08:00
parent 8fc46dc80c
commit 2ddc688926
4 changed files with 170 additions and 4 deletions

View File

@@ -3,6 +3,8 @@
namespace App\Exceptions; namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Illuminate\Auth\AuthenticationException;
use Throwable; use Throwable;
class Handler extends ExceptionHandler class Handler extends ExceptionHandler
@@ -20,11 +22,54 @@ class Handler extends ExceptionHandler
/** /**
* Register the exception handling callbacks for the application. * Register the exception handling callbacks for the application.
*
* @return void
*/ */
public function register(): void public function register()
{ {
$this->reportable(function (Throwable $e) { $this->reportable(function (Throwable $exception) {
// //
}); });
$this->renderable(function (NotFoundHttpException $e, $request) {
if ($request->is('api/*')) {
return response()->json([
'status' => -1,
], 404);
} else {
return redirect()->route('front.home');
}
});
} }
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Throwable $exception)
{
if ($exception instanceof NotFoundHttpException)
{
}
else if ($exception instanceof AuthenticationException)
{
}
else
{
inspector()->reportException($exception);
}
//default laravel response
return parent::render($request, $exception);
}
} }

View File

@@ -94,15 +94,21 @@ public static function suggestArticleTitles($current_title, $supporting_data, $s
public static function chatCompletion($system_prompt, $user_prompt, $model) public static function chatCompletion($system_prompt, $user_prompt, $model)
{ {
dump($system_prompt);
dump($user_prompt);
$response = Http::timeout(800)->withToken(config('platform.ai.openai.api_key')) $response = Http::timeout(800)->withToken(config('platform.ai.openai.api_key'))
->post('https://api.openai.com/v1/chat/completions', [ ->post('https://api.openai.com/v1/chat/completions', [
'model' => $model, 'model' => $model,
'max_tokens' => 2500, 'max_tokens' => 2500,
'messages' => [ 'messages' => [
['role' => 'user', 'content' => $system_prompt.' '.$user_prompt], ['role' => 'system', 'content' => $system_prompt],
['role' => 'user', 'content' => $user_prompt],
], ],
]); ]);
dump($response->body);
$json_response = json_decode($response->body()); $json_response = json_decode($response->body());
$reply = $json_response?->choices[0]?->message?->content; $reply = $json_response?->choices[0]?->message?->content;

View File

@@ -14,6 +14,7 @@
"fivefilters/readability.php": "^1.0", "fivefilters/readability.php": "^1.0",
"graham-campbell/markdown": "^15.0", "graham-campbell/markdown": "^15.0",
"guzzlehttp/guzzle": "^7.2", "guzzlehttp/guzzle": "^7.2",
"inspector-apm/inspector-laravel": "^4.7",
"intervention/image": "^2.7", "intervention/image": "^2.7",
"jovix/dataforseo-clientv3": "^1.1", "jovix/dataforseo-clientv3": "^1.1",
"kalnoy/nestedset": "^6.0", "kalnoy/nestedset": "^6.0",

116
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "b6f2e806cb687a1b5a4a3872968a2157", "content-hash": "ac19e61afee15da0e8592f2bfb9acf73",
"packages": [ "packages": [
{ {
"name": "artesaos/seotools", "name": "artesaos/seotools",
@@ -1389,6 +1389,120 @@
], ],
"time": "2023-08-27T10:19:19+00:00" "time": "2023-08-27T10:19:19+00:00"
}, },
{
"name": "inspector-apm/inspector-laravel",
"version": "4.7.32",
"source": {
"type": "git",
"url": "https://github.com/inspector-apm/inspector-laravel.git",
"reference": "82231274d8d52c21b56e9aef60c3efd3ec7da30c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/inspector-apm/inspector-laravel/zipball/82231274d8d52c21b56e9aef60c3efd3ec7da30c",
"reference": "82231274d8d52c21b56e9aef60c3efd3ec7da30c",
"shasum": ""
},
"require": {
"illuminate/console": "^5.5|^6.0|^7.0|^8.0|^9.0|^10.0",
"illuminate/contracts": "^5.5|^6.0|^7.0|^8.0|^9.0|^10.0",
"illuminate/support": "^5.5|^6.0|^7.0|^8.0|^9.0|^10.0",
"inspector-apm/inspector-php": "^3.7.18",
"php": ">=7.2"
},
"require-dev": {
"orchestra/testbench": "^6.25.1|^7.22|^8.0"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Inspector\\Laravel\\InspectorServiceProvider"
],
"aliases": {
"Inspector": "Inspector\\Laravel\\Facades\\Inspector"
}
}
},
"autoload": {
"files": [
"src/helpers.php"
],
"psr-4": {
"Inspector\\Laravel\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Valerio Barbera",
"email": "valerio@inspector.dev"
}
],
"description": "Simple Code Execution Monitoring for Laravel applications.",
"keywords": [
"inspector",
"laravel",
"monitoring",
"php"
],
"support": {
"issues": "https://github.com/inspector-apm/inspector-laravel/issues",
"source": "https://github.com/inspector-apm/inspector-laravel/tree/4.7.32"
},
"time": "2023-09-12T14:08:14+00:00"
},
{
"name": "inspector-apm/inspector-php",
"version": "3.7.18",
"source": {
"type": "git",
"url": "https://github.com/inspector-apm/inspector-php.git",
"reference": "c79ca8b6a3c83df2dcd292240ce220ebcfe6f83c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/inspector-apm/inspector-php/zipball/c79ca8b6a3c83df2dcd292240ce220ebcfe6f83c",
"reference": "c79ca8b6a3c83df2dcd292240ce220ebcfe6f83c",
"shasum": ""
},
"require": {
"php": ">=7.2"
},
"require-dev": {
"phpunit/phpunit": "^9.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Inspector\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Valerio Barbera",
"email": "valerio@inspector.dev"
}
],
"description": "Inspector for PHP applications.",
"keywords": [
"inspector",
"monitoring",
"php"
],
"support": {
"issues": "https://github.com/inspector-apm/inspector-php/issues",
"source": "https://github.com/inspector-apm/inspector-php/tree/3.7.18"
},
"time": "2022-12-19T09:35:42+00:00"
},
{ {
"name": "intervention/image", "name": "intervention/image",
"version": "2.7.2", "version": "2.7.2",