Skip to content

Commit

Permalink
feat: dont record blank tokens that come before first non-blank
Browse files Browse the repository at this point in the history
  • Loading branch information
sjmonson committed Sep 27, 2024
1 parent 3e5ff9b commit 74380e2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions plugins/openai_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def streaming_request_http(self, query: dict, user_id: int, test_end_time: float
# Iterate through all responses
tokens = []
prev_time = 0
first_token_seen = False
for resp in resps:
message = self._process_resp(resp['data'])
if not message:
Expand All @@ -269,18 +270,20 @@ def streaming_request_http(self, query: dict, user_id: int, test_end_time: float
logger.error("Error received in response message: %s", result.error_text)

token = {}
token['time'] = resp['time']
token['lat'] = token['time'] - prev_time
prev_time = token['time']

if self.api == 'chat':
token["text"] = deepget(message, "choices", 0, 'delta', 'content')
else: # self.api == 'legacy'
token["text"] = deepget(message, "choices", 0, 'text')

# Skip blank tokens
if not token['text']:
# Skip blank tokens before first non-blank
if not first_token_seen and not token['text']:
continue
first_token_seen = True

token['time'] = resp['time']
token['lat'] = token['time'] - prev_time
prev_time = token['time']

# Append our vaild token
tokens.append(token)
Expand Down

0 comments on commit 74380e2

Please sign in to comment.