File size: 913 Bytes
2becd91 |
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 |
# Information extraction from a typed data specification.
import minichain
from dataclasses import dataclass
from typing import List
from enum import Enum
# Data specification
# +
class StatType(Enum):
POINTS = 1
REBOUNDS = 2
ASSISTS = 3
@dataclass
class Stat:
value: int
stat: StatType
@dataclass
class Player:
player: str
stats: List[Stat]
# -
# Code
class ExtractionPrompt(minichain.TypedTemplatePrompt):
template_file = "stats.pmpt.tpl"
Out = Player
with minichain.start_chain("stats") as backend:
p = ExtractionPrompt(backend.OpenAI(max_tokens=512))
article = open("sixers.txt").read()
for player in p({"passage": article}):
print(player)
ExtractionPrompt().show({"passage": "Harden had 10 rebounds."},
'[{"player": "Harden", "stats": {"value": 10, "stat": 2}}]')
# View the run log.
minichain.show_log("bash.log")
|