-
Notifications
You must be signed in to change notification settings - Fork 0
/
PKG-INFO
158 lines (113 loc) · 3.88 KB
/
PKG-INFO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
Metadata-Version: 2.1
Name: PyCharacterAI
Version: 1.1.0
Summary: An unofficial asynchronous api wrapper for Character AI.
Home-page: https://github.com/Xtr4F/PyCharacterAI
Author: XtraF
Author-email: igoromarov15@gmail.com
License: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3.10
Classifier: License :: OSI Approved :: MIT License
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
# PyCharacterAI
> An unofficial asynchronous Python api wrapper for [Character AI](https://character.ai/) using [curl-cffi](https://github.com/yifeikong/curl_cffi).
##
This library is based on the [Character AI Unofficial Node API](https://github.com/realcoloride/node_characterai), made by [realcoloride](https://github.com/realcoloride).
If you have any questions, problems, suggestions, please contact me:
[![Tag](https://img.shields.io/badge/discord-server-black?style=flat&logo=Discord)](https://discord.gg/MN7pMbH2)
[![Tag](https://img.shields.io/badge/telegram-dm-black?style=flat&logo=Telegram)](https://t.me/XtraF)
рџ“љ [Documentation](https://github.com/Xtr4F/PyCharacterAI/blob/main/docs/welcome.md).
---
## Installation
```bash
pip install PyCharacterAI
```
---
## Getting started
**First, import and create a new instance of the `Client` class**:
```Python
from PyCharacterAI import Client
client = Client()
```
> You can use `client = Client(use_plus=True)` if you have character ai
> plus.
---
**This library allows you to authenticate in two ways**:
\
*1. As a guest (Some api features are not available)*:
```Python
await client.authenticate_as_guest()
```
\
*2. Using a token*:
```Python
token = 'TOKEN'
await client.authenticate_with_token(token)
```
> Instructions for getting a token:
>
> 1. Open the Character AI website in your browser
> 2. Open the developer tools `F12` and go to the `Application` tab.
> 3. Go to the `Storage` section and click on `Local Storage`.
> 4. Look for the `char_token` key.
> 5. Copy `value`.
>
>
> вљ пёЏ Warning! Do not share this token with anyone!
---
## Examples
#### Simple example:
```Python
import asyncio
from PyCharacterAI import Client
token = "TOKEN"
async def main():
client = Client()
await client.authenticate_with_token(token)
username = (await client.fetch_user())['user']['username']
print(f'Authenticated as {username}')
character_id = "iV5qb8ttzD7Ytl69U_-ONcW2tW_lrFrOVKExyKJHlJM" # Lily (by @landon)
chat = await client.create_or_continue_chat(character_id)
while True:
message = input(f'{username}: ') # In: Hi!
answer = await chat.send_message(message)
print(f"{answer.src_character_name}: {answer.text}") # Out: hello there! what kind of question you gonna ask me ? i'm here to assist you :)
asyncio.run(main())
```
---
#### Working with images:
> We'll get a link to the image on the Character AI server, which we can use for our own purposes: attach it to a message, download it, etc.
\
*1. We can generate an image from a prompt*:
```python
prompt = "Prompt"
url = await client.generate_image(prompt)
```
\
*2. We can upload our own image*:
```python
image = "URL or path to the image"
url = (await client.upload_image(image))['response']
```
> Available image formats: PNG, JPEG, WEBP.
>
---
#### Working with voice:
> We can synthesize audio from text using one of several voices (Text to Speech)
[A list of available voices](https://github.com/Xtr4F/PyCharacterAI/blob/main/docs/resources/voices.json)
```python
text = "Hi all ! This is PyCharacterAI. PyCharacterAI is An unofficial asynchronous api wrapper for Character AI. For Python."
voice = 22 # Anime Girl (F) (en-US)
audio = await client.generate_voice(voice, text)
```
>It'll return BytesIO, which we can use:
>
>```python
>filepath = "voice.mp3" # Path to the directory where you want to save the audio
>
>with open(filepath, 'wb') as f:
> f.write(audio.read())
>```