From 99e9fadbb1651ae207808441617a46ca3ba980bf Mon Sep 17 00:00:00 2001 From: Richard Date: Tue, 17 Dec 2024 16:17:04 +0200 Subject: [PATCH] feat: ability to hidea costs from Nova --- config/nova-openai.php | 1 + src/Nova/OpenAIRequest.php | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/config/nova-openai.php b/config/nova-openai.php index 5aa7b88..e68c08c 100644 --- a/config/nova-openai.php +++ b/config/nova-openai.php @@ -47,6 +47,7 @@ */ 'pricing' => null, + 'hide_pricing' => env('OPENAI_HIDE_PRICING', false), /* |-------------------------------------------------------------------------- diff --git a/src/Nova/OpenAIRequest.php b/src/Nova/OpenAIRequest.php index a4d63c2..f434eeb 100644 --- a/src/Nova/OpenAIRequest.php +++ b/src/Nova/OpenAIRequest.php @@ -83,7 +83,7 @@ public static function uriKey() */ public function fields(NovaRequest $request) { - return [ + $fields = [ ID::make()->sortable(), Badge::make('Status') ->types([ @@ -104,7 +104,6 @@ public function fields(NovaRequest $request) OpenAIRequestMethod::FILES->value => 'bg-gray-600 text-gray-200', ])->sortable(), Text::make('Name', 'name')->sortable(), - Number::make('Cost', 'cost')->sortable()->displayUsing(fn($value) => $value === null ? null : '$' . number_format($value, 4)), Text::make('Request time', 'time_sec')->sortable()->displayUsing(fn() => $this->time_sec !== null ? "{$this->time_sec} sec" : null), Text::make('Model requested', 'model_requested')->sortable(), Text::make('Model used', 'model_used')->sortable(), @@ -123,8 +122,13 @@ public function fields(NovaRequest $request) }), Code::make('Raw Input', 'input')->json(), Code::make('Raw Output', 'output')->json(), - ]; + + if (!config('nova-openai.hide_pricing')) { + $fields[] = Number::make('Cost', 'cost')->sortable()->displayUsing(fn($value) => $value === null ? null : '$' . number_format($value, 4)); + } + + return $fields; } /** @@ -135,9 +139,12 @@ public function fields(NovaRequest $request) */ public function cards(NovaRequest $request) { - return [ - new CostMetrics, - ]; + $cards = []; + if (!config('nova-openai.hide_pricing')) { + $cards[] = new CostMetrics; + } + + return $cards; } /**