|
#[async_trait] |
|
pub trait TextGeneration: Sync + Send { |
|
async fn generate(&self, prompt: &str, options: TextGenerationOptions) -> String; |
|
async fn generate_stream( |
|
&self, |
|
prompt: &str, |
|
options: TextGenerationOptions, |
|
) -> BoxStream<String>; |
|
} |
Current TextGeneration trait is simple, but it doesn't tell the statics we need for monitoring and optimizing the inference server.
for example, input_token_length and output_token_length stats are really important to measure the inference server throughput.
My initial idea would be something like this:
pub struct TextGenerationStat {
pub prompt_tokens_length: u32,
pub output_tokens_length: Option<u32>, // not available in stream responses
pub time: Option<u32>, // not available in stream responses
}
pub struct TextGenerationResponse {
pub text: String,
pub stat: Option<TextGenerationStat>,
}
pub struct TextGenerationStreamResponse {
pub stream: BoxStream<String>,
pub stat: Option<TextGenerationStat>,
}
pub trait TextGeneration: Sync + Send {
async fn generate(
&self,
prompt: &str,
options: TextGenerationOptions,
) -> TextGenerationResponse;
async fn generate_stream(
&self,
prompt: &str,
options: TextGenerationOptions,
) -> TextGenerationStreamResponse;
}
tabby/crates/tabby-inference/src/lib.rs
Lines 23 to 31 in 99d49a9
Current TextGeneration trait is simple, but it doesn't tell the statics we need for monitoring and optimizing the inference server.
for example,
input_token_lengthandoutput_token_lengthstats are really important to measure the inference server throughput.My initial idea would be something like this: