返回提交历史
Modified
README.md
+5
-0
Added
theb/README.md
+11
-0
Renamed
theb/__init__.py
+11
-23
Added
theb/theb_test.py
+4
-0
Deleted
unfinished/theb.ai/README.md
+0
-3
XFEstudio/gpt4free
theb.ai
ac96278d
代码差异
5 个文件
+31
-26
@@ -38,8 +38,13 @@ Please note the following:
38
38
| **Copyright** | Copyright information | [](#copyright) | - |
39
39
| **Star History** | Star History | [](#star-history) | - |
40
40
| **Usage Examples** | | | |
41
42
| `theb` | Example usage for theb (gpt-3.5) | [](./theb/README.md) |  | | |
43
41
44
| `forefront` | Example usage for forefront (gpt-4) | [](./forefront/README.md) |  | | |
45
42
46
| `quora (poe)` | Example usage for quora | [](./quora/README.md) |  | |
47
43
48
| `you` | Example usage for you | [](./you/README.md) |  |
44
49
| **Try it Out** | | | |
45
50
| Google Colab Jupyter Notebook | Example usage for gpt4free | [](https://colab.research.google.com/github/DanielShemesh/gpt4free-colab/blob/main/gpt4free.ipynb) | - |
@@ -0,0 +1,11 @@
1
### Example: `theb` (use like openai pypi package) <a name="example-theb"></a>
2
3
4
```python
5
# import library
6
import theb
7
8
# simple streaming completion
9
for token in theb.Completion.create('hello world'):
10
print(token, end='', flush=True)
11
```
@@ -1,11 +1,9 @@
1
from re import findall
1
2
from json import loads
2
3
from queue import Queue, Empty
3
from re import findall
4
4
from threading import Thread
5
6
5
from curl_cffi import requests
7
6
8
9
7
class Completion:
10
8
# experimental
11
9
part1 = '{"role":"assistant","id":"chatcmpl'
@@ -16,7 +14,7 @@ class Completion:
16
14
message_queue = Queue()
17
15
stream_completed = False
18
16
19
def request():
17
def request(prompt: str):
20
18
headers = {
21
19
'authority': 'chatbot.theb.ai',
22
20
'content-type': 'application/json',
@@ -25,24 +23,24 @@ class Completion:
25
23
}
26
24
27
25
requests.post('https://chatbot.theb.ai/api/chat-process', headers=headers,
28
content_callback=Completion.handle_stream_response,
29
json={
30
'prompt': 'hello world',
31
'options': {}
32
}
33
)
26
content_callback = Completion.handle_stream_response,
27
json = {
28
'prompt': prompt,
29
'options': {}
30
}
31
)
34
32
35
33
Completion.stream_completed = True
36
34
37
35
@staticmethod
38
def create():
39
Thread(target=Completion.request).start()
36
def create(prompt: str):
37
Thread(target=Completion.request, args=[prompt]).start()
40
38
41
39
while Completion.stream_completed != True or not Completion.message_queue.empty():
42
40
try:
43
41
message = Completion.message_queue.get(timeout=0.01)
44
42
for message in findall(Completion.regex, message):
45
yield loads(Completion.part1 + message + Completion.part2)
43
yield loads(Completion.part1 + message + Completion.part2)['delta']
46
44
47
45
except Empty:
48
46
pass
@@ -50,13 +48,3 @@ class Completion:
50
48
@staticmethod
51
49
def handle_stream_response(response):
52
50
Completion.message_queue.put(response.decode())
53
54
55
def start():
56
for message in Completion.create():
57
yield message['delta']
58
59
60
if __name__ == '__main__':
61
for message in start():
62
print(message)
@@ -0,0 +1,4 @@
1
import theb
2
3
for token in theb.Completion.create('hello world'):
4
print(token, end='', flush=True)
@@ -1,3 +0,0 @@
1
https://chatbot.theb.ai/
2
to do:
3
- code refractoring