discourse-ai/assets/javascripts/discourse/admin/models/ai-llm.js
Keegan George d26c7ac48d
FEATURE: Add spending metrics to AI usage (#1268)
This update adds metrics for estimated spending in AI usage. To make use of it, admins must add cost details to the LLM config page (input, output, and cached input costs per 1M tokens). After doing so, the metrics will appear in the AI usage dashboard as the AI plugin is used.
2025-04-17 15:09:48 -07:00

37 lines
849 B
JavaScript

import { ajax } from "discourse/lib/ajax";
import RestModel from "discourse/models/rest";
export default class AiLlm extends RestModel {
createProperties() {
return this.getProperties(
"id",
"display_name",
"name",
"provider",
"tokenizer",
"max_prompt_tokens",
"max_output_tokens",
"url",
"api_key",
"enabled_chat_bot",
"provider_params",
"vision_enabled",
"input_cost",
"cached_input_cost",
"output_cost"
);
}
updateProperties() {
const attrs = this.createProperties();
attrs.id = this.id;
attrs.llm_quotas = this.llm_quotas;
return attrs;
}
async testConfig(llmConfig) {
return await ajax("/admin/plugins/discourse-ai/ai-llms/test.json", {
data: { ai_llm: llmConfig ?? this.createProperties() },
});
}
}