File size: 2,087 Bytes
52da7b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from __future__ import annotations

import json
import sys
from pathlib import Path

REPO_ROOT = Path(__file__).resolve().parents[1]
if str(REPO_ROOT) not in sys.path:
    sys.path.insert(0, str(REPO_ROOT))

from reframr.cli import compose_generation_context
from reframr.model import ReframrModel


def main() -> None:
    model = ReframrModel.load(REPO_ROOT / "model.safetensors")

    messages = [
        {
            "role": "system",
            "content": (
                "Answer from tool evidence when it is provided. "
                "If the question needs fresh information and no source is available, say what is missing."
            ),
        },
        {
            "role": "user",
            "content": "Who won the Rivergate mayoral runoff, and what number should I cite?",
        },
        {
            "role": "assistant",
            "tool_calls": [
                {
                    "id": "call_1",
                    "type": "function",
                    "function": {
                        "name": "web.search",
                        "arguments": json.dumps({"query": "Rivergate mayoral runoff result vote share"}),
                    },
                }
            ],
        },
        {
            "role": "tool",
            "tool_call_id": "call_1",
            "name": "web.search",
            "content": json.dumps(
                {
                    "ok": True,
                    "source": {
                        "title": "Local Civic Wire",
                        "url": "https://example.org/rivergate-runoff",
                        "snippet": "Mara Ibekwe won the Rivergate mayoral runoff with 52.4 percent of the vote.",
                    },
                }
            ),
        },
    ]

    context = compose_generation_context("", messages=messages)
    print(
        model.generate_text(
            context,
            max_tokens=90,
            temperature=0.58,
            top_k=64,
            top_p=0.92,
            repetition_penalty=1.25,
        )
    )


if __name__ == "__main__":
    main()