| Crates.io | hampter |
| lib.rs | hampter |
| version | 0.1.1 |
| created_at | 2024-12-25 19:42:03.356532+00 |
| updated_at | 2025-01-02 23:27:33.782032+00 |
| description | A 3rd party wrapper for the JanitorAI api |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1495190 |
| size | 77,512 |
This project is a wrapper for JanitorAI's API to make communication with the server possible without the browser. (Well not completely without because... Cloudflare)
Note that there will neither be an implementation of block or report functionalities for users :p
let client: &AuthorizedClient = &AuthorizedClient::new(
"user_agent",
// keep in mind that using an agent that is different
// from the one used to create the cf_clearance token will lead to the requests being blocked
"cf_clearance_token",
"bearer_auth_token",
"refresh_token", // obligatory to request a new bearer token every 30 minutes
"x_app_version", // not needed for most requests yet essential for text generation
"api_key" // only needed for refreshing the auth token
)?;
client.refresh_auth_token()?; // client has to be mutable
use std::io::{self, Write};
use futures::StreamExt;
use hampter::{
auth::AuthorizedClient,
types::{chat::{self, MessageChunk}, profile},
};
let chat: chat::Chat = chat::Chat::get(chat_id &client).await;
let profile: profile::Profile = profile::Profile::get(&client, None).await;
let mut lines = chat.generate(&client, &profile, None, None).await;
while let Some(line) = Some(lines.next()) {
let line_content = line.await;
if line_content.is_none() { break; } // check for the stream end
let json_str = &line_content.unwrap().unwrap();
let chunk = MessageChunk::from_line(json_str)?;
if chunk.is_some() {
print!("{}", chunk.unwrap().content(None));
let _ = io::stdout().flush(); // flush for live preview
}
}