From 3ee8077088d9283702820d276269488508baa2cb Mon Sep 17 00:00:00 2001 From: parkervg Date: Wed, 16 Oct 2024 16:51:39 -0400 Subject: [PATCH] Allow null context in LLMQA ingredient --- blendsql/ingredients/builtin/qa/examples.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/blendsql/ingredients/builtin/qa/examples.py b/blendsql/ingredients/builtin/qa/examples.py index a6dd803..03e9e15 100644 --- a/blendsql/ingredients/builtin/qa/examples.py +++ b/blendsql/ingredients/builtin/qa/examples.py @@ -1,4 +1,4 @@ -from attr import attrs, attrib, validators +from attr import attrs, attrib import pandas as pd from typing import Optional, List, Callable @@ -8,9 +8,9 @@ @attrs(kw_only=True) class QAExample(Example): question: str = attrib() - context: pd.DataFrame = attrib( + context: Optional[pd.DataFrame] = attrib( converter=lambda d: pd.DataFrame.from_dict(d) if isinstance(d, dict) else d, - validator=validators.instance_of(pd.DataFrame), + default=None, ) options: Optional[List[str]] = attrib(default=None) @@ -19,7 +19,8 @@ def to_string(self, context_formatter: Callable[[pd.DataFrame], str]) -> str: s += f"\n\nQuestion: {self.question}\n" if self.options is not None: s += f"Options: {', '.join(self.options)}\n" - s += f"Context:\n{context_formatter(self.context)}" + if self.context is not None: + s += f"Context:\n{context_formatter(self.context)}" s += "\nAnswer: " return s