pub struct TranslationClient { /* private fields */ }Expand description
Client for translating text using OpenAI-compatible APIs.
Supports streaming responses for real-time output.
§Example
use tl_cli::translation::{TranslationClient, TranslationRequest};
use futures_util::StreamExt;
let client = TranslationClient::new(
"http://localhost:11434".to_string(),
None,
);
let request = TranslationRequest {
source_text: "Hello, world!".to_string(),
target_language: "ja".to_string(),
model: "gemma3:12b".to_string(),
endpoint: "http://localhost:11434".to_string(),
};
let mut stream = client.translate_stream(&request).await?;
while let Some(chunk) = stream.next().await {
print!("{}", chunk?);
}Implementations§
Source§impl TranslationClient
impl TranslationClient
Sourcepub fn new(endpoint: String, api_key: Option<String>) -> Self
pub fn new(endpoint: String, api_key: Option<String>) -> Self
Creates a new translation client.
Sourcepub async fn translate_stream(
&self,
request: &TranslationRequest,
) -> Result<Pin<Box<dyn Stream<Item = Result<String>> + Send>>>
pub async fn translate_stream( &self, request: &TranslationRequest, ) -> Result<Pin<Box<dyn Stream<Item = Result<String>> + Send>>>
Translates text and returns a stream of response chunks.
The stream yields chunks of the translated text as they arrive, enabling real-time display of the translation.
Auto Trait Implementations§
impl Freeze for TranslationClient
impl !RefUnwindSafe for TranslationClient
impl Send for TranslationClient
impl Sync for TranslationClient
impl Unpin for TranslationClient
impl !UnwindSafe for TranslationClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more