1
0
Fork 0
This commit is contained in:
t.me/xtekky 2023-04-25 12:31:12 +01:00
parent f236f0764e
commit cfce83bb84
6 changed files with 16 additions and 191 deletions

View file

@ -1,42 +0,0 @@
### Example: `sqlchat` (use like openai pypi package) <a name="example-sqlchat"></a>
```python
# Import sqlchat
import sqlchat
# sqlchat.Completion.create
# sqlchat.StreamCompletion.create
[...]
```
#### Example Chatbot
```python
messages = []
while True:
user = input('you: ')
sqlchat_cmpl = sqlchat.Completion.create(
prompt = user,
messages = messages
)
print('gpt:', sqlchat_cmpl.completion.choices[0].text)
messages.extend([
{'role': 'user', 'content': user },
{'role': 'assistant', 'content': sqlchat_cmpl.completion.choices[0].text}
])
```
#### Streaming Response:
```python
for response in sqlchat.StreamCompletion.create(
prompt = 'write python code to reverse a string',
messages = []):
print(response.completion.choices[0].text)
```

View file

@ -1,117 +0,0 @@
from requests import post
from time import time
headers = {
'authority' : 'www.sqlchat.ai',
'accept' : '*/*',
'accept-language': 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3',
'content-type' : 'text/plain;charset=UTF-8',
'origin' : 'https://www.sqlchat.ai',
'referer' : 'https://www.sqlchat.ai/',
'sec-fetch-dest' : 'empty',
'sec-fetch-mode' : 'cors',
'sec-fetch-site' : 'same-origin',
'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',
}
class SqlchatResponse:
class Completion:
class Choices:
def __init__(self, choice: dict) -> None:
self.text = choice['text']
self.content = self.text.encode()
self.index = choice['index']
self.logprobs = choice['logprobs']
self.finish_reason = choice['finish_reason']
def __repr__(self) -> str:
return f'''<__main__.APIResponse.Completion.Choices(\n text = {self.text.encode()},\n index = {self.index},\n logprobs = {self.logprobs},\n finish_reason = {self.finish_reason})object at 0x1337>'''
def __init__(self, choices: dict) -> None:
self.choices = [self.Choices(choice) for choice in choices]
class Usage:
def __init__(self, usage_dict: dict) -> None:
self.prompt_tokens = usage_dict['prompt_chars']
self.completion_tokens = usage_dict['completion_chars']
self.total_tokens = usage_dict['total_chars']
def __repr__(self):
return f'''<__main__.APIResponse.Usage(\n prompt_tokens = {self.prompt_tokens},\n completion_tokens = {self.completion_tokens},\n total_tokens = {self.total_tokens})object at 0x1337>'''
def __init__(self, response_dict: dict) -> None:
self.response_dict = response_dict
self.id = response_dict['id']
self.object = response_dict['object']
self.created = response_dict['created']
self.model = response_dict['model']
self.completion = self.Completion(response_dict['choices'])
self.usage = self.Usage(response_dict['usage'])
def json(self) -> dict:
return self.response_dict
class Completion:
def create(
prompt: str = 'hello world',
messages: list = []) -> SqlchatResponse:
response = post('https://www.sqlchat.ai/api/chat', headers=headers, stream=True,
json = {
'messages': messages,
'openAIApiConfig':{'key':'','endpoint':''}})
return SqlchatResponse({
'id' : f'cmpl-1337-{int(time())}',
'object' : 'text_completion',
'created': int(time()),
'model' : 'gpt-3.5-turbo',
'choices': [{
'text' : response.text,
'index' : 0,
'logprobs' : None,
'finish_reason' : 'stop'
}],
'usage': {
'prompt_chars' : len(prompt),
'completion_chars' : len(response.text),
'total_chars' : len(prompt) + len(response.text)
}
})
class StreamCompletion:
def create(
prompt : str = 'hello world',
messages: list = []) -> SqlchatResponse:
messages.append({
'role':'user',
'content':prompt
})
response = post('https://www.sqlchat.ai/api/chat', headers=headers, stream=True,
json = {
'messages': messages,
'openAIApiConfig':{'key':'','endpoint':''}})
for chunk in response.iter_content(chunk_size = 2046):
yield SqlchatResponse({
'id' : f'cmpl-1337-{int(time())}',
'object' : 'text_completion',
'created': int(time()),
'model' : 'gpt-3.5-turbo',
'choices': [{
'text' : chunk.decode(),
'index' : 0,
'logprobs' : None,
'finish_reason' : 'stop'
}],
'usage': {
'prompt_chars' : len(prompt),
'completion_chars' : len(chunk.decode()),
'total_chars' : len(prompt) + len(chunk.decode())
}
})

View file

@ -1,3 +1,5 @@
### note: currently patched
### Example: `t3nsor` (use like openai pypi package) <a name="example-t3nsor"></a>
```python

View file

@ -1,6 +1,4 @@
import asyncio
import websockets
from json import dumps, loads
async def test():
@ -20,6 +18,8 @@ async def test():
try:
response = await wss.recv()
json_response = loads(response)
print(json_response)
ended = json_response.get('eof')
if not ended:
@ -28,4 +28,3 @@ async def test():
except websockets.ConnectionClosed:
break
asyncio.run(test())

View file

@ -1,29 +0,0 @@
# inport ora
import ora
# create model
model = ora.CompletionModel.create(
system_prompt = 'You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible',
description = 'ChatGPT Openai Language Model',
name = 'gpt-3.5')
print(model.id)
# init conversation (will give you a conversationId)
init = ora.Completion.create(
model = model,
prompt = 'hello world')
print(init.completion.choices[0].text)
while True:
# pass in conversationId to continue conversation
prompt = input('>>> ')
response = ora.Completion.create(
model = model,
prompt = prompt,
includeHistory = True,
conversationId = init.id)
print(response.completion.choices[0].text)

12
unfinished/test.py Normal file
View file

@ -0,0 +1,12 @@
import gptbz
import asyncio
# asyncio.run(gptbz.test())
import requests
image = '/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAoALQDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2u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BJ5ewuEBYx8gbiBxz+FFFS3ZM1p01OdNN/wBaFfVtU0qHxHplx9qsSkEl2853SvIjxwjdtCZXIX7wbt05q7YJdS6nc6vYxWEtpfi2KS+bKsjQhCSWBBG4bhtAAyCcmiinF3k0RWgqdKMl1VvxZfM2s+VkWFh5nl5x9tfG/djGfK6bec468Y/irN1CeUCeHXbrTItPc3O6GN5PNltxHx0I+YKXLYB42455ooqpaIwo2lO1rE1rZjUYrcCO2Giw/Zp7BYzKrkKu4bh8oAB2EA56HIz0u3uxL+1kbygQpQFt2fmki4GOOuOvfHbNFFPpcTu6nKFpsTU75V8oNJKXIXduOI4hk54zjHTjGO+a0KKKaM59PQxLqNNBMuoQpDFYJEfPQLISp8zcWAXIxh5CcLnOMnHQaFNKkkvtOFoli0k9xqP32Zn24LIFyM7kwRg98c5yUVL3No6xTfV2/IrxyW0vh21kQ2phaexKn97s5aErj+LPTbnj7u7+KujoopxZNZW+9/oQXdpBfWk1rcxiSGVGjdSSMhgQeRyOCRxWOtvbXU0Ol6mIHksJbea0IMoJYISGy3U5ST+JuB83uUUMVJuz121JnaL/AITOBSYPOGnyEA7/ADdvmJnH8G3IHX5s4xxmtmiihdRVFZR9AoooqjI//9k='
response = requests.get('https://ocr.holey.cc/ncku?base64_str=%s' % image) #.split('base64,')[1])
print(response.content)