Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ability to hide costs from Nova #73

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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