diff options
author | t.me/xtekky <98614666+xtekky@users.noreply.github.com> | 2023-04-06 21:29:56 +0200 |
---|---|---|
committer | t.me/xtekky <98614666+xtekky@users.noreply.github.com> | 2023-04-06 21:29:56 +0200 |
commit | ab75098dd21eb9cf4024d67ddcfaac01f946ea9f (patch) | |
tree | 374ed252ab858cac831d358567dc77e374f0749c | |
parent | updated poe api (gpt4) (diff) | |
download | gpt4free-ab75098dd21eb9cf4024d67ddcfaac01f946ea9f.tar gpt4free-ab75098dd21eb9cf4024d67ddcfaac01f946ea9f.tar.gz gpt4free-ab75098dd21eb9cf4024d67ddcfaac01f946ea9f.tar.bz2 gpt4free-ab75098dd21eb9cf4024d67ddcfaac01f946ea9f.tar.lz gpt4free-ab75098dd21eb9cf4024d67ddcfaac01f946ea9f.tar.xz gpt4free-ab75098dd21eb9cf4024d67ddcfaac01f946ea9f.tar.zst gpt4free-ab75098dd21eb9cf4024d67ddcfaac01f946ea9f.zip |
-rw-r--r-- | t3nsor/__init__.py | 47 | ||||
-rw-r--r-- | testing/t3nsor.py | 7 |
2 files changed, 30 insertions, 24 deletions
diff --git a/t3nsor/__init__.py b/t3nsor/__init__.py index 5cd12608..9079f9d9 100644 --- a/t3nsor/__init__.py +++ b/t3nsor/__init__.py @@ -21,9 +21,9 @@ class T3nsorResponse: class Usage: def __init__(self, usage_dict: dict) -> None: - self.prompt_tokens = usage_dict['prompt_tokens'] - self.completion_tokens = usage_dict['completion_tokens'] - self.total_tokens = usage_dict['total_tokens'] + 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>''' @@ -95,24 +95,23 @@ class StreamCompletion: 'prompt' : prompt }) - for resp in response.iter_lines(): - if resp: - yield T3nsorResponse({ - 'id' : f'cmpl-1337-{int(time())}', - 'object' : 'text_completion', - 'created': int(time()), - 'model' : Completion.model, - - 'choices': [{ - 'text' : resp.decode(), - 'index' : 0, - 'logprobs' : None, - 'finish_reason' : 'stop' - }], - - 'usage': { - 'prompt_chars' : len(prompt), - 'completion_chars' : len(resp.decode()), - 'total_chars' : len(prompt) + len(resp.decode()) - } - })
\ No newline at end of file + 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, + + '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()) + } + })
\ No newline at end of file diff --git a/testing/t3nsor.py b/testing/t3nsor.py new file mode 100644 index 00000000..38e047b9 --- /dev/null +++ b/testing/t3nsor.py @@ -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)
\ No newline at end of file |