"examples/runtime/vscode:/vscode.git/clone" did not exist on "357671e216d30e8e11afd4210624a71c11c12329"
gemini_example_complete.py 633 Bytes
Newer Older
1
from sglang import function, gen, set_default_backend, VertexAI
shiyi.c_98's avatar
shiyi.c_98 committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18


@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)


19
set_default_backend(VertexAI("gemini-pro"))
shiyi.c_98's avatar
shiyi.c_98 committed
20
21
22
23
24
25
26

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())