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>
27 lines
672 B
Python
27 lines
672 B
Python
from sglang import function, gen, set_default_backend, Anthropic
|
|
|
|
|
|
@function
|
|
def few_shot_qa(s, question):
|
|
s += (
|
|
"""
|
|
\n\nHuman: What is the capital of France?
|
|
\n\nAssistant: Paris
|
|
\n\nHuman: What is the capital of Germany?
|
|
\n\nAssistant: Berlin
|
|
\n\nHuman: What is the capital of Italy?
|
|
\n\nAssistant: Rome
|
|
""")
|
|
s += "\n\nHuman: " + question + "\n"
|
|
s += "\n\nAssistant:" + gen("answer", stop="\n", temperature=0)
|
|
|
|
|
|
set_default_backend(Anthropic("claude-2"))
|
|
|
|
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())
|