Unverified Commit 2b6d9991 authored by Fronx's avatar Fronx Committed by GitHub
Browse files

Fix issue #367 – System message not supported for Anthropic (anthropic.BadRequestError) (#368)


Co-authored-by: default avatarYing Sheng <sqy1415@gmail.com>
parent 65501a9c
......@@ -35,8 +35,14 @@ class Anthropic(BaseBackend):
else:
messages = [{"role": "user", "content": s.text_}]
if messages and messages[0]["role"] == "system":
system = messages.pop(0)["content"]
else:
system = ""
ret = anthropic.Anthropic().messages.create(
model=self.model_name,
system=system,
messages=messages,
**sampling_params.to_anthropic_kwargs(),
)
......@@ -54,8 +60,14 @@ class Anthropic(BaseBackend):
else:
messages = [{"role": "user", "content": s.text_}]
if messages and messages[0]["role"] == "system":
system = messages.pop(0)["content"]
else:
system = ""
with anthropic.Anthropic().messages.stream(
model=self.model_name,
system=system,
messages=messages,
**sampling_params.to_anthropic_kwargs(),
) as stream:
......
......@@ -313,6 +313,7 @@ def test_image_qa():
def test_stream():
@sgl.function
def qa(s, question):
s += sgl.system("You are a helpful assistant.")
s += sgl.user(question)
s += sgl.assistant(sgl.gen("answer"))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment