Open TwangyMoney opened 11 months ago
same
I've found that. Your problem must be in using wrong chat, Use chat2 instead of just chat
import asyncio
from characterai import PyAsyncCAI
async def main():
client = PyAsyncCAI('TOKEN')
char = input('Enter CHAR: ')
chat = await client.chat2.get_chat(char)
author = {
'author_id': chat['chats'][0]['creator_id']
}
while True:
message = input('You: ')
async with client.connect() as chat2:
data = await chat2.send_message(
char, chat['chats'][0]['chat_id'],
message, author
)
name = data['turn']['author']['name']
text = data['turn']['candidates'][0]['raw_content']
print(f"{name}: {text}")
asyncio.run(main())
I've found that. Your problem must be in using wrong chat, Use chat2 instead of just chat
import asyncio from characterai import PyAsyncCAI async def main(): client = PyAsyncCAI('TOKEN') char = input('Enter CHAR: ') chat = await client.chat2.get_chat(char) author = { 'author_id': chat['chats'][0]['creator_id'] } while True: message = input('You: ') async with client.connect() as chat2: data = await chat2.send_message( char, chat['chats'][0]['chat_id'], message, author ) name = data['turn']['author']['name'] text = data['turn']['candidates'][0]['raw_content'] print(f"{name}: {text}") asyncio.run(main())
well still got error.
I found a fix from a discord server. But uh, idk how to explain it. The error is fixed for me now I just used another person's example code.
I found a fix from a discord server. But uh, idk how to explain it. The error is fixed for me now I just used another person's example code.
can i ask you why you reply this message without any solution, even when you have solution? give solution. this is issues, to find solution.
I didn't give a solution as I replied through gmail not from the website and I was busy.
On Sun, Oct 22, 2023 at 8:28 PM Yoga Pranata @.***> wrote:
I found a fix from a discord server. But uh, idk how to explain it. The error is fixed for me now I just used another person's example code.
can i ask you why you reply this message without any solution, even when you have solution? give solution. this is issues, to find solution.
— Reply to this email directly, view it on GitHub https://github.com/kramcat/CharacterAI/issues/59#issuecomment-1774110050, or unsubscribe https://github.com/notifications/unsubscribe-auth/AU5VVYRE7UH3QTAHW5DWRGDYAUUSRAVCNFSM6AAAAAA6GUZJNWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZUGEYTAMBVGA . You are receiving this because you authored the thread.Message ID: @.***>
So, as per user zYxDevs and everyone's request, I'm writing this to let you guys know how I got it to work. I did this from python 3.11.6 and on the latest version of character.ai which currently is characterai==0.8.0 To install python 3.11.6 go to python website here: https://www.python.org/downloads/release/python-3116/ To install characterai==0.8.0, make sure you have python installed first and then run:
pip3.11 install characterai==0.8.0
Now, first of all, make sure you go to the characterai website and, whichever character you chose go to it's chat and write 1 message there and let the AI reply. In this specific code we're using chat2 so in the url (for example https://beta.character.ai/chat?char=X4Q7WpO2BcDrxSBtFtrTkJJR3os46b0clYOtoigyWD4) make sure it says chat2 instead for chat after beta.character.ai/ (for example https://beta.character.ai/chat2?char=X4Q7WpO2BcDrxSBtFtrTkJJR3os46b0clYOtoigyWD4) and then write 1 message there after making sure the url says chat2. Now with that said, this is how the python code works:
client = PyAsyncCAI('CHARACTER_AI_TOKEN')
char = 'CHARACTER_ID'
chat = await client.chat2.get_chat(char)
author = {'author_id': chat['chats'][0]['creator_id']}
msg1 = "Hello."
async with client.connect() as chat2:
data = await chat2.send_message(
char, chat['chats'][0]['chat_id'],
msg1, author
)
text = data['turn']['candidates'][0]['raw_content']
Here, the msg1 variable is where we're sending our message. The msg1 variable will be the message we're sending to the bot. And the text variable is the bot's reply. When using this make sure to await so it can finish loading the bot's message. For example in cases of discord bots, you can await like this:
await message.channel.send(text)
Anywhere else similarly. This way the variable has time to load the bot's message and thus can work correctly. These are all the things you need to make sure so that your code works. Or so I hope. For further help message me on Discord: realtwangy
So, as per user zYxDevs and everyone's request, I'm writing this to let you guys know how I got it to work. I did this from python 3.11.6 and on the latest version of character.ai which currently is characterai==0.8.0 To install python 3.11.6 go to python website here: https://www.python.org/downloads/release/python-3116/ To install characterai==0.8.0, make sure you have python installed first and then run:
pip3.11 install characterai==0.8.0
Now, first of all, make sure you go to the characterai website and, whichever character you chose go to it's chat and write 1 message there and let the AI reply. In this specific code we're using chat2 so in the url (for example https://beta.character.ai/chat?char=X4Q7WpO2BcDrxSBtFtrTkJJR3os46b0clYOtoigyWD4) make sure it says chat2 instead for chat after beta.character.ai/ (for example https://beta.character.ai/chat2?char=X4Q7WpO2BcDrxSBtFtrTkJJR3os46b0clYOtoigyWD4) and then write 1 message there after making sure the url says chat2. Now with that said, this is how the python code works:
client = PyAsyncCAI(os.environ['CHARACTER_AI_TOKEN']) char = os.environ['CHARACTER_ID'] chat = await client.chat2.get_chat(char) author = {'author_id': chat['chats'][0]['creator_id']} msg1 = "Hello." async with client.connect() as chat2: data = await chat2.send_message( char, chat['chats'][0]['chat_id'], msg1, author ) text = data['turn']['candidates'][0]['raw_content']
Here, the msg1 variable is where we're sending our message. The msg1 variable will be the message we're sending to the bot. And the text variable is the bot's reply. When using this make sure to await so it can finish loading the bot's message. For example in cases of discord bots, you can await like this:
await message.channel.send(text)
Anywhere else similarly. This way the variable has time to load the bot's message and thus can work correctly. These are all the things you need to make sure so that your code works. Or so I hope. For further help message me on Discord: realtwangy
this is very helpful, after reading this i found my mistake is chat not chat2, after changed to chat2 on character ai web and chatting to the bot its work fine. thank you bro!
So, as per user zYxDevs and everyone's request, I'm writing this to let you guys know how I got it to work. I did this from python 3.11.6 and on the latest version of character.ai which currently is characterai==0.8.0 To install python 3.11.6 go to python website here: https://www.python.org/downloads/release/python-3116/ To install characterai==0.8.0, make sure you have python installed first and then run:
pip3.11 install characterai==0.8.0
Now, first of all, make sure you go to the characterai website and, whichever character you chose go to it's chat and write 1 message there and let the AI reply. In this specific code we're using chat2 so in the url (for example https://beta.character.ai/chat?char=X4Q7WpO2BcDrxSBtFtrTkJJR3os46b0clYOtoigyWD4) make sure it says chat2 instead for chat after beta.character.ai/ (for example https://beta.character.ai/chat2?char=X4Q7WpO2BcDrxSBtFtrTkJJR3os46b0clYOtoigyWD4) and then write 1 message there after making sure the url says chat2. Now with that said, this is how the python code works:
client = PyAsyncCAI(os.environ['CHARACTER_AI_TOKEN']) char = os.environ['CHARACTER_ID'] chat = await client.chat2.get_chat(char) author = {'author_id': chat['chats'][0]['creator_id']} msg1 = "Hello." async with client.connect() as chat2: data = await chat2.send_message( char, chat['chats'][0]['chat_id'], msg1, author ) text = data['turn']['candidates'][0]['raw_content']
Here, the msg1 variable is where we're sending our message. The msg1 variable will be the message we're sending to the bot. And the text variable is the bot's reply. When using this make sure to await so it can finish loading the bot's message. For example in cases of discord bots, you can await like this:
await message.channel.send(text)
Anywhere else similarly. This way the variable has time to load the bot's message and thus can work correctly. These are all the things you need to make sure so that your code works. Or so I hope. For further help message me on Discord: realtwangy
this is very helpful, after reading this i found my mistake is chat not chat2, after changed to chat2 on character ai web and chatting to the bot its work fine. thank you bro!
Np also both chat and chat2 will work, just if you use chat you also needa change the url from chat2 to chat and then write a message, and then your code will work.
What can we do if we want to use the synchronous API (PyCAI)?
client = PyCAI(token)
char = 'mPKDui2e1V7mfbLxTv6S5eu8WTAAwzXmdo1iwfo79IM'
chat = client.chat2.get_chat(char)
author = {'author_id': chat['chats'][0]['creator_id']}
gives AttributeError: 'PyCAI' object has no attribute 'chat2'. Did you mean: 'chat'?
I don't think PyCAI has chat2 idk so, that will be client = PyAsyncCAI(token) not PyCAI(token) or you can use just chat, and make sure you message the ai from the url being chat instead for chat2.
I've tried this example code and it doesn't seem to function:
This is the error it gives me:
I also used another example code provided by someone
It gave me this error:
Help? Also don't worry that token there isn't mine it's a broken version of a token provided by someone else.