Skip to content

Commit

Permalink
fix tk_count undefine issue (#996)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?


### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
  • Loading branch information
KevinHuSh committed May 30, 2024
1 parent 77363a0 commit 117a173
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions rag/llm/chat_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def chat_streamly(self, system, history, gen_conf):
if system:
history.insert(0, {"role": "system", "content": system})
ans = ""
tk_count = 0
try:
response = Generation.call(
self.model_name,
Expand All @@ -214,7 +215,6 @@ def chat_streamly(self, system, history, gen_conf):
stream=True,
**gen_conf
)
tk_count = 0
for resp in response:
if resp.status_code == HTTPStatus.OK:
ans = resp.output.choices[0]['message']['content']
Expand Down Expand Up @@ -261,14 +261,14 @@ def chat_streamly(self, system, history, gen_conf):
if "presence_penalty" in gen_conf: del gen_conf["presence_penalty"]
if "frequency_penalty" in gen_conf: del gen_conf["frequency_penalty"]
ans = ""
tk_count = 0
try:
response = self.client.chat.completions.create(
model=self.model_name,
messages=history,
stream=True,
**gen_conf
)
tk_count = 0
for resp in response:
if not resp.choices[0].delta.content:continue
delta = resp.choices[0].delta.content
Expand Down Expand Up @@ -439,6 +439,7 @@ def chat_streamly(self, system, history, gen_conf):
if system:
history.insert(0, {"role": "system", "content": system})
ans = ""
tk_count = 0
try:
req = {
"parameters": {
Expand Down

0 comments on commit 117a173

Please sign in to comment.