Co-authored-by: Ying Sheng <sqy1415@gmail.com>
This commit is contained in:
@@ -35,8 +35,14 @@ class Anthropic(BaseBackend):
|
|||||||
else:
|
else:
|
||||||
messages = [{"role": "user", "content": s.text_}]
|
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(
|
ret = anthropic.Anthropic().messages.create(
|
||||||
model=self.model_name,
|
model=self.model_name,
|
||||||
|
system=system,
|
||||||
messages=messages,
|
messages=messages,
|
||||||
**sampling_params.to_anthropic_kwargs(),
|
**sampling_params.to_anthropic_kwargs(),
|
||||||
)
|
)
|
||||||
@@ -54,8 +60,14 @@ class Anthropic(BaseBackend):
|
|||||||
else:
|
else:
|
||||||
messages = [{"role": "user", "content": s.text_}]
|
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(
|
with anthropic.Anthropic().messages.stream(
|
||||||
model=self.model_name,
|
model=self.model_name,
|
||||||
|
system=system,
|
||||||
messages=messages,
|
messages=messages,
|
||||||
**sampling_params.to_anthropic_kwargs(),
|
**sampling_params.to_anthropic_kwargs(),
|
||||||
) as stream:
|
) as stream:
|
||||||
|
|||||||
@@ -313,6 +313,7 @@ def test_image_qa():
|
|||||||
def test_stream():
|
def test_stream():
|
||||||
@sgl.function
|
@sgl.function
|
||||||
def qa(s, question):
|
def qa(s, question):
|
||||||
|
s += sgl.system("You are a helpful assistant.")
|
||||||
s += sgl.user(question)
|
s += sgl.user(question)
|
||||||
s += sgl.assistant(sgl.gen("answer"))
|
s += sgl.assistant(sgl.gen("answer"))
|
||||||
|
|
||||||
|
|||||||
0
test/__init__.py
Normal file
0
test/__init__.py
Normal file
Reference in New Issue
Block a user