srt_example_regex.py 503 Bytes
Newer Older
Lianmin Zheng's avatar
Lianmin Zheng committed
1
2
3
from sglang import function, gen, set_default_backend, Runtime


4
5
6
IP_ADDR_REGEX = r"((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)"


Lianmin Zheng's avatar
Lianmin Zheng committed
7
8
9
10
11
12
@function
def regex_gen(s):
    s += "Q: What is the IP address of the Google DNS servers?\n"
    s += "A: " + gen(
        "answer",
        temperature=0,
13
        regex=IP_ADDR_REGEX,
Lianmin Zheng's avatar
Lianmin Zheng committed
14
15
16
17
18
19
20
21
22
23
24
    )


runtime = Runtime(model_path="meta-llama/Llama-2-7b-chat-hf")
set_default_backend(runtime)

state = regex_gen.run()

print(state.text())

runtime.shutdown()