File size: 1,660 Bytes
be38993
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/python

import sys, os
from pprint import pprint
from jinja2 import Environment, FileSystemLoader, meta
import yaml


sys.path.append(".")
os.chdir(os.path.dirname(os.path.abspath(__file__)))


if __name__ == "__main__":

    with open('prompt_config.yaml') as f:
        config = yaml.safe_load(f)

    print("prompt format:", config.get("prompt_format"))
    print(config)
    print()
    for prompt in config["prompts"]:
        print(f'--- prompt mode: {prompt["mode"]} ---')
        env = Environment(loader=FileSystemLoader("."))
        template = env.get_template(prompt["template"])

        source = template.environment.loader.get_source(template.environment, template.name)
        variables = meta.find_undeclared_variables(env.parse(source[0]))

        print("variables:", variables)
        print("---")

        data = {
            "query": "Comment est votre blanquette ?",
            "chunks" : [
                {
                    "url": "http://data.gouv.fr",
                    "h": "hash49080805",
                    "title": "A chunk title",
                    "text": "text texs\ntext again ",
                },
                {
                    "url": "http://...",
                    "h": "hash49080806",
                    "title": "A chunk title",
                    "text": "text texs\ntext again ",
                    "context": "I > am > a > context"
                },

            ]
        }

        if "system_prompt" in variables:
            data["system_prompt"] = prompt["system_prompt"]

        rendered_template = template.render(**data)
        print(rendered_template)
        print("---")