黄腾 aopstudio commited on
Commit
b4d4127
·
1 Parent(s): 4a00dc8

fix MiniMax chat bug (#1733)

Browse files

### What problem does this PR solve?

#1717 fix MiniMax chat bug

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

Co-authored-by: Zhedong Cen <[email protected]>

Files changed (1) hide show
  1. rag/llm/chat_model.py +7 -4
rag/llm/chat_model.py CHANGED
@@ -564,12 +564,15 @@ class MiniMaxChat(Base):
564
  )
565
  for resp in response.text.split("\n\n")[:-1]:
566
  resp = json.loads(resp[6:])
567
- if "delta" in resp["choices"][0]:
 
568
  text = resp["choices"][0]["delta"]["content"]
569
- else:
570
- continue
571
  ans += text
572
- total_tokens += num_tokens_from_string(text)
 
 
 
 
573
  yield ans
574
 
575
  except Exception as e:
 
564
  )
565
  for resp in response.text.split("\n\n")[:-1]:
566
  resp = json.loads(resp[6:])
567
+ text = ""
568
+ if "choices" in resp and "delta" in resp["choices"][0]:
569
  text = resp["choices"][0]["delta"]["content"]
 
 
570
  ans += text
571
+ total_tokens = (
572
+ total_tokens + num_tokens_from_string(text)
573
+ if "usage" not in resp
574
+ else resp["usage"]["total_tokens"]
575
+ )
576
  yield ans
577
 
578
  except Exception as e: