srt_example_llava.py 661 Bytes
Newer Older
Lianmin Zheng's avatar
Lianmin Zheng committed
1
2
3
4
5
6
7
8
9
import sglang as sgl


@sgl.function
def image_qa(s, image_path, question):
    s += sgl.user(sgl.image(image_path) + question)
    s += sgl.assistant(sgl.gen("answer"))


shiyi.c_98's avatar
shiyi.c_98 committed
10
11
12
13
# runtime = sgl.Runtime(model_path="liuhaotian/llava-v1.5-7b",
#                       tokenizer_path="llava-hf/llava-1.5-7b-hf")
runtime = sgl.Runtime(model_path="llava-internal/llava-v1.6-7b-hd-224px_3x2-preview-20230103",
                      tokenizer_path="llava-internal/llava-v1.6-7b-hd-224px_3x2-preview-20230103-tokenizer")
Lianmin Zheng's avatar
Lianmin Zheng committed
14
15
16
17
18
19
20
sgl.set_default_backend(runtime)


state = image_qa.run(image_path="images/cat.jpeg", question="What is this?")
print(state["answer"])

runtime.shutdown()