t.me/xtekky commited on
Commit
ac96278
1 Parent(s): 011d0ba
README.md CHANGED
@@ -38,8 +38,13 @@ Please note the following:
38
  | **Copyright** | Copyright information | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#copyright) | - |
39
  | **Star History** | Star History | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#star-history) | - |
40
  | **Usage Examples** | | | |
 
 
 
41
  | `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) | | |
 
42
  | `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) | |
 
43
  | `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
  | **Try it Out** | | | |
45
  | 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) | - |
 
38
  | **Copyright** | Copyright information | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#copyright) | - |
39
  | **Star History** | Star History | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#star-history) | - |
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
+
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
+
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
+
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) |
49
  | **Try it Out** | | | |
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) | - |
theb/README.md ADDED
@@ -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
+ ```
{unfinished/theb.ai → theb}/__init__.py RENAMED
@@ -1,11 +1,9 @@
 
1
  from json import loads
2
  from queue import Queue, Empty
3
- from re import findall
4
  from threading import Thread
5
-
6
  from curl_cffi import requests
7
 
8
-
9
  class Completion:
10
  # experimental
11
  part1 = '{"role":"assistant","id":"chatcmpl'
@@ -16,7 +14,7 @@ class Completion:
16
  message_queue = Queue()
17
  stream_completed = False
18
 
19
- def request():
20
  headers = {
21
  'authority': 'chatbot.theb.ai',
22
  'content-type': 'application/json',
@@ -25,24 +23,24 @@ class Completion:
25
  }
26
 
27
  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
- )
34
 
35
  Completion.stream_completed = True
36
 
37
  @staticmethod
38
- def create():
39
- Thread(target=Completion.request).start()
40
 
41
  while Completion.stream_completed != True or not Completion.message_queue.empty():
42
  try:
43
  message = Completion.message_queue.get(timeout=0.01)
44
  for message in findall(Completion.regex, message):
45
- yield loads(Completion.part1 + message + Completion.part2)
46
 
47
  except Empty:
48
  pass
@@ -50,13 +48,3 @@ class Completion:
50
  @staticmethod
51
  def handle_stream_response(response):
52
  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)
 
1
+ from re import findall
2
  from json import loads
3
  from queue import Queue, Empty
 
4
  from threading import Thread
 
5
  from curl_cffi import requests
6
 
 
7
  class Completion:
8
  # experimental
9
  part1 = '{"role":"assistant","id":"chatcmpl'
 
14
  message_queue = Queue()
15
  stream_completed = False
16
 
17
+ def request(prompt: str):
18
  headers = {
19
  'authority': 'chatbot.theb.ai',
20
  'content-type': 'application/json',
 
23
  }
24
 
25
  requests.post('https://chatbot.theb.ai/api/chat-process', headers=headers,
26
+ content_callback = Completion.handle_stream_response,
27
+ json = {
28
+ 'prompt': prompt,
29
+ 'options': {}
30
+ }
31
+ )
32
 
33
  Completion.stream_completed = True
34
 
35
  @staticmethod
36
+ def create(prompt: str):
37
+ Thread(target=Completion.request, args=[prompt]).start()
38
 
39
  while Completion.stream_completed != True or not Completion.message_queue.empty():
40
  try:
41
  message = Completion.message_queue.get(timeout=0.01)
42
  for message in findall(Completion.regex, message):
43
+ yield loads(Completion.part1 + message + Completion.part2)['delta']
44
 
45
  except Empty:
46
  pass
 
48
  @staticmethod
49
  def handle_stream_response(response):
50
  Completion.message_queue.put(response.decode())
 
 
 
 
 
 
 
 
 
 
theb/theb_test.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ import theb
2
+
3
+ for token in theb.Completion.create('hello world'):
4
+ print(token, end='', flush=True)
unfinished/theb.ai/README.md DELETED
@@ -1,3 +0,0 @@
1
- https://chatbot.theb.ai/
2
- to do:
3
- - code refractoring