Skip to content

Commit

Permalink
MBS-9374: Fix user overview table for azure models
Browse files Browse the repository at this point in the history
  • Loading branch information
PhMemmel committed Sep 18, 2024
1 parent 0699a0e commit fa9fc57
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 26 deletions.
19 changes: 0 additions & 19 deletions classes/local/connector_factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,6 @@ public function get_connector_by_purpose(string $purpose): ?base_connector {
return $this->connector;
}

/**
* Returns the connector object for a given model.
*
* The function searches through all the connector classes and looks if the given model name is in the available models of the
* connector class. First match will be returned.
*
* @param string $model the model name
* @return ?base_connector the corresponding connector object
*/
public function get_connector_by_model(string $model): ?base_connector {
foreach (base_connector::get_all_connectors() as $connectorname) {
$connector = $this->get_connector_by_connectorname($connectorname);
if (in_array($model, $connector->get_models())) {
return $connector;
}
}
return null;
}

/**
* Helper function to determine if an instance already exists.
*
Expand Down
10 changes: 3 additions & 7 deletions classes/local/statistics_overview_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ public function __construct(
$this->define_headers($headers);
$this->collapsible(false);

$fields = 'modelinfo, model, COUNT(modelinfo) AS requestcount, SUM(value) AS userusage';
$fields = 'modelinfo, connector, COUNT(modelinfo) AS requestcount, SUM(value) AS userusage';
$from = '{local_ai_manager_request_log} rl JOIN {user} u ON rl.userid = u.id';
$tenantfield = get_config('local_ai_manager', 'tenantcolumn');
$tenant = \core\di::get(tenant::class);
$where = 'u.' . $tenantfield . ' = :tenant GROUP BY modelinfo, model';
$where = 'u.' . $tenantfield . ' = :tenant GROUP BY modelinfo, connector';
$params = ['tenant' => $tenant->get_sql_identifier()];
$this->set_sql($fields, $from, $where, $params);
$this->set_count_sql('SELECT COUNT(DISTINCT modelinfo) FROM {local_ai_manager_request_log} rl'
Expand All @@ -81,11 +81,7 @@ public function __construct(
* @return string the string representation of the userusage column
*/
public function col_userusage(stdClass $row): string {
$connector = \core\di::get(\local_ai_manager\local\connector_factory::class)->get_connector_by_model($row->model);
if ($connector === null) {
// This should only be in case we have disabled or removed a connector plugin. In this case we cannot provide a unit.
return $row->userusage;
}
$connector = \core\di::get(connector_factory::class)->get_connector_by_connectorname($row->connector);
// Currently there are only requests and tokens as units, so we can use intval for the moment.
return intval($row->userusage) . " " . $connector->get_unit()->to_string();
}
Expand Down

0 comments on commit fa9fc57

Please sign in to comment.