t.me/xtekky
commited on
Commit
•
ab75098
1
Parent(s):
76571f2
updated t3nsor (gpt 3.5)
Browse fileschanged iter lines to iter content chunks, way smoother and more updates + resolved dict issue
- t3nsor/__init__.py +23 -24
- testing/t3nsor.py +7 -0
t3nsor/__init__.py
CHANGED
@@ -21,9 +21,9 @@ class T3nsorResponse:
|
|
21 |
|
22 |
class Usage:
|
23 |
def __init__(self, usage_dict: dict) -> None:
|
24 |
-
self.prompt_tokens = usage_dict['
|
25 |
-
self.completion_tokens = usage_dict['
|
26 |
-
self.total_tokens = usage_dict['
|
27 |
|
28 |
def __repr__(self):
|
29 |
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>'''
|
@@ -95,24 +95,23 @@ class StreamCompletion:
|
|
95 |
'prompt' : prompt
|
96 |
})
|
97 |
|
98 |
-
for
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
'
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
})
|
|
|
21 |
|
22 |
class Usage:
|
23 |
def __init__(self, usage_dict: dict) -> None:
|
24 |
+
self.prompt_tokens = usage_dict['prompt_chars']
|
25 |
+
self.completion_tokens = usage_dict['completion_chars']
|
26 |
+
self.total_tokens = usage_dict['total_chars']
|
27 |
|
28 |
def __repr__(self):
|
29 |
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>'''
|
|
|
95 |
'prompt' : prompt
|
96 |
})
|
97 |
|
98 |
+
for chunk in response.iter_content(chunk_size = 2046):
|
99 |
+
yield T3nsorResponse({
|
100 |
+
'id' : f'cmpl-1337-{int(time())}',
|
101 |
+
'object' : 'text_completion',
|
102 |
+
'created': int(time()),
|
103 |
+
'model' : Completion.model,
|
104 |
+
|
105 |
+
'choices': [{
|
106 |
+
'text' : chunk.decode(),
|
107 |
+
'index' : 0,
|
108 |
+
'logprobs' : None,
|
109 |
+
'finish_reason' : 'stop'
|
110 |
+
}],
|
111 |
+
|
112 |
+
'usage': {
|
113 |
+
'prompt_chars' : len(prompt),
|
114 |
+
'completion_chars' : len(chunk.decode()),
|
115 |
+
'total_chars' : len(prompt) + len(chunk.decode())
|
116 |
+
}
|
117 |
+
})
|
|
testing/t3nsor.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import t3nsor
|
2 |
+
|
3 |
+
for response in t3nsor.StreamCompletion.create(
|
4 |
+
prompt = 'write python code to reverse a string',
|
5 |
+
messages = []):
|
6 |
+
|
7 |
+
print(response.completion.choices[0].text)
|