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
0a4f5f9b
"cmake/vscode:/vscode.git/clone" did not exist on "7ec78bb6d2ff5c9a54962d0f26befba0716bf71e"
Unverified
Commit
0a4f5f9b
authored
Aug 04, 2024
by
Ying Sheng
Committed by
GitHub
Aug 04, 2024
Browse files
Test regex in vision api (#926)
parent
3bc99e6f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
7 deletions
+54
-7
test/srt/test_openai_server.py
test/srt/test_openai_server.py
+4
-3
test/srt/test_vision_openai_server.py
test/srt/test_vision_openai_server.py
+50
-4
No files found.
test/srt/test_openai_server.py
View file @
0a4f5f9b
...
@@ -139,10 +139,12 @@ class TestOpenAIServer(unittest.TestCase):
...
@@ -139,10 +139,12 @@ class TestOpenAIServer(unittest.TestCase):
model
=
self
.
model
,
model
=
self
.
model
,
messages
=
[
messages
=
[
{
"role"
:
"system"
,
"content"
:
"You are a helpful AI assistant"
},
{
"role"
:
"system"
,
"content"
:
"You are a helpful AI assistant"
},
{
"role"
:
"user"
,
"content"
:
"What is the capital of France?"
},
{
"role"
:
"user"
,
"content"
:
"What is the capital of France? Answer in a few words."
,
},
],
],
temperature
=
0
,
temperature
=
0
,
max_tokens
=
32
,
logprobs
=
logprobs
is
not
None
and
logprobs
>
0
,
logprobs
=
logprobs
is
not
None
and
logprobs
>
0
,
top_logprobs
=
logprobs
,
top_logprobs
=
logprobs
,
n
=
parallel_sample_num
,
n
=
parallel_sample_num
,
...
@@ -178,7 +180,6 @@ class TestOpenAIServer(unittest.TestCase):
...
@@ -178,7 +180,6 @@ class TestOpenAIServer(unittest.TestCase):
{
"role"
:
"user"
,
"content"
:
"What is the capital of France?"
},
{
"role"
:
"user"
,
"content"
:
"What is the capital of France?"
},
],
],
temperature
=
0
,
temperature
=
0
,
max_tokens
=
32
,
logprobs
=
logprobs
is
not
None
and
logprobs
>
0
,
logprobs
=
logprobs
is
not
None
and
logprobs
>
0
,
top_logprobs
=
logprobs
,
top_logprobs
=
logprobs
,
stream
=
True
,
stream
=
True
,
...
...
test/srt/test_vision_openai_server.py
View file @
0a4f5f9b
...
@@ -46,25 +46,71 @@ class TestOpenAIVisionServer(unittest.TestCase):
...
@@ -46,25 +46,71 @@ class TestOpenAIVisionServer(unittest.TestCase):
{
{
"type"
:
"image_url"
,
"type"
:
"image_url"
,
"image_url"
:
{
"image_url"
:
{
"url"
:
"https://github.com/sgl-project/sglang/blob/main/
assets/logo
.png?raw=true"
"url"
:
"https://github.com/sgl-project/sglang/blob/main/
test/lang/example_image
.png?raw=true"
},
},
},
},
{
"type"
:
"text"
,
"text"
:
"Describe this image"
},
{
"type"
:
"text"
,
"text"
:
"Describe this image in a very short sentence."
,
},
],
],
},
},
],
],
temperature
=
0
,
temperature
=
0
,
max_tokens
=
32
,
)
)
assert
response
.
choices
[
0
].
message
.
role
==
"assistant"
assert
response
.
choices
[
0
].
message
.
role
==
"assistant"
assert
isinstance
(
response
.
choices
[
0
].
message
.
content
,
str
)
text
=
response
.
choices
[
0
].
message
.
content
assert
isinstance
(
text
,
str
)
assert
"car"
in
text
or
"taxi"
in
text
,
text
assert
response
.
id
assert
response
.
id
assert
response
.
created
assert
response
.
created
assert
response
.
usage
.
prompt_tokens
>
0
assert
response
.
usage
.
prompt_tokens
>
0
assert
response
.
usage
.
completion_tokens
>
0
assert
response
.
usage
.
completion_tokens
>
0
assert
response
.
usage
.
total_tokens
>
0
assert
response
.
usage
.
total_tokens
>
0
def
test_regex
(
self
):
client
=
openai
.
Client
(
api_key
=
self
.
api_key
,
base_url
=
self
.
base_url
)
regex
=
(
r
"""\{\n"""
+
r
""" "color": "[\w]+",\n"""
+
r
""" "number_of_cars": [\d]+\n"""
+
r
"""\}"""
)
response
=
client
.
chat
.
completions
.
create
(
model
=
"default"
,
messages
=
[
{
"role"
:
"user"
,
"content"
:
[
{
"type"
:
"image_url"
,
"image_url"
:
{
"url"
:
"https://github.com/sgl-project/sglang/blob/main/test/lang/example_image.png?raw=true"
},
},
{
"type"
:
"text"
,
"text"
:
"Describe this image in the JSON format."
,
},
],
},
],
temperature
=
0
,
extra_body
=
{
"regex"
:
regex
},
)
text
=
response
.
choices
[
0
].
message
.
content
try
:
js_obj
=
json
.
loads
(
text
)
except
(
TypeError
,
json
.
decoder
.
JSONDecodeError
):
print
(
"JSONDecodeError"
,
text
)
raise
assert
isinstance
(
js_obj
[
"color"
],
str
)
assert
isinstance
(
js_obj
[
"number_of_cars"
],
int
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
(
warnings
=
"ignore"
)
unittest
.
main
(
warnings
=
"ignore"
)
...
...
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