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
change
sglang
Commits
5ff25cdf
Unverified
Commit
5ff25cdf
authored
Aug 26, 2024
by
yichuan~
Committed by
GitHub
Aug 26, 2024
Browse files
[Minor] add delete test and delete tmp file on ci server (#1227)
parent
2f1d9283
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
156 deletions
+8
-156
examples/frontend_language/usage/openai_parallel_sample.py
examples/frontend_language/usage/openai_parallel_sample.py
+0
-153
test/srt/test_openai_server.py
test/srt/test_openai_server.py
+8
-3
No files found.
examples/frontend_language/usage/openai_parallel_sample.py
deleted
100644 → 0
View file @
2f1d9283
import
openai
client
=
openai
.
Client
(
base_url
=
"http://127.0.0.1:30000/v1"
,
api_key
=
"EMPTY"
)
# Text completion
response
=
client
.
completions
.
create
(
model
=
"default"
,
prompt
=
"I am a robot and I want to study like humans. Now let's tell a story. Once upon a time, there was a little"
,
n
=
1
,
temperature
=
0.8
,
max_tokens
=
32
,
)
print
(
response
)
# Text completion
response
=
client
.
completions
.
create
(
model
=
"default"
,
prompt
=
"I am a robot and I want to study like humans. Now let's tell a story. Once upon a time, there was a little"
,
n
=
5
,
temperature
=
0.8
,
max_tokens
=
320
,
)
print
(
response
)
# Text completion
response
=
client
.
completions
.
create
(
model
=
"default"
,
prompt
=
"I am a robot and I want to study like humans. Now let's tell a story. Once upon a time, there was a little"
,
n
=
3
,
temperature
=
0.8
,
max_tokens
=
32
,
)
print
(
response
)
# Text completion
response
=
client
.
completions
.
create
(
model
=
"default"
,
prompt
=
[
"The name of the famous soccer player is"
],
n
=
1
,
temperature
=
0.8
,
max_tokens
=
128
,
)
print
(
response
)
# Text completion
response
=
client
.
completions
.
create
(
model
=
"default"
,
prompt
=
[
"The name of the famous soccer player is "
,
"The capital of US is"
],
n
=
1
,
temperature
=
0.8
,
max_tokens
=
32
,
)
print
(
response
)
# Text completion
response
=
client
.
completions
.
create
(
model
=
"default"
,
prompt
=
[
"The name of the famous soccer player is "
,
"The capital of US is"
],
n
=
3
,
temperature
=
0.8
,
max_tokens
=
32
,
)
print
(
response
)
response
=
client
.
completions
.
create
(
model
=
"default"
,
prompt
=
[
"prompt1: I am a robot and I want to learn like humans. Now let's begin a tale. Once upon a time, there was a small"
,
"prompt2: As a robot, my goal is to understand human learning. Let's start a story. In a faraway land, there lived a tiny"
,
"prompt3: Being a robot, I aspire to study like people. Let's share a story. Long ago, there was a little"
,
"prompt4: I am a robot aiming to learn like humans. Let's narrate a story. Once, in a distant kingdom, there was a young"
,
"prompt5: As a robot, I seek to learn in human ways. Let's tell a story. Once upon a time, in a small village, there was a young"
,
],
n
=
1
,
temperature
=
0.8
,
max_tokens
=
320
,
)
print
(
response
)
# Text completion
response
=
client
.
completions
.
create
(
model
=
"default"
,
prompt
=
[
"The capital of France is"
,
"The capital of Germany is"
,
"The capital of US is"
,
],
n
=
3
,
temperature
=
0.8
,
max_tokens
=
32
,
)
print
(
response
)
# Chat completion
response
=
client
.
chat
.
completions
.
create
(
model
=
"default"
,
messages
=
[
{
"role"
:
"system"
,
"content"
:
"You are a helpful AI assistant"
},
{
"role"
:
"user"
,
"content"
:
"List 3 countries and their capitals."
},
],
temperature
=
0.8
,
max_tokens
=
1
,
logprobs
=
True
,
top_logprobs
=
3
,
)
print
(
response
)
# Chat completion
response
=
client
.
chat
.
completions
.
create
(
model
=
"default"
,
messages
=
[
{
"role"
:
"system"
,
"content"
:
"You are a helpful AI assistant"
},
{
"role"
:
"user"
,
"content"
:
"List 3 countries and their capitals."
},
],
temperature
=
0.8
,
max_tokens
=
1
,
n
=
1
,
)
print
(
response
)
# Chat completion
response
=
client
.
chat
.
completions
.
create
(
model
=
"default"
,
messages
=
[
{
"role"
:
"system"
,
"content"
:
"You are a helpful AI assistant"
},
{
"role"
:
"user"
,
"content"
:
"List 3 countries and their capitals."
},
],
temperature
=
0.8
,
max_tokens
=
1
,
logprobs
=
True
,
top_logprobs
=
3
,
)
print
(
response
)
# Chat completion
response
=
client
.
chat
.
completions
.
create
(
model
=
"default"
,
messages
=
[
{
"role"
:
"system"
,
"content"
:
"You are a helpful AI assistant"
},
{
"role"
:
"user"
,
"content"
:
"List 3 countries and their capitals."
},
],
temperature
=
0.8
,
max_tokens
=
1
,
n
=
4
,
)
print
(
response
)
test/srt/test_openai_server.py
View file @
5ff25cdf
...
...
@@ -350,11 +350,11 @@ class TestOpenAIServer(unittest.TestCase):
completion_window
=
completion_window
,
)
return
batch_job
,
content
return
batch_job
,
content
,
uploaded_file
def
run_batch
(
self
,
mode
):
client
=
openai
.
Client
(
api_key
=
self
.
api_key
,
base_url
=
self
.
base_url
)
batch_job
,
content
=
self
.
_create_batch
(
mode
=
mode
,
client
=
client
)
batch_job
,
content
,
uploaded_file
=
self
.
_create_batch
(
mode
=
mode
,
client
=
client
)
while
batch_job
.
status
not
in
[
"completed"
,
"failed"
,
"cancelled"
]:
time
.
sleep
(
3
)
...
...
@@ -378,10 +378,13 @@ class TestOpenAIServer(unittest.TestCase):
if
line
.
strip
()
!=
""
]
assert
len
(
results
)
==
len
(
content
)
for
delete_fid
in
[
uploaded_file
.
id
,
result_file_id
]:
del_pesponse
=
client
.
files
.
delete
(
delete_fid
)
assert
del_pesponse
.
deleted
def
run_cancel_batch
(
self
,
mode
):
client
=
openai
.
Client
(
api_key
=
self
.
api_key
,
base_url
=
self
.
base_url
)
batch_job
,
_
=
self
.
_create_batch
(
mode
=
mode
,
client
=
client
)
batch_job
,
_
,
uploaded_file
=
self
.
_create_batch
(
mode
=
mode
,
client
=
client
)
assert
batch_job
.
status
not
in
[
"cancelling"
,
"cancelled"
]
...
...
@@ -396,6 +399,8 @@ class TestOpenAIServer(unittest.TestCase):
time
.
sleep
(
3
)
assert
batch_job
.
status
==
"cancelled"
del_response
=
client
.
files
.
delete
(
uploaded_file
.
id
)
assert
del_response
.
deleted
def
test_completion
(
self
):
for
echo
in
[
False
,
True
]:
...
...
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