File size: 1,883 Bytes
2b28792
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Forced-tool example for a running Donto-Qwen vLLM endpoint."""

from typing import Union

from openai import OpenAI
from pydantic import BaseModel, ConfigDict, Field


class Fact(BaseModel):
    model_config = ConfigDict(extra="forbid")

    s: str
    p: str
    o: Union[str, int, float, bool]
    c: float = Field(ge=0.0, le=1.0)
    h: bool


class Submission(BaseModel):
    model_config = ConfigDict(extra="forbid")

    facts: list[Fact] = Field(max_length=64)
    more_supported_facts: bool


TOOLS = [
    {
        "type": "function",
        "function": {
            "name": "submit_facts",
            "description": "Submit validated Donto extraction facts.",
            "parameters": Submission.model_json_schema(),
        },
    }
]

SOURCE = """Ari reported that the primary system failed, while the reserve
system remained available. The panel postponed deployment until an independent
check was complete. Vera said the postponement wasted money, but Ari argued that
it protected staff."""

PROMPT = f"""Extract every atomic proposition directly supported by SOURCE.
Preserve attribution, contrast, modality, and negation. Use stable ex:kebab-case
entities, concise camelCase predicates, h:false for direct facts, and no prose.

SOURCE:
{SOURCE}
"""

client = OpenAI(base_url="http://127.0.0.1:8000/v1", api_key="unused")
response = client.chat.completions.create(
    model="donto-qwen",
    messages=[{"role": "user", "content": PROMPT}],
    tools=TOOLS,
    tool_choice={"type": "function", "function": {"name": "submit_facts"}},
    temperature=0,
    max_tokens=1024,
    extra_body={"chat_template_kwargs": {"enable_thinking": False, "preserve_thinking": False}},
)

call = response.choices[0].message.tool_calls[0]
submission = Submission.model_validate_json(call.function.arguments)
print(submission.model_dump_json(indent=2))