release initial code
Co-authored-by: Ying Sheng <sqy1415@gmail.com> Co-authored-by: Liangsheng Yin <hnyls2002@gmail.com> Co-authored-by: Zhiqiang Xie <xiezhq@stanford.edu> Co-authored-by: parasol-aser <3848358+parasol-aser@users.noreply.github.com> Co-authored-by: LiviaSun <33578456+ChuyueSun@users.noreply.github.com> Co-authored-by: Cody Yu <hao.yu.cody@gmail.com>
This commit is contained in:
26
examples/quick_start/srt_example_stream.py
Normal file
26
examples/quick_start/srt_example_stream.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from sglang import function, system, user, assistant, gen, set_default_backend, Runtime
|
||||
|
||||
|
||||
@function
|
||||
def multi_turn_question(s, question_1, question_2):
|
||||
s += system("You are a helpful assistant.")
|
||||
s += user(question_1)
|
||||
s += assistant(gen("answer_1", max_tokens=256))
|
||||
s += user(question_2)
|
||||
s += assistant(gen("answer_2", max_tokens=256))
|
||||
|
||||
runtime = Runtime("meta-llama/Llama-2-7b-chat-hf")
|
||||
set_default_backend(runtime)
|
||||
|
||||
state = multi_turn_question.run(
|
||||
question_1="What is the capital of the United States?",
|
||||
question_2="List two local attractions.",
|
||||
temperature=0,
|
||||
stream=True,
|
||||
)
|
||||
|
||||
for out in state.text_iter():
|
||||
print(out, end="", flush=True)
|
||||
print()
|
||||
|
||||
runtime.shutdown()
|
||||
Reference in New Issue
Block a user