updated t3nsor (gpt 3.5)
changed iter lines to iter content chunks, way smoother and more updates + resolved dict issue
This commit is contained in:
parent
76571f2591
commit
ab75098dd2
2 changed files with 30 additions and 24 deletions
|
@ -21,9 +21,9 @@ class T3nsorResponse:
|
||||||
|
|
||||||
class Usage:
|
class Usage:
|
||||||
def __init__(self, usage_dict: dict) -> None:
|
def __init__(self, usage_dict: dict) -> None:
|
||||||
self.prompt_tokens = usage_dict['prompt_tokens']
|
self.prompt_tokens = usage_dict['prompt_chars']
|
||||||
self.completion_tokens = usage_dict['completion_tokens']
|
self.completion_tokens = usage_dict['completion_chars']
|
||||||
self.total_tokens = usage_dict['total_tokens']
|
self.total_tokens = usage_dict['total_chars']
|
||||||
|
|
||||||
def __repr__(self):
|
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>'''
|
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,8 +95,7 @@ class StreamCompletion:
|
||||||
'prompt' : prompt
|
'prompt' : prompt
|
||||||
})
|
})
|
||||||
|
|
||||||
for resp in response.iter_lines():
|
for chunk in response.iter_content(chunk_size = 2046):
|
||||||
if resp:
|
|
||||||
yield T3nsorResponse({
|
yield T3nsorResponse({
|
||||||
'id' : f'cmpl-1337-{int(time())}',
|
'id' : f'cmpl-1337-{int(time())}',
|
||||||
'object' : 'text_completion',
|
'object' : 'text_completion',
|
||||||
|
@ -104,7 +103,7 @@ class StreamCompletion:
|
||||||
'model' : Completion.model,
|
'model' : Completion.model,
|
||||||
|
|
||||||
'choices': [{
|
'choices': [{
|
||||||
'text' : resp.decode(),
|
'text' : chunk.decode(),
|
||||||
'index' : 0,
|
'index' : 0,
|
||||||
'logprobs' : None,
|
'logprobs' : None,
|
||||||
'finish_reason' : 'stop'
|
'finish_reason' : 'stop'
|
||||||
|
@ -112,7 +111,7 @@ class StreamCompletion:
|
||||||
|
|
||||||
'usage': {
|
'usage': {
|
||||||
'prompt_chars' : len(prompt),
|
'prompt_chars' : len(prompt),
|
||||||
'completion_chars' : len(resp.decode()),
|
'completion_chars' : len(chunk.decode()),
|
||||||
'total_chars' : len(prompt) + len(resp.decode())
|
'total_chars' : len(prompt) + len(chunk.decode())
|
||||||
}
|
}
|
||||||
})
|
})
|
7
testing/t3nsor.py
Normal file
7
testing/t3nsor.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import t3nsor
|
||||||
|
|
||||||
|
for response in t3nsor.StreamCompletion.create(
|
||||||
|
prompt = 'write python code to reverse a string',
|
||||||
|
messages = []):
|
||||||
|
|
||||||
|
print(response.completion.choices[0].text)
|
Loading…
Reference in a new issue