1
0
Fork 0

added theb to openai_rev module

This commit is contained in:
Raju Komati 2023-04-28 02:58:12 +05:30
parent b206a1eb63
commit dc1d9834f9
No known key found for this signature in database
GPG key ID: A581A5D67A8EB090
9 changed files with 35 additions and 21 deletions

View file

@ -38,7 +38,7 @@ Please note the following:
| **Copyright** | Copyright information | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#copyright) | - | | **Copyright** | Copyright information | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#copyright) | - |
| **Star History** | Star History | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#star-history) | - | | **Star History** | Star History | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#star-history) | - |
| **Usage Examples** | | | | | **Usage Examples** | | | |
| `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) | | `theb` | Example usage for theb (gpt-3.5) | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](openai_rev/theb/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) |
| `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) | || | `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) | ||
| `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) | | `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) |
| `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) | | `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) |

View file

@ -169,7 +169,6 @@ class Completion:
) -> ForeFrontResponse: ) -> ForeFrontResponse:
text = '' text = ''
final_response = None final_response = None
res = list(StreamingCompletion.create(token=token, prompt=prompt))
for response in StreamingCompletion.create( for response in StreamingCompletion.create(
token=token, token=token,
chat_id=chat_id, chat_id=chat_id,

View file

@ -2,6 +2,7 @@ from enum import Enum
from openai_rev import forefront from openai_rev import forefront
from openai_rev import quora from openai_rev import quora
from openai_rev import theb
from openai_rev import you from openai_rev import you
@ -9,6 +10,7 @@ class Provider(Enum):
You = 'you' You = 'you'
Poe = 'poe' Poe = 'poe'
ForeFront = 'fore_front' ForeFront = 'fore_front'
Theb = 'theb'
class Completion: class Completion:
@ -20,6 +22,8 @@ class Completion:
return Completion.__you_service(prompt, **kwargs) return Completion.__you_service(prompt, **kwargs)
elif provider == Provider.ForeFront: elif provider == Provider.ForeFront:
return Completion.__fore_front_service(prompt, **kwargs) return Completion.__fore_front_service(prompt, **kwargs)
elif provider == Provider.Theb:
return Completion.__theb_service(prompt, **kwargs)
@classmethod @classmethod
def __you_service(cls, prompt: str, **kwargs) -> str: def __you_service(cls, prompt: str, **kwargs) -> str:
@ -32,3 +36,7 @@ class Completion:
@classmethod @classmethod
def __fore_front_service(cls, prompt: str, **kwargs) -> str: def __fore_front_service(cls, prompt: str, **kwargs) -> str:
return forefront.Completion.create(prompt=prompt, **kwargs).text return forefront.Completion.create(prompt=prompt, **kwargs).text
@classmethod
def __theb_service(cls, prompt: str, **kwargs):
return ''.join(theb.Completion.create(prompt=prompt))

View file

@ -1,9 +1,8 @@
### Example: `theb` (use like openai pypi package) <a name="example-theb"></a> ### Example: `theb` (use like openai pypi package) <a name="example-theb"></a>
```python ```python
# import library # import library
import theb from openai_rev import theb
# simple streaming completion # simple streaming completion
for token in theb.Completion.create('hello world'): for token in theb.Completion.create('hello world'):

View file

@ -1,9 +1,11 @@
from re import findall
from json import loads from json import loads
from queue import Queue, Empty from queue import Queue, Empty
from re import findall
from threading import Thread from threading import Thread
from curl_cffi import requests from curl_cffi import requests
class Completion: class Completion:
# experimental # experimental
part1 = '{"role":"assistant","id":"chatcmpl' part1 = '{"role":"assistant","id":"chatcmpl'
@ -14,7 +16,8 @@ class Completion:
message_queue = Queue() message_queue = Queue()
stream_completed = False stream_completed = False
def request(prompt: str): @classmethod
def request(cls, prompt: str):
headers = { headers = {
'authority': 'chatbot.theb.ai', 'authority': 'chatbot.theb.ai',
'content-type': 'application/json', 'content-type': 'application/json',
@ -22,12 +25,11 @@ class Completion:
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36',
} }
requests.post('https://chatbot.theb.ai/api/chat-process', headers=headers, requests.post(
content_callback = Completion.handle_stream_response, 'https://chatbot.theb.ai/api/chat-process',
json = { headers=headers,
'prompt': prompt, content_callback=Completion.handle_stream_response,
'options': {} json={'prompt': prompt, 'options': {}},
}
) )
Completion.stream_completed = True Completion.stream_completed = True
@ -36,7 +38,7 @@ class Completion:
def create(prompt: str): def create(prompt: str):
Thread(target=Completion.request, args=[prompt]).start() Thread(target=Completion.request, args=[prompt]).start()
while Completion.stream_completed != True or not Completion.message_queue.empty(): while not Completion.stream_completed or not Completion.message_queue.empty():
try: try:
message = Completion.message_queue.get(timeout=0.01) message = Completion.message_queue.get(timeout=0.01)
for message in findall(Completion.regex, message): for message in findall(Completion.regex, message):

View file

@ -0,0 +1,4 @@
from openai_rev import theb
for token in theb.Completion.create('hello world'):
print(token, end='', flush=True)

View file

@ -15,3 +15,6 @@ trbfm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_Cw8lFCtsc-uDcgMMSrenYmGnlPt8cD49k7OGNzE-GAXjVoxaVUFNQSloP76C-Nh919ycDId6x8U6P9DkOojLRUhEaGRNPI5SopO7IAOWt3S7jgpczzRW70pC_tn3EEcxFPm67tb2c41PdXk2vxrOwRo38cXPA

View file

@ -3,15 +3,13 @@ from openai_rev import openai_rev, Provider, quora, forefront
# usage You # usage You
response = openai_rev.Completion.create(Provider.You, prompt='Write a poem on Lionel Messi') response = openai_rev.Completion.create(Provider.You, prompt='Write a poem on Lionel Messi')
print(response) print(response)
print(f'END')
# usage Poe # usage Poe
# token = quora.Account.create(logging=False) token = quora.Account.create(logging=False)
token = 'GKzCahZYGKhp76LfE197xw=='
response = openai_rev.Completion.create( response = openai_rev.Completion.create(
Provider.Poe, prompt='Write a poem on Lionel Messi', token=token, model='ChatGPT' Provider.Poe, prompt='Write a poem on Lionel Messi', token=token, model='ChatGPT'
) )
print(response) print(response)
print(f'END')
# usage forefront # usage forefront
token = forefront.Account.create(logging=False) token = forefront.Account.create(logging=False)
@ -19,3 +17,8 @@ response = openai_rev.Completion.create(
Provider.ForeFront, prompt='Write a poem on Lionel Messi', model='gpt-4', token=token Provider.ForeFront, prompt='Write a poem on Lionel Messi', model='gpt-4', token=token
) )
print(response) print(response)
print(f'END')
# usage theb
response = openai_rev.Completion.create(Provider.Theb, prompt='Write a poem on Lionel Messi')
print(response)

View file

@ -1,4 +0,0 @@
import theb
for token in theb.Completion.create('hello world'):
print(token, end='', flush=True)