gemini_example_stream.py 570 Bytes
Newer Older
1
from sglang import function, user, assistant, gen, set_default_backend, VertexAI
shiyi.c_98's avatar
shiyi.c_98 committed
2
3
4
5
6
7
8
9
10


@function
def multi_turn_question(s, question_1, question_2):
    s += user(question_1)
    s += assistant(gen("answer_1", max_tokens=256))
    s += user(question_2)
    s += assistant(gen("answer_2", max_tokens=256))

11
set_default_backend(VertexAI("gemini-pro"))
shiyi.c_98's avatar
shiyi.c_98 committed
12
13
14
15
16
17
18
19
20

state = multi_turn_question.run(
    question_1="What is the capital of the United States?",
    question_2="List two local attractions.",
    stream=True
)

for out in state.text_iter():
    print(out, end="", flush=True)