Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
zhaoyu6
sglang
Commits
e57f0792
"official/modeling/fast_training/progressive/trainer.py" did not exist on "86df41f7b3c192187058f8d6fc8170a57634b9f9"
Unverified
Commit
e57f0792
authored
Mar 22, 2024
by
Jani Monoses
Committed by
GitHub
Mar 22, 2024
Browse files
Use Anthropic messages API (#304)
parent
08df63a6
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
24 additions
and
18 deletions
+24
-18
examples/quick_start/anthropic_example_chat.py
examples/quick_start/anthropic_example_chat.py
+1
-1
examples/quick_start/anthropic_example_complete.py
examples/quick_start/anthropic_example_complete.py
+2
-2
python/pyproject.toml
python/pyproject.toml
+1
-1
python/sglang/backend/anthropic.py
python/sglang/backend/anthropic.py
+18
-12
python/sglang/lang/ir.py
python/sglang/lang/ir.py
+1
-1
test/lang/test_anthropic_backend.py
test/lang/test_anthropic_backend.py
+1
-1
No files found.
examples/quick_start/anthropic_example_chat.py
View file @
e57f0792
...
...
@@ -52,7 +52,7 @@ def batch():
if
__name__
==
"__main__"
:
sgl
.
set_default_backend
(
sgl
.
Anthropic
(
"claude-
2
"
))
sgl
.
set_default_backend
(
sgl
.
Anthropic
(
"claude-
3-haiku-20240307
"
))
# Run a single request
print
(
"
\n
========== single ==========
\n
"
)
...
...
examples/quick_start/anthropic_example_complete.py
View file @
e57f0792
...
...
@@ -19,7 +19,7 @@ def few_shot_qa(s, question):
\n\n
Assistant: Rome
"""
)
s
+=
"
\n\n
Human: "
+
question
+
"
\n
"
s
+=
"
\n\n
Assistant:"
+
sgl
.
gen
(
"answer"
,
stop
=
"
\n
"
,
temperature
=
0
)
s
+=
"
\n\n
Assistant:"
+
sgl
.
gen
(
"answer"
,
stop
=
"
\
\
n"
,
temperature
=
0
)
def
single
():
...
...
@@ -52,7 +52,7 @@ def batch():
if
__name__
==
"__main__"
:
sgl
.
set_default_backend
(
sgl
.
Anthropic
(
"claude-
2
"
))
sgl
.
set_default_backend
(
sgl
.
Anthropic
(
"claude-
3-haiku-20240307
"
))
# Run a single request
print
(
"
\n
========== single ==========
\n
"
)
...
...
python/pyproject.toml
View file @
e57f0792
...
...
@@ -22,7 +22,7 @@ srt = ["aiohttp", "fastapi", "psutil", "rpyc", "torch", "uvloop", "uvicorn",
"zmq"
,
"vllm>=0.3.3"
,
"interegular"
,
"lark"
,
"numba"
,
"pydantic"
,
"referencing"
,
"diskcache"
,
"cloudpickle"
,
"pillow"
,
"outlines>=0.0.27"
]
openai
=
[
"openai>=1.0"
,
"numpy"
]
anthropic
=
[
"anthropic"
,
"numpy"
]
anthropic
=
[
"anthropic
>=0.20.0
"
,
"numpy"
]
all
=
["sglang[srt]
", "
sglang
[openai]
", "
sglang
[anthropic]"]
[project.urls]
...
...
python/sglang/backend/anthropic.py
View file @
e57f0792
...
...
@@ -30,13 +30,17 @@ class Anthropic(BaseBackend):
s
:
StreamExecutor
,
sampling_params
:
SglSamplingParams
,
):
prompt
=
s
.
text_
ret
=
anthropic
.
Anthropic
().
completions
.
create
(
if
s
.
messages_
:
messages
=
s
.
messages_
else
:
messages
=
[{
"role"
:
"user"
,
"content"
:
s
.
text_
}]
ret
=
anthropic
.
Anthropic
().
messages
.
create
(
model
=
self
.
model_name
,
prompt
=
prompt
,
messages
=
messages
,
**
sampling_params
.
to_anthropic_kwargs
(),
)
comp
=
ret
.
co
mpletion
comp
=
ret
.
co
ntent
[
0
].
text
return
comp
,
{}
...
...
@@ -45,13 +49,15 @@ class Anthropic(BaseBackend):
s
:
StreamExecutor
,
sampling_params
:
SglSamplingParams
,
):
prompt
=
s
.
text_
generator
=
anthropic
.
Anthropic
().
completions
.
create
(
if
s
.
messages_
:
messages
=
s
.
messages_
else
:
messages
=
[{
"role"
:
"user"
,
"content"
:
s
.
text_
}]
with
anthropic
.
Anthropic
().
messages
.
stream
(
model
=
self
.
model_name
,
prompt
=
prompt
,
stream
=
True
,
messages
=
messages
,
**
sampling_params
.
to_anthropic_kwargs
(),
)
for
ret
in
generator
:
yield
ret
.
completion
,
{}
)
as
stream
:
for
text
in
stream
.
text_stream
:
yield
text
,
{}
python/sglang/lang/ir.py
View file @
e57f0792
...
...
@@ -73,7 +73,7 @@ class SglSamplingParams:
"Regular expression is not supported in the Anthropic backend."
)
return
{
"max_tokens
_to_sample
"
:
self
.
max_new_tokens
,
"max_tokens"
:
self
.
max_new_tokens
,
"stop_sequences"
:
(
self
.
stop
if
isinstance
(
self
.
stop
,
(
list
,
tuple
))
else
[
self
.
stop
]
),
...
...
test/lang/test_anthropic_backend.py
View file @
e57f0792
...
...
@@ -14,7 +14,7 @@ class TestAnthropicBackend(unittest.TestCase):
cls
=
type
(
self
)
if
cls
.
backend
is
None
:
cls
.
backend
=
Anthropic
(
"claude-
2
"
)
cls
.
backend
=
Anthropic
(
"claude-
3-haiku-20240307
"
)
set_default_backend
(
cls
.
backend
)
def
test_mt_bench
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment