Update codegeex.py

This commit is contained in:
Shaobo 2024-07-15 21:24:38 +08:00 committed by GitHub
parent 38342ab02b
commit 7c3cbf6b33
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -39,11 +39,14 @@ class CodegeexChatModel:
"max_new_tokens": request.max_tokens, "max_new_tokens": request.max_tokens,
"temperature": request.temperature, "temperature": request.temperature,
"top_p": request.top_p, "top_p": request.top_p,
"repetition_penalty": request.presence_penalty "repetition_penalty": request.presence_penalty,
"do_sample": True if request.temperature else request.temperature,
} }
length = 0 length = 0
for i, outputs in enumerate(self.model.stream_generate(**inputs, **gen_configs)): for i, outputs in enumerate(self.model.stream_generate(**inputs, **gen_configs)):
response = self.tokenizer.decode(outputs.tolist()[0][len(inputs["input_ids"][0]):-1]) response = self.tokenizer.decode(outputs.tolist()[0][len(inputs["input_ids"][0]):-1])
if not response or response[-1] == "<EFBFBD>":
continue
resp = ChatCompletionStreamResponse() resp = ChatCompletionStreamResponse()
resp.choices[0].index = i resp.choices[0].index = i
resp.choices[0].delta.content = response[length:] resp.choices[0].delta.content = response[length:]