🧑‍💻Quick Start

Example and explanation of the library

Let's write a version of the code for chatting with a character

First of all, we need to import the library and write the startup code

from characterai import PyCAI

client = PyCAI('TOKEN')

# CODE

Now we have to take the necessary chat information to send the message

char = input('Enter CHAR: ')

chat = client.chat.get_chat(char)

participants = chat['participants']

if not participants[0]['is_human']:
    tgt = participants[0]['user']['username']
else:
    tgt = participants[1]['user']['username']

And now let's make a cycle in which there will be a chat

while True:
    message = input('You: ')

    data = client.chat.send_message(
        chat['external_id'], tgt, message
    )

    name = data['src_char']['participant']['name']
    text = data['replies'][0]['text']

    print(f"{name}: {text}")

The full code is available in the "Examples" folder

Last updated