Kevin Hu
commited on
Commit
·
2646b91
1
Parent(s):
76ea913
fix: Anthropic param error (#3327)
Browse files### What problem does this PR solve?
#3263
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
- rag/llm/chat_model.py +7 -3
rag/llm/chat_model.py
CHANGED
@@ -1249,6 +1249,8 @@ class AnthropicChat(Base):
|
|
1249 |
self.system = system
|
1250 |
if "max_tokens" not in gen_conf:
|
1251 |
gen_conf["max_tokens"] = 4096
|
|
|
|
|
1252 |
|
1253 |
ans = ""
|
1254 |
try:
|
@@ -1278,6 +1280,8 @@ class AnthropicChat(Base):
|
|
1278 |
self.system = system
|
1279 |
if "max_tokens" not in gen_conf:
|
1280 |
gen_conf["max_tokens"] = 4096
|
|
|
|
|
1281 |
|
1282 |
ans = ""
|
1283 |
total_tokens = 0
|
@@ -1290,11 +1294,11 @@ class AnthropicChat(Base):
|
|
1290 |
**gen_conf,
|
1291 |
)
|
1292 |
for res in response.iter_lines():
|
1293 |
-
res
|
1294 |
-
|
1295 |
-
text = json.loads(res[6:])["delta"]["text"]
|
1296 |
ans += text
|
1297 |
total_tokens += num_tokens_from_string(text)
|
|
|
1298 |
except Exception as e:
|
1299 |
yield ans + "\n**ERROR**: " + str(e)
|
1300 |
|
|
|
1249 |
self.system = system
|
1250 |
if "max_tokens" not in gen_conf:
|
1251 |
gen_conf["max_tokens"] = 4096
|
1252 |
+
if "presence_penalty" in gen_conf: del gen_conf["presence_penalty"]
|
1253 |
+
if "frequency_penalty" in gen_conf: del gen_conf["frequency_penalty"]
|
1254 |
|
1255 |
ans = ""
|
1256 |
try:
|
|
|
1280 |
self.system = system
|
1281 |
if "max_tokens" not in gen_conf:
|
1282 |
gen_conf["max_tokens"] = 4096
|
1283 |
+
if "presence_penalty" in gen_conf: del gen_conf["presence_penalty"]
|
1284 |
+
if "frequency_penalty" in gen_conf: del gen_conf["frequency_penalty"]
|
1285 |
|
1286 |
ans = ""
|
1287 |
total_tokens = 0
|
|
|
1294 |
**gen_conf,
|
1295 |
)
|
1296 |
for res in response.iter_lines():
|
1297 |
+
if res.type == 'content_block_delta':
|
1298 |
+
text = res.delta.text
|
|
|
1299 |
ans += text
|
1300 |
total_tokens += num_tokens_from_string(text)
|
1301 |
+
yield ans
|
1302 |
except Exception as e:
|
1303 |
yield ans + "\n**ERROR**: " + str(e)
|
1304 |
|