-
Notifications
You must be signed in to change notification settings - Fork 588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System message not supported for Anthropic (anthropic.BadRequestError) #367
Comments
Here is how Anthropic system messages are supposed to be provided (source: https://docs.anthropic.com/claude/docs/system-prompts): client = anthropic.Client(api_key="YOUR_API_KEY")
response = client.messages.create(
model="claude-2.1",
system="Respond only in Spanish.", # <-- system prompt
messages=[
{"role": "user", "content": "Hello, Claude!"} # <-- user prompt
]
) And here is what the current sglang implementation does: # …
if s.messages_:
messages = s.messages_
else:
messages = [{"role": "user", "content": s.text_}]
ret = anthropic.Anthropic().messages.create(
model=self.model_name,
messages=messages,
**sampling_params.to_anthropic_kwargs(),
)
# … So there is currently no way of converting a system message into a system parameter. |
Would the following be an acceptable fix? # …
if s.messages_:
messages = s.messages_
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(),
)
# … If I can figure out how to set things up on my machine so I can run tests for this repo, I could contribute a fix. |
…c.BadRequestError) (#368) Co-authored-by: Ying Sheng <sqy1415@gmail.com>
Using the
system
role with the Anthropic backend results in the following error:Is there a known workaround? I've tried using a
user
message instead, but occasionally that causes confusion for Haiku.The text was updated successfully, but these errors were encountered: