Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.
Drevz edited this page Feb 23, 2024 · 2 revisions

Introduction

Welcome to the Character.AI library wiki!

This library supports high level interacting with character.ai's api. For anyone who doesn't know, character.ai is an online neural language model chatbot service.

And it is in development; it currently supports some functions:

  • Modify account information (avatar, bio, name,...)
  • Interact with posts (create, upload, vote, comment, etc.)
  • Editing characters (name, title, description, and many more)
  • Chat with characters

This is a simple wiki to guide you through the basic usage of this library; you will find some examples here.

Warning

You must have your character.ai token first. See here for how to get it.

Basic

To use the library, first import it and initialize a client.

from CharAI import *

MY_TOKEN = "xxxx"

client = Client(MY_TOKEN)

You've created a new client! Congratulations!

The new client sticks with a user object, you can find basic information about your account there. Now I will show you some basic usage of this library.

  1. Get your account object
user = client.User.self()
# you can also get another user's (info) object from there username
other_user = client.User.get_user_info("myfriend")
  1. Get a user's posts
posts = client.Post.get_user_posts("myfriend")
# posts is now a list of Post object
  1. Playing with characters
char_id = "xxxx" # your character's id
char = client.Character.get(char_id)
# The above function returns a character object that helps you modify it
# To get the character info only, you can client.Character.info(char_id)
  1. Chatting
char_id = "xxxx" # your character's id
chat = client.Chat.open(char_id) # This creates a new chat (if it doesn't exist one) or reopen the old one

Demos

  1. Get your registration email
from CharAI import *

MY_TOKEN = "xxxx"

client = Client(MY_TOKEN)

my_email = client.user.email
print(my_email)
  1. Upload your new avatar
from CharAI import *

MY_TOKEN = "xxxx"

client = Client(MY_TOKEN)

user = client.User.self()
user.update(avatar=new.File("path/to/img.jpg", content_type="image/jpg", name="img.jpg"))
  1. Send a simple message and generate alternative responses
from CharAI import *

MY_TOKEN = "xxxx"

client = Client(MY_TOKEN)

chat = client.Chat.open("CHARACTER_ID_HERE")

message = Messaging.Object(client, "hello world")
response1 = chat.reply(message).replies
response2 = chat.next().replies
response3 = chat.next().replies
response4 = chat.next().replies
  1. Send message with AI-generated image and receiving speech
from CharAI import *

MY_TOKEN = "xxxx"

client = Client(MY_TOKEN)

chat = client.Chat.open("CHARACTER_ID_HERE")
message = Messaging.Object(client, "hello world", gen_img=True, gen_descr="A beautiful flower")

response = chat.reply(message)
audios = response.audios
replies = response.replies

# to get the binaries of the audios, you can
aud1 = audios[0].binaries()
# or you can dump it to a file
with open("aud1.mp3", "wb") as fp:
    audios[0].dump(fp)
Clone this wiki locally