Skip to content

Commit

Permalink
feat: ability to hidea costs from Nova
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-raadi committed Dec 17, 2024
1 parent b4d11dc commit 99e9fad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions config/nova-openai.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
*/

'pricing' => null,
'hide_pricing' => env('OPENAI_HIDE_PRICING', false),

/*
|--------------------------------------------------------------------------
Expand Down
19 changes: 13 additions & 6 deletions src/Nova/OpenAIRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static function uriKey()
*/
public function fields(NovaRequest $request)
{
return [
$fields = [
ID::make()->sortable(),
Badge::make('Status')
->types([
Expand All @@ -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(),
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 99e9fad

Please sign in to comment.