forked from kramcat/CharacterAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import asyncio | ||
from characterai import PyAsyncCAI | ||
|
||
async def main(): | ||
client = PyAsyncCAI('TOKEN') | ||
await client.start() | ||
|
||
char = input('Enter CHAR: ') | ||
|
||
# Save tgt and history_external_id | ||
# to avoid making a lot of requests | ||
chat = await 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 = await 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}") | ||
|
||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import asyncio | ||
from characterai import PyAsyncCAI | ||
|
||
async def main(): | ||
client = PyAsyncCAI('TOKEN') | ||
await client.start() | ||
|
||
history = await client.chat.get_history('CHAR') | ||
|
||
for h in history['messages']: | ||
name = h['src_char']['participant']['name'] | ||
text = h['text'] | ||
|
||
print(f'{name}: {text}') | ||
|
||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from characterai import PyCAI | ||
|
||
client = PyCAI('TOKEN') | ||
|
||
char = input('Enter CHAR: ') | ||
|
||
# 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from characterai import PyCAI | ||
|
||
client = PyCAI('TOKEN') | ||
|
||
history = client.chat.get_history('CHAR') | ||
|
||
for h in history['messages']: | ||
name = h['src_char']['participant']['name'] | ||
text = h['text'] | ||
|
||
print(f'{name}: {text}') |