Update messagers/message_outputer.py
Browse files
messagers/message_outputer.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import json
|
2 |
-
import time
|
3 |
|
4 |
|
5 |
class OpenaiStreamOutputer:
|
@@ -7,22 +7,16 @@ class OpenaiStreamOutputer:
|
|
7 |
Create chat completion - OpenAI API Documentation
|
8 |
* https://platform.openai.com/docs/api-reference/chat/create
|
9 |
"""
|
10 |
-
|
11 |
|
12 |
def __init__(self):
|
13 |
-
current_time = int(time.time())
|
14 |
self.default_data = {
|
|
|
15 |
"id": "chatcmpl-hugginface",
|
16 |
"object": "chat.completion.chunk",
|
17 |
-
"created": current_time,
|
18 |
# "content_type": "Completions",
|
19 |
"model": "hugginface",
|
20 |
"choices": [],
|
21 |
-
"usage": {
|
22 |
-
"prompt_tokens": 0,
|
23 |
-
"completion_tokens": 0,
|
24 |
-
"total_tokens": 0
|
25 |
-
}
|
26 |
}
|
27 |
|
28 |
def data_to_string(self, data={}, content_type=""):
|
@@ -70,10 +64,4 @@ class OpenaiStreamOutputer:
|
|
70 |
"finish_reason": None,
|
71 |
}
|
72 |
]
|
73 |
-
|
74 |
-
data["usage"]["prompt_tokens"] += tokens_count
|
75 |
-
data["usage"]["completion_tokens"] += len(content.split())
|
76 |
-
data["usage"]["total_tokens"] = data["usage"]["prompt_tokens"] + data["usage"]["completion_tokens"]
|
77 |
-
|
78 |
-
return self.data_to_string(data, content_type)
|
79 |
-
|
|
|
1 |
import json
|
2 |
+
import time
|
3 |
|
4 |
|
5 |
class OpenaiStreamOutputer:
|
|
|
7 |
Create chat completion - OpenAI API Documentation
|
8 |
* https://platform.openai.com/docs/api-reference/chat/create
|
9 |
"""
|
|
|
10 |
|
11 |
def __init__(self):
|
12 |
+
current_time = int(time.time())
|
13 |
self.default_data = {
|
14 |
+
"created": current_time,
|
15 |
"id": "chatcmpl-hugginface",
|
16 |
"object": "chat.completion.chunk",
|
|
|
17 |
# "content_type": "Completions",
|
18 |
"model": "hugginface",
|
19 |
"choices": [],
|
|
|
|
|
|
|
|
|
|
|
20 |
}
|
21 |
|
22 |
def data_to_string(self, data={}, content_type=""):
|
|
|
64 |
"finish_reason": None,
|
65 |
}
|
66 |
]
|
67 |
+
return self.data_to_string(data, content_type)
|
|
|
|
|
|
|
|
|
|
|
|