Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 9 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ import DiscourseRoute from "discourse/routes/discourse";

export default class AdminPluginsShowDiscourseAiLlmsEdit extends DiscourseRoute {
async model(params) {
const allLlms = this.modelFor("adminPlugins.show.discourse-ai-llms");
const id = parseInt(params.id, 10);

if (id < 0) {
// You shouldn't be able to access the edit page
// if the model is seeded
return this.router.transitionTo(
"adminPlugins.show.discourse-ai-llms.index"
);
}

const allLlms = this.modelFor("adminPlugins.show.discourse-ai-llms");
const record = allLlms.findBy("id", id);
record.provider_params = record.provider_params || {};
return record;
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/discourse_ai/admin/ai_llms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ def ai_llm_params(updating: nil)
:api_key,
:enabled_chat_bot,
:vision_enabled,
:input_cost,
:cached_input_cost,
:output_cost,
)

provider = updating ? updating.provider : permitted[:provider]
Expand Down
10 changes: 10 additions & 0 deletions app/models/llm_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ class LlmModel < ActiveRecord::Base
validates :url, presence: true, unless: -> { provider == BEDROCK_PROVIDER_NAME }
validates_presence_of :name, :api_key
validates :max_prompt_tokens, numericality: { greater_than: 0 }
validates :input_cost,
:cached_input_cost,
:output_cost,
numericality: {
greater_than_or_equal_to: 0,
},
allow_nil: true
validate :required_provider_params
scope :in_use,
-> do
Expand Down Expand Up @@ -183,4 +190,7 @@ def required_provider_params
# enabled_chat_bot :boolean default(FALSE), not null
# provider_params :jsonb
# vision_enabled :boolean default(FALSE), not null
# input_cost :float
# cached_input_cost :float
# output_cost :float
#
10 changes: 10 additions & 0 deletions app/serializers/ai_usage_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def features
total_cached_tokens
total_request_tokens
total_response_tokens
input_spending
output_spending
cached_input_spending
],
)
end
Expand All @@ -35,6 +38,9 @@ def models
total_cached_tokens
total_request_tokens
total_response_tokens
input_spending
output_spending
cached_input_spending
],
)
end
Expand All @@ -49,6 +55,9 @@ def users
total_cached_tokens: user.total_cached_tokens,
total_request_tokens: user.total_request_tokens,
total_response_tokens: user.total_response_tokens,
input_spending: user.input_spending,
output_spending: user.output_spending,
cached_input_spending: user.cached_input_spending,
}
end
end
Expand All @@ -60,6 +69,7 @@ def summary
total_request_tokens: object.total_request_tokens,
total_response_tokens: object.total_response_tokens,
total_requests: object.total_requests,
total_spending: object.total_spending,
date_range: {
start: object.start_date,
end: object.end_date,
Expand Down
3 changes: 3 additions & 0 deletions app/serializers/llm_model_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class LlmModelSerializer < ApplicationSerializer
:enabled_chat_bot,
:provider_params,
:vision_enabled,
:input_cost,
:output_cost,
:cached_input_cost,
:used_by

has_one :user, serializer: BasicUserSerializer, embed: :object
Expand Down
5 changes: 4 additions & 1 deletion assets/javascripts/discourse/admin/models/ai-llm.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export default class AiLlm extends RestModel {
"api_key",
"enabled_chat_bot",
"provider_params",
"vision_enabled"
"vision_enabled",
"input_cost",
"cached_input_cost",
"output_cost"
);
}

Expand Down
Loading