Skip to content

Meph1sto666/hampter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
	}
}

About

3rd party janitorai rust api

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages