hampter

Crates.iohampter
lib.rshampter
version0.1.1
created_at2024-12-25 19:42:03.356532+00
updated_at2025-01-02 23:27:33.782032+00
descriptionA 3rd party wrapper for the JanitorAI api
homepage
repository
max_upload_size
id1495190
size77,512
Meph1sto666 (Meph1sto666)

documentation

README

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
      • google
      • twitter
      • 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)
  • 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
	}
}
Commit count: 0

cargo fmt