kramcat / CharacterAI

Unofficial Python API for character.ai
https://docs.kram.cat
MIT License
434 stars 61 forks source link

Stuck waiting for Character response #46

Closed Psyk0loge closed 1 year ago

Psyk0loge commented 1 year ago

Hi, I started using this library cause I had problems when developing my own library. I am using the synchronous standard example provided in github. It sometimes works, but mostly does not. When using the headless = false option it is always stuck at the point shown in the picture. image

Any ideas what is happenig? There is no error messagen, its just waiting for the response: image

kramcat commented 1 year ago

send your code

Psyk0loge commented 1 year ago
from characterai import PyCAI

client = PyCAI('#####################################', headless=False)

char = 'VvRwRK_-FuuBkX3X1YqqJFsfKbXw3uL1NLet2emisv0'

# Save tgt and history_external_id 
# to avoid making a lot of requests
chat = client.chat.get_chat(char)

history_id = chat['external_id']
participants = chat['participants']

# In the list of "participants",
# a character can be at zero or in the first place
if not participants[0]['is_human']:
    tgt = participants[0]['user']['username']
else:
    tgt = participants[1]['user']['username']

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

    data = client.chat.send_message(
        char, message, history_external_id=history_id, tgt=tgt
    )

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

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

This is my code I will provide whats happening more detailed in a second

Psyk0loge commented 1 year ago

Hey, sorry for wasting your time... When trying to record a timeout happend and I relaized that character.py was trying to open urls with the: "https://beta.character.ai/" but I am a plus user (forgot to cancle) and so I need to replace all urls with: "https://plus.character.ai/". And now everything works like a char !!!!