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:
28
examples/quick_start/srt_example_complete.py
Normal file
28
examples/quick_start/srt_example_complete.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from sglang import function, gen, set_default_backend, Runtime
|
||||
|
||||
|
||||
@function
|
||||
def few_shot_qa(s, question):
|
||||
s += (
|
||||
"""The following are questions with answers.
|
||||
Q: What is the capital of France?
|
||||
A: Paris
|
||||
Q: What is the capital of Germany?
|
||||
A: Berlin
|
||||
Q: What is the capital of Italy?
|
||||
A: Rome
|
||||
""")
|
||||
s += "Q: " + question + "\n"
|
||||
s += "A:" + gen("answer", stop="\n", temperature=0)
|
||||
|
||||
|
||||
runtime = Runtime(model_path="meta-llama/Llama-2-7b-chat-hf")
|
||||
set_default_backend(runtime)
|
||||
|
||||
state = few_shot_qa.run(question="What is the capital of the United States?")
|
||||
|
||||
answer = state["answer"].strip().lower()
|
||||
assert "washington" in answer, f"answer: {state['answer']}"
|
||||
print(state.text())
|
||||
|
||||
runtime.shutdown()
|
||||
Reference in New Issue
Block a user