From 30dae5c12b81a6f92be138966d8930fa15612cb0 Mon Sep 17 00:00:00 2001 From: sigoden Date: Fri, 17 Jan 2025 20:06:28 +0800 Subject: feat: support macro (#1087) --- src/client/model.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src/client/model.rs') diff --git a/src/client/model.rs b/src/client/model.rs index 47f6598..60320cb 100644 --- a/src/client/model.rs +++ b/src/client/model.rs @@ -5,7 +5,7 @@ use super::{ }; use crate::config::Config; -use crate::utils::{estimate_token_length, format_option_value}; +use crate::utils::estimate_token_length; use anyhow::{bail, Result}; use serde::{Deserialize, Serialize}; @@ -133,10 +133,10 @@ impl Model { supports_function_calling, .. } = &self.data; - let max_input_tokens = format_option_value(max_input_tokens); - let max_output_tokens = format_option_value(max_output_tokens); - let input_price = format_option_value(input_price); - let output_price = format_option_value(output_price); + let max_input_tokens = stringify_option_value(max_input_tokens); + let max_output_tokens = stringify_option_value(max_output_tokens); + let input_price = stringify_option_value(input_price); + let output_price = stringify_option_value(output_price); let mut capabilities = vec![]; if *supports_vision { capabilities.push('👁'); @@ -161,9 +161,9 @@ impl Model { max_batch_size, .. } = &self.data; - let max_tokens = format_option_value(max_tokens_per_chunk); - let max_batch = format_option_value(max_batch_size); - let price = format_option_value(input_price); + let max_tokens = stringify_option_value(max_tokens_per_chunk); + let max_batch = stringify_option_value(max_batch_size); + let price = stringify_option_value(input_price); format!("max-tokens:{max_tokens};max-batch:{max_batch};price:{price}") } ModelType::Reranker => String::new(), @@ -366,3 +366,13 @@ impl ModelType { } } } + +fn stringify_option_value(value: &Option) -> String +where + T: std::fmt::Display, +{ + match value { + Some(value) => value.to_string(), + None => "-".to_string(), + } +} -- cgit v1.2.3