-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot create a new chat #70
Comments
Hi, try this: client = PyAsyncCAI('CHARACTER_AI_TOKEN')
async with client.connect() as chat2:
#create your new chat here... See the source for more details |
@tominal I dont understand what you mean. I got the char_token and it's working great to send and receive messages, the problem here is that idk how to use the new_chat method because the websocket property is never defined :/ @Karvp Thank you for your answer. |
Could you share your code and goal so we can understand your issue better? |
Sure! The aim is to create a new chat everytime i run the code and then to speak with the character. async def test():
client = PyAsyncCAI(token)
async with client.connect() as chat2:
chat = await chat2.new_chat(char_id,"idk",user_id)
author = {"author_id": chat["chats"][0]["creator_id"]}
while True:
message = input("You: ")
data = await chat2.send_message(char_id, chat["chats"][0]["chat_id"], message, author)
print(json.dumps(data))
name = data["turn"]["author"]["name"]
text = data["turn"]["candidates"][0]["raw_content"]
print(f"{name}: {text}")
asyncio.run(test()) Edit : I forgot to put the call to the client sry |
Did you use the correct user id? Are you the owner of the character? If not, is the character public? Edit: I have fixed a few mistake in your code: import uuid
import characterai, asyncio, json
def print_response(data: dict):
name, text = data["turn"]["author"]["name"], data["turn"]["candidates"][0]["raw_content"]
print(f'{name}: {text}')
async def test():
char_id = "CHARACTER_ID"
user_id = "USER_ID"
client = characterai.PyAsyncCAI("TOKEN")
async with client.connect() as chat2:
# generate the chat_id
chat_id = str(uuid.uuid4())
# The new_chat returns a tuple
chat, greeting = await chat2.new_chat(char_id,chat_id,user_id)
# This is the correct way to get creator_id
author = {"author_id": chat["chat"]["creator_id"]}
# Correct way to get chat_id
# chat_id = chat["chat"]["chat_id"]
while True:
message = input("You: ")
data = await chat2.send_message(char_id, chat_id, message, author)
print(json.dumps(data))
print_response(data)
asyncio.run(test()) I have added the chat_id creator, see uuid.uuid4(). Please note that you can only create 1 chat with an id. P/s: This is the dictionary structure of the
|
check on new version |
Hello,
When I'm trying to create a new chat, I got this error :
AttributeError: 'NoneType' object has no attribute 'send'
We can see in pyaisynccai.py:31 that the ws attribute is defined as None.
Am I doing something wrong or is it just a lack of implementation in the code?
The text was updated successfully, but these errors were encountered: