Coder Social home page Coder Social logo

character.ai's Introduction

Character.AI

An unofficial high level API for character.ai for Python

Warning

Since kramcat's CharacterAI has updated (v1.0.0a1) and cover a lot of this library's functions, there is no need for this library anymore. This library will be archived. Thanks for all of the support.

Introduction

The original idea was from kramcat's CharacterAI. This library aims on ease of use rather than a more functional library. You can get the token to use in this library from your Character AI account. kramcat has made a demonstration on it.

Note

This library is developing, bugs may occur occasionally. Every contribution is greatly appreciated!

Sorry for the messy coding ๐Ÿคฃ If you have any issues, please tell me at Github Issues.

Documentation

You can check the wiki or read my notes in the code, though it is so little.

Usage

Currently this library only supports querying with: Character, Post, User and Chat. You can make a post, comment on it, search information about characters, users, posts, or even chatting

Here is an example of getting basic information from the account:

from CharAI import *
from CharAI.helper import dump

# don't mind this messy, it is just for dumpping attributes
def pass_check(x):
    if isinstance(x, CAI):
        return False
    return True

full_dumper = lambda x: (dict([(k, v) for k, v in vars(x).items() if not k.startswith('__') and pass_check(x)]) if hasattr(x, '__dict__') else str(x)) if pass_check(x) else "PASSED"

client = Client("YOUR_TOKEN_HERE")

me = client.User.self()

dump(me, default=full_json_dumper)

dump(me.recent_chat(), default=full_dumper)
dump(me.recent_chat2(), default=full_dumper)
dump(me.recent_rooms(), default=full_dumper)

And here is an example of chatting:

from CharAI import *

client = Client("YOUR_TOKEN_HERE")

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

chat.voice = True
# we will turn on voice

message = Messaging.Object(client, "hello world", img=new.File("path/to/your/image"), img_descr="YOUR_IMAGE_DESCRIPTION")
# or you can use this as well
# message = client.Chat.msg("hello world", img=new.File("path/to/your/image"), img_descr="YOUR_IMAGE_DESCRIPTION")

# We will try to send our message
try:
    # the reply function is used to send message
    response = chat.reply(message)
    # if you have alternatives, you can select by its uuid
    # response = chat.reply(message, uuid="0000-0000-0000-0000")

    # the reply function returns a Response object, with its attributes: `replies` and `audios`
    # `audios` is the list of new.MP3 object, use new.MP3.binaries() to get the binaries
    # `replies` containing replies from the bot

    # to get alternative response, use chat.next()
    response = chat.next()
except errors.ServerError:
    print("Retrying...")
    try:
        # After you've sent the message for the first time, you can retry sending it like this
        response = message.retry()
    except errors.ServerError:
        print("Failed!")

Bottom

Note

I built this library as a hobby, so I will not update it frequently. Stay tuned if you find something interesting.

character.ai's People

Contributors

karvp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

character.ai's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.