summaryrefslogtreecommitdiffstats
path: root/unfinished/t3nsor/__init__.py
diff options
context:
space:
mode:
authort.me/xtekky <98614666+xtekky@users.noreply.github.com>2023-04-27 20:16:07 +0200
committert.me/xtekky <98614666+xtekky@users.noreply.github.com>2023-04-27 20:16:07 +0200
commit10104774c10cccf95bbebcafd17c0a85207583e0 (patch)
tree6fec52831117ee43fe7141a153b7e123ff09d469 /unfinished/t3nsor/__init__.py
parent_ (diff)
parentMerge pull request #205 from AymaneHrouch/reformat__code (diff)
downloadgpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.tar
gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.tar.gz
gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.tar.bz2
gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.tar.lz
gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.tar.xz
gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.tar.zst
gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.zip
Diffstat (limited to 'unfinished/t3nsor/__init__.py')
-rw-r--r--unfinished/t3nsor/__init__.py131
1 files changed, 65 insertions, 66 deletions
diff --git a/unfinished/t3nsor/__init__.py b/unfinished/t3nsor/__init__.py
index aec45dcf..9b588e98 100644
--- a/unfinished/t3nsor/__init__.py
+++ b/unfinished/t3nsor/__init__.py
@@ -1,5 +1,6 @@
+from time import time
+
from requests import post
-from time import time
headers = {
'authority': 'www.t3nsor.tech',
@@ -19,18 +20,17 @@ headers = {
'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 T3nsorResponse:
-
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']
-
+ 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>'''
@@ -39,99 +39,98 @@ class T3nsorResponse:
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']
+ 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'])
+ 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:
model = {
'model': {
- 'id' : 'gpt-3.5-turbo',
- 'name' : 'Default (GPT-3.5)'
+ 'id': 'gpt-3.5-turbo',
+ 'name': 'Default (GPT-3.5)'
}
}
def create(
- prompt: str = 'hello world',
- messages: list = []) -> T3nsorResponse:
-
- response = post('https://www.t3nsor.tech/api/chat', headers = headers, json = Completion.model | {
- 'messages' : messages,
- 'key' : '',
- 'prompt' : prompt
+ prompt: str = 'hello world',
+ messages: list = []) -> T3nsorResponse:
+ response = post('https://www.t3nsor.tech/api/chat', headers=headers, json=Completion.model | {
+ 'messages': messages,
+ 'key': '',
+ 'prompt': prompt
})
return T3nsorResponse({
- 'id' : f'cmpl-1337-{int(time())}',
- 'object' : 'text_completion',
- 'created': int(time()),
- 'model' : Completion.model,
+ 'id': f'cmpl-1337-{int(time())}',
+ 'object': 'text_completion',
+ 'created': int(time()),
+ 'model': Completion.model,
'choices': [{
- 'text' : response.text,
- 'index' : 0,
- 'logprobs' : None,
- 'finish_reason' : 'stop'
- }],
+ '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)
+ 'prompt_chars': len(prompt),
+ 'completion_chars': len(response.text),
+ 'total_chars': len(prompt) + len(response.text)
}
})
+
class StreamCompletion:
model = {
'model': {
- 'id' : 'gpt-3.5-turbo',
- 'name' : 'Default (GPT-3.5)'
+ 'id': 'gpt-3.5-turbo',
+ 'name': 'Default (GPT-3.5)'
}
}
def create(
- prompt: str = 'hello world',
- messages: list = []) -> T3nsorResponse:
-
+ prompt: str = 'hello world',
+ messages: list = []) -> T3nsorResponse:
print('t3nsor api is down, this may not work, refer to another module')
- response = post('https://www.t3nsor.tech/api/chat', headers = headers, stream = True, json = Completion.model | {
- 'messages' : messages,
- 'key' : '',
- 'prompt' : prompt
+ response = post('https://www.t3nsor.tech/api/chat', headers=headers, stream=True, json=Completion.model | {
+ 'messages': messages,
+ 'key': '',
+ 'prompt': prompt
})
-
- for chunk in response.iter_content(chunk_size = 2046):
+
+ for chunk in response.iter_content(chunk_size=2046):
yield T3nsorResponse({
- 'id' : f'cmpl-1337-{int(time())}',
- 'object' : 'text_completion',
- 'created': int(time()),
- 'model' : Completion.model,
-
+ 'id': f'cmpl-1337-{int(time())}',
+ 'object': 'text_completion',
+ 'created': int(time()),
+ 'model': Completion.model,
+
'choices': [{
- 'text' : chunk.decode(),
- 'index' : 0,
- 'logprobs' : None,
- 'finish_reason' : 'stop'
+ '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())
+ 'prompt_chars': len(prompt),
+ 'completion_chars': len(chunk.decode()),
+ 'total_chars': len(prompt) + len(chunk.decode())
}
})