XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

theb.ai

ac96278d
t.me/xtekky <98614666+xtekky@users.noreply.github.com>
提交于

代码差异

5 个文件 +31 -26
Modified README.md +5 -0
@@ -38,8 +38,13 @@ Please note the following:
38 38 | **Copyright** | Copyright information | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#copyright) | - |
39 39 | **Star History** | Star History | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#star-history) | - |
40 40 | **Usage Examples** | | | |
41
42 | `theb` | Example usage for theb (gpt-3.5) | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./theb/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) | | |
43
41 44 | `forefront` | Example usage for forefront (gpt-4) | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./forefront/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) | | |
45
42 46 | `quora (poe)` | Example usage for quora | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./quora/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) | |
47
43 48 | `you` | Example usage for you | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./you/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) |
44 49 | **Try it Out** | | | |
45 50 | Google Colab Jupyter Notebook | Example usage for gpt4free | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DanielShemesh/gpt4free-colab/blob/main/gpt4free.ipynb) | - |
Added theb/README.md +11 -0
@@ -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 ```
Renamed theb/__init__.py +11 -23
@@ -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)
Added theb/theb_test.py +4 -0
@@ -0,0 +1,4 @@
1 import theb
2
3 for token in theb.Completion.create('hello world'):
4 print(token, end='', flush=True)
Deleted unfinished/theb.ai/README.md +0 -3
@@ -1,3 +0,0 @@
1 https://chatbot.theb.ai/
2 to do:
3 - code refractoring