2 releases
new 0.1.1 | Jan 2, 2025 |
---|---|
0.1.0 | Dec 25, 2024 |
#799 in Web programming
161 downloads per month
28KB
868 lines
Hampter
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)
TODO
Note that there will neither be an implementation of block or report functionalities for users :p
- auth
- create an authorized client
- refresh authorization token
- login (Cloudflare... so maybe not coming)
- credentials
- discord
- sign up (same here)
- chat
- create
- get
- list (character-chats)
- delete
- message
- send
- generate (missing a few dynamic parameters)
- edit
- delete
- rate
- profile
- mine
- update
- blocked-content
- get (default to mine)
- mine
- personas
- create
- get
- edit
- delete
- character
- query (searching)
- create
- upload image
- get
- delete
- edit
- tags
- get tag list
- get custom tag suggestions
- set following tags
- reviews
- favourites
- add crate to cargo
Examples
Create an authorized client
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
)?;
Refresh the auth token
client.refresh_auth_token()?; // client has to be mutable
Generate a response
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
}
}
Dependencies
~9–22MB
~320K SLoC