Skip to content

Commit

Permalink
show warning if only few tokens left
Browse files Browse the repository at this point in the history
  • Loading branch information
wi-wissen committed Jan 10, 2025
1 parent 239ee4d commit 0c46fd6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/Helpers/HubHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ public function hasTable($name)
return in_array($name, $this->tables);
}

public function hasTokens()
public function hasTokens($amount = 1)
{
if ($this->isHub()) {
return $this->teacher()->hasTokens();
return $this->teacher()->hasTokens($amount);
} else {
return Auth::user()->hasTokens();
return Auth::user()->hasTokens($amount);
}
}

Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct()
$this->middleware('auth');
}

public function index(Request $request, $filter = null, $param = null)
public function index($filter = null, $param = null)
{
if ($filter == 'suggested') {
return view('user.index', ['users' => User::getSuggested(), 'heading' => __('Suggested')]); //TODO: Lassen sich Punkte mit übertragen?
Expand All @@ -28,7 +28,7 @@ public function index(Request $request, $filter = null, $param = null)
}
}

public function show(User $user, Request $request)
public function show(User $user)
{
return view('user.show', ['user' => $user]);
}
Expand Down Expand Up @@ -76,7 +76,7 @@ public function update(Request $request, User $user)
return redirect('/'.$user->username);
}

public function activate(User $user, Request $request)
public function activate(User $user)
{
if (Auth::user()->allowed('dba')) {
$user->save();
Expand All @@ -90,7 +90,7 @@ public function activate(User $user, Request $request)
return redirect('/'.$user->username);
}

public function deactivate(User $user, Request $request)
public function deactivate(User $user)
{
if (Auth::user()->allowed('dba')) {
$user->save();
Expand Down
1 change: 1 addition & 0 deletions lang/de/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@
'query' => 'Die Abfrage muss <code>true</code> oder <code>false</code> ergeben. Alternativ kann auch eine Liste zurückgegeben werden, in welcher die Benutzer-ID gesucht wird. <code>$user</code> kann als Platzhalter für den angemeldeten Benutzer und <code>$photo</code> für das aktuelle Photo verwendet werden.',
],
'hubdomain' => 'Deinen eigenen Hub erreichst du unter deiner eigenen Domain. Diese könnte etwa <code>azurblau27.instahub.org</code> sein.',
'fewTokens' => 'Du hast nur noch wenig Guthaben, um die KI-Funktionen in InstaHub zu verwenden.',
'noTokens' => 'Du hast kein Guthaben mehr, um die KI-Funktionen in InstaHub zu verwenden.',
];
1 change: 1 addition & 0 deletions lang/en/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@
'query' => 'Query must return <code>true</code> or <code>false</code> or an list of User-IDs which contains or not contains actual User. Use <code>$user</code> for actual User and <code>$photo</code> for actual Photo.',
],
'hubdomain' => 'You can reach your own hub under your own domain. This could be <code>azurblau27.instahub.org</code>.',
'fewTokens' => 'You have only a few credits left to use the AI functions in InstaHub.',
'noTokens' => 'You no longer have credit to use the AI functions in InstaHub.',
];
4 changes: 4 additions & 0 deletions resources/views/hub/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<div class="alert alert-warning alert-important" role="alert">
{{ __('messages.noTokens') }}
</div>
@elseif(! RequestHub::hasTokens(config('azure.max_tokens') / 2))
<div class="alert alert-warning alert-important" role="alert">
{{ __('messages.fewTokens') }}
</div>
@endif

<h1>{{ __('Hubs') }}</h1>
Expand Down

0 comments on commit 0c46fd6

Please sign in to comment.