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
eabcf82a
Unverified
Commit
eabcf82a
authored
May 18, 2025
by
Yineng Zhang
Committed by
GitHub
May 18, 2025
Browse files
feat: add long context example (#6391)
parent
c47a51db
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
0 deletions
+36
-0
scripts/playground/long_context_example.py
scripts/playground/long_context_example.py
+36
-0
No files found.
scripts/playground/long_context_example.py
0 → 100644
View file @
eabcf82a
from
urllib.request
import
urlopen
from
openai
import
OpenAI
test_cases
=
{
"64k"
:
"https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-1M/test-data/64k.txt"
,
"200k"
:
"https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-1M/test-data/200k.txt"
,
"600k"
:
"https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-1M/test-data/600k.txt"
,
"1m"
:
"https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-1M/test-data/1m.txt"
,
}
client
=
OpenAI
(
api_key
=
"EMPTY"
,
base_url
=
"http://127.0.0.1:30000/v1"
)
for
name
,
url
in
test_cases
.
items
():
print
(
f
"
\n
==== Running test case:
{
name
}
===="
)
try
:
with
urlopen
(
url
,
timeout
=
10
)
as
response
:
prompt
=
response
.
read
().
decode
(
"utf-8"
)
except
Exception
as
e
:
print
(
f
"Failed to load prompt for
{
name
}
:
{
e
}
"
)
continue
try
:
response
=
client
.
chat
.
completions
.
create
(
model
=
"meta-llama/Llama-4-Scout-17B-16E-Instruct"
,
messages
=
[{
"role"
:
"user"
,
"content"
:
prompt
}],
stream
=
True
,
max_tokens
=
128
,
temperature
=
0
,
)
for
chunk
in
response
:
if
chunk
.
choices
and
chunk
.
choices
[
0
].
delta
.
content
is
not
None
:
print
(
chunk
.
choices
[
0
].
delta
.
content
,
end
=
""
,
flush
=
True
)
except
Exception
as
e
:
print
(
f
"
\n
Error during completion for
{
name
}
:
{
e
}
"
)
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