XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/gpt4free

updated t3nsor (gpt 3.5)

changed iter lines to iter content chunks, way smoother and more updates + resolved dict issue

ab75098d
t.me/xtekky <98614666+xtekky@users.noreply.github.com>
提交于

代码差异

2 个文件 +30 -24
Modified t3nsor/__init__.py +23 -24
@@ -21,9 +21,9 @@ class T3nsorResponse:
21 21
22 22 class Usage:
23 23 def __init__(self, usage_dict: dict) -> None:
24 self.prompt_tokens = usage_dict['prompt_tokens']
25 self.completion_tokens = usage_dict['completion_tokens']
26 self.total_tokens = usage_dict['total_tokens']
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 27
28 28 def __repr__(self):
29 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 95 'prompt' : prompt
96 96 })
97 97
98 for resp in response.iter_lines():
99 if resp:
100 yield T3nsorResponse({
101 'id' : f'cmpl-1337-{int(time())}',
102 'object' : 'text_completion',
103 'created': int(time()),
104 'model' : Completion.model,
105
106 'choices': [{
107 'text' : resp.decode(),
108 'index' : 0,
109 'logprobs' : None,
110 'finish_reason' : 'stop'
111 }],
112
113 'usage': {
114 'prompt_chars' : len(prompt),
115 'completion_chars' : len(resp.decode()),
116 'total_chars' : len(prompt) + len(resp.decode())
117 }
118 })
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 })
Added testing/t3nsor.py +7 -0
@@ -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)