Skip to content

Commit

Permalink
fix: Anthropic param error (infiniflow#3327)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

infiniflow#3263

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
  • Loading branch information
KevinHuSh authored and jhaiq committed Nov 30, 2024
1 parent be3724f commit 122d710
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions rag/llm/chat_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,8 @@ def chat(self, system, history, gen_conf):
self.system = system
if "max_tokens" not in gen_conf:
gen_conf["max_tokens"] = 4096
if "presence_penalty" in gen_conf: del gen_conf["presence_penalty"]
if "frequency_penalty" in gen_conf: del gen_conf["frequency_penalty"]

ans = ""
try:
Expand Down Expand Up @@ -1278,6 +1280,8 @@ def chat_streamly(self, system, history, gen_conf):
self.system = system
if "max_tokens" not in gen_conf:
gen_conf["max_tokens"] = 4096
if "presence_penalty" in gen_conf: del gen_conf["presence_penalty"]
if "frequency_penalty" in gen_conf: del gen_conf["frequency_penalty"]

ans = ""
total_tokens = 0
Expand All @@ -1290,11 +1294,11 @@ def chat_streamly(self, system, history, gen_conf):
**gen_conf,
)
for res in response.iter_lines():
res = res.decode("utf-8")
if "content_block_delta" in res and "data" in res:
text = json.loads(res[6:])["delta"]["text"]
if res.type == 'content_block_delta':
text = res.delta.text
ans += text
total_tokens += num_tokens_from_string(text)
yield ans
except Exception as e:
yield ans + "\n**ERROR**: " + str(e)

Expand Down

0 comments on commit 122d710

Please sign in to comment.