mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-16 11:20:50 +00:00
Use three metrics for the three different tokens
This commit is contained in:
@ -21,9 +21,23 @@ lazy_static! {
|
|||||||
"Meilisearch number of search requests performed by the chat route itself"
|
"Meilisearch number of search requests performed by the chat route itself"
|
||||||
))
|
))
|
||||||
.expect("Can't create a metric");
|
.expect("Can't create a metric");
|
||||||
pub static ref MEILISEARCH_CHAT_TOKENS_USAGE: IntCounterVec = register_int_counter_vec!(
|
pub static ref MEILISEARCH_CHAT_PROMPT_TOKENS_USAGE: IntCounterVec = register_int_counter_vec!(
|
||||||
opts!("meilisearch_chat_tokens_usage", "Meilisearch Chat Tokens Usage"),
|
opts!("meilisearch_chat_prompt_tokens_usage", "Meilisearch Chat Prompt Tokens Usage"),
|
||||||
&["chat", "model", "type"]
|
&["workspace", "model"]
|
||||||
|
)
|
||||||
|
.expect("Can't create a metric");
|
||||||
|
pub static ref MEILISEARCH_CHAT_COMPLETION_TOKENS_USAGE: IntCounterVec =
|
||||||
|
register_int_counter_vec!(
|
||||||
|
opts!(
|
||||||
|
"meilisearch_chat_completion_tokens_usage",
|
||||||
|
"Meilisearch Chat Completion Tokens Usage"
|
||||||
|
),
|
||||||
|
&["workspace", "model"]
|
||||||
|
)
|
||||||
|
.expect("Can't create a metric");
|
||||||
|
pub static ref MEILISEARCH_CHAT_TOTAL_TOKENS_USAGE: IntCounterVec = register_int_counter_vec!(
|
||||||
|
opts!("meilisearch_chat_total_tokens_usage", "Meilisearch Chat Total Tokens Usage"),
|
||||||
|
&["workspace", "model"]
|
||||||
)
|
)
|
||||||
.expect("Can't create a metric");
|
.expect("Can't create a metric");
|
||||||
pub static ref MEILISEARCH_DB_SIZE_BYTES: IntGauge =
|
pub static ref MEILISEARCH_DB_SIZE_BYTES: IntGauge =
|
||||||
|
@ -49,7 +49,8 @@ use crate::error::MeilisearchHttpError;
|
|||||||
use crate::extractors::authentication::policies::ActionPolicy;
|
use crate::extractors::authentication::policies::ActionPolicy;
|
||||||
use crate::extractors::authentication::{extract_token_from_request, GuardedData, Policy as _};
|
use crate::extractors::authentication::{extract_token_from_request, GuardedData, Policy as _};
|
||||||
use crate::metrics::{
|
use crate::metrics::{
|
||||||
MEILISEARCH_CHAT_INTERNAL_SEARCH_REQUESTS, MEILISEARCH_CHAT_TOKENS_USAGE,
|
MEILISEARCH_CHAT_COMPLETION_TOKENS_USAGE, MEILISEARCH_CHAT_INTERNAL_SEARCH_REQUESTS,
|
||||||
|
MEILISEARCH_CHAT_PROMPT_TOKENS_USAGE, MEILISEARCH_CHAT_TOTAL_TOKENS_USAGE,
|
||||||
MEILISEARCH_DEGRADED_SEARCH_REQUESTS,
|
MEILISEARCH_DEGRADED_SEARCH_REQUESTS,
|
||||||
};
|
};
|
||||||
use crate::routes::chats::utils::SseEventSender;
|
use crate::routes::chats::utils::SseEventSender;
|
||||||
@ -563,15 +564,15 @@ async fn run_conversation<C: async_openai::config::Config>(
|
|||||||
match result {
|
match result {
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
if let Some(usage) = resp.usage.as_ref() {
|
if let Some(usage) = resp.usage.as_ref() {
|
||||||
for (r#type, value) in &[
|
MEILISEARCH_CHAT_PROMPT_TOKENS_USAGE
|
||||||
("prompt", usage.prompt_tokens),
|
.with_label_values(&[workspace_uid, &chat_completion.model])
|
||||||
("completion", usage.completion_tokens),
|
.inc_by(usage.prompt_tokens as u64);
|
||||||
("total", usage.total_tokens),
|
MEILISEARCH_CHAT_COMPLETION_TOKENS_USAGE
|
||||||
] {
|
.with_label_values(&[workspace_uid, &chat_completion.model])
|
||||||
MEILISEARCH_CHAT_TOKENS_USAGE
|
.inc_by(usage.completion_tokens as u64);
|
||||||
.with_label_values(&[workspace_uid, &chat_completion.model, r#type])
|
MEILISEARCH_CHAT_TOTAL_TOKENS_USAGE
|
||||||
.inc_by(*value as u64);
|
.with_label_values(&[workspace_uid, &chat_completion.model])
|
||||||
}
|
.inc_by(usage.total_tokens as u64);
|
||||||
}
|
}
|
||||||
let choice = match resp.choices.first() {
|
let choice = match resp.choices.first() {
|
||||||
Some(choice) => choice,
|
Some(choice) => choice,
|
||||||
|
Reference in New Issue
Block a user