Skip to content

Commit

Permalink
Generator -> Facts
Browse files Browse the repository at this point in the history
  • Loading branch information
GeneralPoxter committed Sep 6, 2024
1 parent 469128b commit d9906f0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions etc/scallopy-plugins/gpt/src/scallop_gpt/fp_gpt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Tuple
from typing import Tuple, Generator

import openai
import scallopy
Expand All @@ -9,7 +9,7 @@


@scallopy.foreign_predicate
def gpt(s: str) -> scallopy.Generator[None, str]:
def gpt(s: str) -> scallopy.Facts[None, str]:
# Check if the storage already contains the response
if s in STORAGE:
response = STORAGE[s]
Expand Down
4 changes: 2 additions & 2 deletions etc/scallopy-plugins/plip/src/scallop_plip/plip.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def plip(
assert args[2].ty.is_string() and (args[2].adornment is None or args[2].adornment.is_free()), f"{ERR_HEAD} third argument has to be of free type `String`"

@scallopy.foreign_predicate(name=relation_decl.name.name)
def plip_classify(img: scallopy.Tensor) -> scallopy.Generator[float, Tuple[str]]:
def plip_classify(img: scallopy.Tensor) -> scallopy.Facts[float, Tuple[str]]:
device = get_device()
maybe_plip_model = get_plip_model(debug=debug)
if maybe_plip_model is None:
Expand All @@ -64,7 +64,7 @@ def plip_classify(img: scallopy.Tensor) -> scallopy.Generator[float, Tuple[str]]

# Generate the foreign predicate for dynamic labels
@scallopy.foreign_predicate(name=relation_decl.name.name)
def plip_classify_with_labels(img: scallopy.Tensor, list: scallopy.String) -> scallopy.Generator[float, Tuple[str]]:
def plip_classify_with_labels(img: scallopy.Tensor, list: scallopy.String) -> scallopy.Facts[float, Tuple[str]]:
nonlocal labels
labels = [item.strip() for item in list.split(DELIMITER)]
return plip_classify(img)
Expand Down
14 changes: 6 additions & 8 deletions experiments/clutrr-v2/kinship_scallop.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import openai
import json
from tqdm import tqdm
from io import StringIO
Expand All @@ -24,6 +23,12 @@ def __init__(self):

def test_kinship(range=range(N)):
out = {"score": 0, "data": [], "logs": []}

plugins = scallopy_ext.PluginRegistry()
parser = argparse.ArgumentParser()
plugins.setup_argument_parser(parser)
known_args, unknown_args = parser.parse_known_args()
plugins.configure(known_args, unknown_args)

for i in tqdm(range):
(ctx, query), ans = TASK[i]
Expand All @@ -33,14 +38,7 @@ def test_kinship(range=range(N)):
sys.stdout = buffer
try:
ctx = scallopy.ScallopContext(provenance="unit")
plugins = scallopy_ext.PluginRegistry()

parser = argparse.ArgumentParser()
plugins.setup_argument_parser(parser)
known_args, unknown_args = parser.parse_known_args()
plugins.configure(known_args, unknown_args)
plugins.load_into_ctx(ctx)

ctx.import_file(SCALLOP_FILE)
ctx.add_facts("context", [(input,)])
ctx.run()
Expand Down

0 comments on commit d9906f0

Please sign in to comment.