| Crates.io | nah_chat |
| lib.rs | nah_chat |
| version | 0.5.1 |
| created_at | 2025-07-24 04:00:10.944056+00 |
| updated_at | 2025-08-07 03:35:08.032719+00 |
| description | Lightweight LLM chat completion API. |
| homepage | https://github.com/linmx0130/nah |
| repository | https://github.com/linmx0130/nah |
| max_upload_size | |
| id | 1765486 |
| size | 65,295 |
This crate exposes an async stream API for the widely-used OpenAI chat completion API.
Supported features:
reqwest and serde_json.use nah_chat::{ChatClient, ChatMessage};
use futures_util::{pin_mut, StreamExt};
let chat_client = ChatClient::init(base_url, auth_token);
// create and pin the stream
let stream = chat_client
.chat_completion_stream(model_name, &messages, ¶ms)
.await
.unwrap();
pin_mut!(stream);
// buffer for the new message
let mut message = ChatMessage::new();
// consume the stream
while let Some(delta_result) = stream.next().await {
match delta_result {
Ok(delta) => {
message.apply_model_response_chunk(delta);
}
Err(e) => {
eprintln!("Error occurred while processing the chat completion: {}", e);
}
}
}
Copyright 2025, Mengxiao Lin.
This is a part of nah project. nah means "Not A
Human". Source code is available under MPL-2.0.