Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

Force the optimizer to not repeat signatures

Thomas D Ahle1e638a14da97
diff --git a/dspy/signatures/signature.py b/dspy/signatures/signature.py
index 314d6c712..74fa3ee73 100644
--- a/dspy/signatures/signature.py
+++ b/dspy/signatures/signature.py
@@ -35,7 +35,9 @@ class SignatureMeta(type(BaseModel)):
def __new__(mcs, signature_name, bases, namespace, **kwargs): # noqa: N804
# Set `str` as the default type for all fields
raw_annotations = namespace.get("__annotations__", {})
- for name, _field in namespace.items():
+ for name, field in namespace.items():
+ if not isinstance(field, FieldInfo):
+ continue # Don't add types to non-field attributes
if not name.startswith("__") and name not in raw_annotations:
raw_annotations[name] = str
namespace["__annotations__"] = raw_annotations
@@ -272,9 +274,8 @@ def make_signature(
def _parse_signature(signature: str) -> Tuple[Type, Field]:
- pattern = r"^\s*[\w\s,:]+\s*->\s*[\w\s,:]+\s*$"
- if not re.match(pattern, signature):
- raise ValueError(f"Invalid signature format: '{signature}'")
+ if signature.count("->") != 1:
+ raise ValueError(f"Invalid signature format: '{signature}', must contain exactly one '->'.")
fields = {}
inputs_str, outputs_str = map(str.strip, signature.split("->"))
diff --git a/dspy/teleprompt/signature_opt_typed.py b/dspy/teleprompt/signature_opt_typed.py
index 35e103306..145597153 100644
--- a/dspy/teleprompt/signature_opt_typed.py
+++ b/dspy/teleprompt/signature_opt_typed.py
@@ -100,20 +100,32 @@ def make_initial_signature(n_prompts: int) -> type[Signature]:
return GenerateInstructionInitial
-class GenerateSignature(dspy.Signature, Generic[T]):
- __doc__ = textwrap.dedent("""\
- You are an instruction optimizer for large language models.
+def generate_with_avoidance(signatures_to_avoid: list[BaseModel]) -> type[Signature]:
+ class GenerateSignature(dspy.Signature, Generic[T]):
+ __doc__ = textwrap.dedent("""\
+ You are an instruction optimizer for large language models.
+
+ I will give some task instructions I've tried, along with their corresponding validation scores.
+ - The instructions are arranged in order based on their scores, where higher scores indicate better quality.
+ - Your task is to propose a new instruction that will lead a good language model to perform the task even better.
+ - Be creative, and think out of the box.
+ - Don't repeat instructions, descriptions and prefixes that have already been attempted.
+ """)
- I will give some task instructions I've tried, along with their corresponding validation scores.
- - The instructions are arranged in order based on their scores, where higher scores indicate better quality.
- - Your task is to propose a new instruction that will lead a good language model to perform the task even better.
- - Be creative, and think out of the box.
- - Don't repeat instructions, descriptions and prefixes that have already been attempted.
- """)
+ analysis: str = OutputField(desc="Consider what made the previous instructions good or bad.")
+ proposed_signature: T = OutputField(desc="A signature that will likely lead to a high score.")
+ score: float = OutputField(
+ desc="The expected score for the new signature. Don't write anything after this number."
+ )
+
+ @pydantic.field_validator("proposed_signature")
+ @classmethod
+ def check_signature_not_attempted(cls, s: T) -> T:
+ if s in signatures_to_avoid:
+ raise ValueError("Never propose a signature already in the list above.")
+ return s
- analysis: str = OutputField(desc="Consider what made the previous instructions good or bad.")
- proposed_signature: T = OutputField(desc="A signature that will likely lead to a high score.")
- score: float = OutputField(desc="The expected score for the new signature. Don't write anything after this number.")
+ return GenerateSignature
@dataclass
@@ -233,7 +245,6 @@ def optimize_signature(
# TODO: Parallelize this
for name, _p in named_predictors:
SignatureInfo = type(candidates[name][0]) # noqa: N806
- generator = TypedPredictor(GenerateSignature[SignatureInfo])
demos = [dspy.Example(proposed_signature=info, score=sc) for info, sc in zip(candidates[name], scores)]
if sorted_order == "chronological":
@@ -246,6 +257,10 @@ def optimize_signature(
demos = demos[:max_examples]
else:
raise ValueError(f"Invalid sorted_order: {sorted_order}")
+
+ # We can only tell the LM to avoid the signatures we are actually giving it as demos.
+ avoid = [ex.proposed_signature for ex in demos]
+ generator = TypedPredictor(generate_with_avoidance(avoid)[SignatureInfo])
generator.predictor.demos = demos
if verbose:
diff --git a/examples/functional/signature_opt_typed.ipynb b/examples/functional/signature_opt_typed.ipynb
index 115d48140..feab8d635 100644
--- a/examples/functional/signature_opt_typed.ipynb
+++ b/examples/functional/signature_opt_typed.ipynb
@@ -2,18 +2,9 @@
"cells": [
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": 1,
"metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "The autoreload extension is already loaded. To reload it, use:\n",
- " %reload_ext autoreload\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2\n",
@@ -25,1529 +16,310 @@
]
},
{
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [],
- "source": [
- "import dspy\n",
- "turbo = dspy.OpenAI(model='gpt-3.5-turbo', max_tokens=4000)\n",
- "gpt4 = dspy.OpenAI(model='gpt-4', max_tokens=4000)\n",
- "dspy.settings.configure(lm=turbo)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Prediction(\n",
- " answer='Paris'\n",
- ")"
- ]
- },
- "execution_count": 9,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "dspy.TypedPredictor(\"question -> answer\")(question=\"What is the capital of France?\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "(20, 50)"
- ]
- },
- "execution_count": 10,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "from dspy.datasets import HotPotQA\n",
- "\n",
- "# Load the dataset.\n",
- "dataset = HotPotQA(train_seed=1, train_size=20, eval_seed=2023, dev_size=50, test_size=0)\n",
- "\n",
- "# Tell DSPy that the 'question' field is the input. Any other fields are labels and/or metadata.\n",
- "trainset = [x.with_inputs('question') for x in dataset.train]\n",
- "devset = [x.with_inputs('question') for x in dataset.dev]\n",
- "\n",
- "len(trainset), len(devset)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [],
- "source": [
- "class BasicQA(dspy.Signature):\n",
- " \"\"\"Answer questions with short factoid answers.\"\"\"\n",
- "\n",
- " question = dspy.InputField()\n",
- " answer = dspy.OutputField(desc=\"often between 1 and 5 words\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 24,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Found 1 typed predictors to optimize.\n",
- "Generating 6 initial signatures for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 0...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 16 / 50 (32.0): 100%|██████████| 50/50 [00:00<00:00, 5693.37it/s]\n",
- "/Users/ahle/repos/dspy/dspy/evaluate/evaluate.py:145: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
- " df = df.applymap(truncate_cell)\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 16 / 50 (32.0%)\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 1...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 1 / 50 (2.0): 100%|██████████| 50/50 [00:00<00:00, 5255.36it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 1 / 50 (2.0%)\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 2...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 4871.89it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0%)\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 3...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 16 / 50 (32.0): 100%|██████████| 50/50 [00:00<00:00, 5412.98it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 16 / 50 (32.0%)\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 4...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 6 / 50 (12.0): 100%|██████████| 50/50 [00:00<00:00, 5261.43it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 6 / 50 (12.0%)\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 5...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 5 / 50 (10.0): 100%|██████████| 50/50 [00:00<00:00, 5405.45it/s]"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 5 / 50 (10.0%)\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 6...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "\n",
- "Average Metric: 12 / 50 (24.0): 100%|██████████| 50/50 [00:00<00:00, 5346.47it/s]"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 12 / 50 (24.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 7...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "\n",
- "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 2367.98it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 8...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 5037.72it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 9...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 12 / 50 (24.0): 100%|██████████| 50/50 [00:00<00:00, 4994.05it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 12 / 50 (24.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 10...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 11 / 50 (22.0): 100%|██████████| 50/50 [00:00<00:00, 5207.99it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 11 / 50 (22.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 11...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5178.03it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 12...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 6126.65it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 13...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 1013.36it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 14...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 4902.06it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 15...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 16 / 50 (32.0): 100%|██████████| 50/50 [00:00<00:00, 4703.72it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 16 / 50 (32.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 16...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 16 / 50 (32.0): 100%|██████████| 50/50 [00:00<00:00, 5067.42it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 16 / 50 (32.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 17...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 5343.06it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 18...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 16 / 50 (32.0): 100%|██████████| 50/50 [00:00<00:00, 5155.11it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 16 / 50 (32.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 19...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 19 / 50 (38.0): 100%|██████████| 50/50 [00:00<00:00, 673.08it/s] \n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 19 / 50 (38.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 20...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 16 / 50 (32.0): 100%|██████████| 50/50 [00:00<00:00, 5469.88it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 16 / 50 (32.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 21...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 4980.53it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 22...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 19 / 50 (38.0): 100%|██████████| 50/50 [00:00<00:00, 6185.74it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 19 / 50 (38.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 23...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5566.87it/s]"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 24...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "\n",
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 4908.72it/s]"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 25...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "\n",
- "Average Metric: 16 / 50 (32.0): 100%|██████████| 50/50 [00:00<00:00, 968.52it/s] \n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 16 / 50 (32.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 26...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 4921.16it/s]"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 27...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "\n",
- "Average Metric: 18 / 50 (36.0): 100%|██████████| 50/50 [00:00<00:00, 5208.37it/s]"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 18 / 50 (36.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 28...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "\n",
- "Average Metric: 20 / 50 (40.0): 100%|██████████| 50/50 [00:00<00:00, 5443.61it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 20 / 50 (40.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 29...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 20 / 50 (40.0): 100%|██████████| 50/50 [00:00<00:00, 5854.70it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 20 / 50 (40.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 30...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 19 / 50 (38.0): 100%|██████████| 50/50 [00:00<00:00, 5709.64it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 19 / 50 (38.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 31...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 18 / 50 (36.0): 100%|██████████| 50/50 [00:00<00:00, 810.21it/s] \n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 18 / 50 (36.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 32...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 19 / 50 (38.0): 100%|██████████| 50/50 [00:00<00:00, 3970.45it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 19 / 50 (38.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 33...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 4379.74it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 34...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 3614.53it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 35...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 3822.32it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 36...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 20 / 50 (40.0): 100%|██████████| 50/50 [00:00<00:00, 3541.11it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 20 / 50 (40.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 37...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 18 / 50 (36.0): 100%|██████████| 50/50 [00:00<00:00, 2972.87it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 18 / 50 (36.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 38...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 2611.94it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 39...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 18 / 50 (36.0): 100%|██████████| 50/50 [00:00<00:00, 2124.95it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 18 / 50 (36.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 40...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 2477.12it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 41...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 18 / 50 (36.0): 100%|██████████| 50/50 [00:00<00:00, 5950.21it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 18 / 50 (36.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 42...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 19 / 50 (38.0): 100%|██████████| 50/50 [00:00<00:00, 5514.47it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 19 / 50 (38.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 43...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 18 / 50 (36.0): 100%|██████████| 50/50 [00:00<00:00, 5892.86it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 18 / 50 (36.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 44...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 16 / 50 (32.0): 100%|██████████| 50/50 [00:00<00:00, 2642.45it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 16 / 50 (32.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 45...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 19 / 50 (38.0): 100%|██████████| 50/50 [00:00<00:00, 4842.19it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 19 / 50 (38.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 46...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 5380.35it/s]"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 17 / 50 (34.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 47...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "\n",
- "Average Metric: 19 / 50 (38.0): 100%|██████████| 50/50 [00:00<00:00, 5425.87it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 19 / 50 (38.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 48...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 21 / 50 (42.0): 100%|██████████| 50/50 [00:00<00:00, 5317.32it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 21 / 50 (42.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 49...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 21 / 50 (42.0): 100%|██████████| 50/50 [00:00<00:00, 5832.88it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 21 / 50 (42.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 50...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 1801.99it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 51...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 4837.94it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 52...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5629.33it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 53...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5490.21it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 54...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5715.56it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 55...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5685.19it/s]"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 56...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "\n",
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 668.95it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 57...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5015.07it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 58...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5527.40it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 59...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5037.23it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 60...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5525.36it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 61...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5428.40it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 62...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 956.70it/s] "
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 63...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "\n",
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5655.44it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 64...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5225.77it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 65...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 4379.93it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 66...\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5452.39it/s]\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
- "\n",
- "================================================================================\n",
- "Running eval iteration 67...\n"
- ]
- },
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {},
+ "outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5898.83it/s]\n"
+ "/opt/homebrew/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
+ " from .autonotebook import tqdm as notebook_tqdm\n"
]
- },
+ }
+ ],
+ "source": [
+ "import dspy\n",
+ "turbo = dspy.OpenAI(model='gpt-3.5-turbo', max_tokens=4000)\n",
+ "gpt4 = dspy.OpenAI(model='gpt-4', max_tokens=4000)\n",
+ "dspy.settings.configure(lm=turbo)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Prediction(\n",
+ " answer='Paris'\n",
+ ")"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "dspy.TypedPredictor(\"question -> answer\")(question=\"What is the capital of France?\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "(20, 50)"
+ ]
+ },
+ "execution_count": 4,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "from dspy.datasets import HotPotQA\n",
+ "\n",
+ "# Load the dataset.\n",
+ "dataset = HotPotQA(train_seed=1, train_size=20, eval_seed=2023, dev_size=50, test_size=0)\n",
+ "\n",
+ "# Tell DSPy that the 'question' field is the input. Any other fields are labels and/or metadata.\n",
+ "trainset = [x.with_inputs('question') for x in dataset.train]\n",
+ "devset = [x.with_inputs('question') for x in dataset.dev]\n",
+ "\n",
+ "len(trainset), len(devset)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "class BasicQA(dspy.Signature):\n",
+ " \"\"\"Answer questions with short factoid answers.\"\"\"\n",
+ "\n",
+ " question = dspy.InputField()\n",
+ " answer = dspy.OutputField(desc=\"often between 1 and 5 words\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {},
+ "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
+ "Found 1 typed predictors to optimize.\n",
+ "Generating 6 initial signatures for base...\n",
"\n",
"================================================================================\n",
- "Running eval iteration 68...\n"
+ "Running eval iteration 0...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 711.01it/s] \n"
+ "Average Metric: 16 / 50 (32.0): 100%|██████████| 50/50 [00:00<00:00, 3086.59it/s]\n",
+ "/Users/ahle/repos/dspy/dspy/evaluate/evaluate.py:145: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
+ " df = df.applymap(truncate_cell)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
+ "Average Metric: 16 / 50 (32.0%)\n",
"\n",
"================================================================================\n",
- "Running eval iteration 69...\n"
+ "Running eval iteration 1...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 3476.83it/s]\n"
+ "Average Metric: 1 / 50 (2.0): 100%|██████████| 50/50 [00:00<00:00, 1268.65it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
+ "Average Metric: 1 / 50 (2.0%)\n",
"\n",
"================================================================================\n",
- "Running eval iteration 70...\n"
+ "Running eval iteration 2...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 4120.30it/s]\n"
+ "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 1031.35it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
+ "Average Metric: 17 / 50 (34.0%)\n",
"\n",
"================================================================================\n",
- "Running eval iteration 71...\n"
+ "Running eval iteration 3...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 4182.01it/s]\n"
+ "Average Metric: 16 / 50 (32.0): 100%|██████████| 50/50 [00:00<00:00, 1364.88it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
+ "Average Metric: 16 / 50 (32.0%)\n",
"\n",
"================================================================================\n",
- "Running eval iteration 72...\n"
+ "Running eval iteration 4...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 4117.15it/s]\n"
+ "Average Metric: 6 / 50 (12.0): 100%|██████████| 50/50 [00:00<00:00, 892.68it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
+ "Average Metric: 6 / 50 (12.0%)\n",
"\n",
"================================================================================\n",
- "Running eval iteration 73...\n"
+ "Running eval iteration 5...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 3325.38it/s]\n"
+ "Average Metric: 5 / 50 (10.0): 100%|██████████| 50/50 [00:00<00:00, 1055.56it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
- "Generating new signature for base...\n",
+ "Average Metric: 5 / 50 (10.0%)\n",
"\n",
"================================================================================\n",
- "Running eval iteration 74...\n"
+ "Running eval iteration 6...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 3122.67it/s]\n"
+ "Average Metric: 12 / 50 (24.0): 100%|██████████| 50/50 [00:00<00:00, 942.15it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 12 / 50 (24.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 7 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 75...\n"
+ "Running eval iteration 7...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 2266.85it/s]\n"
+ "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 1054.12it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 17 / 50 (34.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 8 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 76...\n"
+ "Running eval iteration 8...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 1976.75it/s]\n"
+ "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 957.29it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 17 / 50 (34.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 9 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 77...\n"
+ "Running eval iteration 9...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 2248.40it/s]\n"
+ "Average Metric: 12 / 50 (24.0): 100%|██████████| 50/50 [00:00<00:00, 1015.95it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 12 / 50 (24.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 10 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 78...\n"
+ "Running eval iteration 10...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5650.26it/s]\n"
+ "Average Metric: 11 / 50 (22.0): 100%|██████████| 50/50 [00:00<00:00, 839.64it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 11 / 50 (22.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 11 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 79...\n"
+ "Running eval iteration 11...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 1173.79it/s]\n"
+ "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 833.32it/s]\n"
]
},
{
@@ -1556,16 +328,17 @@
"text": [
"Average Metric: 15 / 50 (30.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 12 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 80...\n"
+ "Running eval iteration 12...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5328.67it/s]\n"
+ "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 1105.97it/s]\n"
]
},
{
@@ -1574,196 +347,207 @@
"text": [
"Average Metric: 15 / 50 (30.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 13 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 81...\n"
+ "Running eval iteration 13...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 4941.68it/s]\n"
+ "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 1112.59it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 17 / 50 (34.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 14 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 82...\n"
+ "Running eval iteration 14...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 4712.60it/s]\n"
+ "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 1096.58it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 17 / 50 (34.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 15 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 83...\n"
+ "Running eval iteration 15...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5124.50it/s]\n"
+ "Average Metric: 16 / 50 (32.0): 100%|██████████| 50/50 [00:00<00:00, 1092.70it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 16 / 50 (32.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 16 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 84...\n"
+ "Running eval iteration 16...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5616.82it/s]\n"
+ "Average Metric: 16 / 50 (32.0): 100%|██████████| 50/50 [00:00<00:00, 1097.79it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 16 / 50 (32.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 17 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 85...\n"
+ "Running eval iteration 17...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5007.41it/s]\n"
+ "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 547.69it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 17 / 50 (34.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 18 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 86...\n"
+ "Running eval iteration 18...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5371.25it/s]\n"
+ "Average Metric: 16 / 50 (32.0): 100%|██████████| 50/50 [00:00<00:00, 964.67it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 16 / 50 (32.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 19 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 87...\n"
+ "Running eval iteration 19...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 1938.59it/s]\n"
+ "Average Metric: 19 / 50 (38.0): 100%|██████████| 50/50 [00:00<00:00, 1014.22it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 19 / 50 (38.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 20 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 88...\n"
+ "Running eval iteration 20...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5357.39it/s]\n"
+ "Average Metric: 16 / 50 (32.0): 100%|██████████| 50/50 [00:00<00:00, 906.14it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 16 / 50 (32.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 21 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 89...\n"
+ "Running eval iteration 21...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5891.37it/s]\n"
+ "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:00<00:00, 1017.81it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 17 / 50 (34.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 22 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 90...\n"
+ "Running eval iteration 22...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 4924.74it/s]\n"
+ "Average Metric: 19 / 50 (38.0): 100%|██████████| 50/50 [00:00<00:00, 1032.48it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 19 / 50 (38.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 23 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 91...\n"
+ "Running eval iteration 23...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5301.19it/s]\n"
+ "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 726.33it/s]\n"
]
},
{
@@ -1772,16 +556,17 @@
"text": [
"Average Metric: 15 / 50 (30.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 24 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 92...\n"
+ "Running eval iteration 24...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 2998.12it/s]\n"
+ "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 957.55it/s]\n"
]
},
{
@@ -1790,34 +575,36 @@
"text": [
"Average Metric: 15 / 50 (30.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 25 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 93...\n"
+ "Running eval iteration 25...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 975.27it/s]\n"
+ "Average Metric: 16 / 50 (32.0): 100%|██████████| 50/50 [00:00<00:00, 1009.53it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 16 / 50 (32.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 26 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 94...\n"
+ "Running eval iteration 26...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5701.88it/s]\n"
+ "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 1064.53it/s]\n"
]
},
{
@@ -1826,102 +613,114 @@
"text": [
"Average Metric: 15 / 50 (30.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 27 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 95...\n"
+ "Running eval iteration 27...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5424.74it/s]\n"
+ "Average Metric: 18 / 50 (36.0): 100%|██████████| 50/50 [00:00<00:00, 1052.90it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 18 / 50 (36.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 28 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 96...\n"
+ "Running eval iteration 28...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 4879.48it/s]\n"
+ "Average Metric: 20 / 50 (40.0): 100%|██████████| 50/50 [00:00<00:00, 731.18it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 20 / 50 (40.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 29 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 97...\n"
+ "Running eval iteration 29...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5342.52it/s]\n"
+ "Average Metric: 16 / 50 (32.0): 100%|██████████| 50/50 [00:02<00:00, 18.61it/s]\n",
+ "/Users/ahle/repos/dspy/dspy/evaluate/evaluate.py:145: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
+ " df = df.applymap(truncate_cell)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 16 / 50 (32.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 30 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 98...\n"
+ "Running eval iteration 30...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 5386.71it/s]\n"
+ "Average Metric: 17 / 50 (34.0): 100%|██████████| 50/50 [00:02<00:00, 18.23it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n",
+ "Average Metric: 17 / 50 (34.0%)\n",
"Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 31 to avoid.\n",
"\n",
"================================================================================\n",
- "Running eval iteration 99...\n"
+ "Running eval iteration 31...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0): 100%|██████████| 50/50 [00:00<00:00, 957.51it/s] "
+ "Average Metric: 19 / 50 (38.0): 100%|██████████| 50/50 [00:02<00:00, 20.82it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Average Metric: 15 / 50 (30.0%)\n"
+ "Average Metric: 19 / 50 (38.0%)\n",
+ "Generating new signature for base...\n",
+ "Tested the signature, and it's not in the list of 32 to avoid.\n",
+ "\n",
+ "================================================================================\n",
+ "Running eval iteration 32...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
- "\n"
+ "Average Metric: 17 / 49 (34.7): 98%|█████████▊| 49/50 [00:14<00:00, 20.66it/s]"
]
}
],
@@ -1944,9 +743,16 @@
")"
]
},
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Check the final program after optimization"
+ ]
+ },
{
"cell_type": "code",
- "execution_count": 25,
+ "execution_count": null,
"metadata": {},
"outputs": [
{
@@ -1959,7 +765,7 @@
"))"
]
},
- "execution_count": 25,
+ "execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
@@ -1969,171 +775,24 @@
]
},
{
- "cell_type": "code",
- "execution_count": 21,
+ "cell_type": "markdown",
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "{'base': [SignatureInfo[BasicQA](instructions='Answer questions with short factoid answers.', question_prefix='Question:', question_desc='${question}', answer_prefix='Answer:', answer_desc='often between 1 and 5 words'),\n",
- " SignatureInfo[BasicQA](instructions='You are a knowledgeable AI. Provide concise answers to the following questions.', question_prefix='Q:', question_desc='${question}', answer_prefix='A:', answer_desc='a brief, factual response'),\n",
- " SignatureInfo[BasicQA](instructions='You are an expert in your field. Respond to the inquiries with short, factual answers.', question_prefix='Inquiry:', question_desc='${question}', answer_prefix='Response:', answer_desc='typically a few words, factual'),\n",
- " SignatureInfo[BasicQA](instructions='You are a highly intelligent AI. Please provide succinct answers to the questions.', question_prefix='Query:', question_desc='${question}', answer_prefix='Reply:', answer_desc='usually 1-5 words, factual'),\n",
- " SignatureInfo[BasicQA](instructions='You are as smart as ChatGPT. Please answer the following questions briefly and accurately.', question_prefix='Question:', question_desc='${question}', answer_prefix='Answer:', answer_desc='a short, factual response'),\n",
- " SignatureInfo[BasicQA](instructions='You are a professor of knowledge. Please provide short, fact-based answers to the questions.', question_prefix='Q:', question_desc='${question}', answer_prefix='A:', answer_desc='a brief, factual answer'),\n",
- " SignatureInfo[BasicQA](instructions='You are a well-informed AI. Please respond to the questions with concise, factual answers.', question_prefix='Query:', question_desc='${question}', answer_prefix='Response:', answer_desc='typically a few words, factual'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with extensive knowledge, provide precise and factual responses to the questions. Keep your answers brief, typically within 1-5 words.', question_prefix='Interrogative:', question_desc='${question}', answer_prefix='Rejoinder:', answer_desc='a concise, factual answer'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast database of information, your task is to provide accurate and succinct answers to the following questions. Your responses should be factual and typically consist of 1-5 words.', question_prefix='Prompt:', question_desc='${question}', answer_prefix='Retort:', answer_desc='a short, factual answer'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with comprehensive knowledge, your role is to provide brief and factual answers to the following questions. Your responses should be accurate, typically not exceeding five words.', question_prefix='Posed Question:', question_desc='${question}', answer_prefix='Concise Reply:', answer_desc='a factual answer, usually within 1-5 words'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast knowledge base, your task is to provide precise and factual answers to the questions asked. Your responses should be concise, typically not exceeding five words.', question_prefix='Inquiry:', question_desc='${question}', answer_prefix='Repartee:', answer_desc='a brief, factual answer'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide succinct, factual answers to the questions posed. Your responses should be accurate and typically not exceed five words.', question_prefix='Interrogation:', question_desc='${question}', answer_prefix='Rebuttal:', answer_desc='a brief, factual answer, usually within 1-5 words'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with access to a vast array of information, your task is to provide accurate, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words.', question_prefix='Prompt:', question_desc='${question}', answer_prefix='Retort:', answer_desc='a brief, factual answer'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with access to a vast knowledge base, your task is to provide accurate, factual answers to the questions posed. The questions will be about various topics, and your responses should be succinct, typically consisting of 1-5 words.', question_prefix='Inquiry:', question_desc='${question}', answer_prefix='Response:', answer_desc='a brief, factual answer'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast reservoir of information, your task is to provide precise, factual answers to the questions asked. Your responses should be succinct, typically consisting of 1-5 words, and cover a wide range of topics.', question_prefix='Enquiry:', question_desc='${question}', answer_prefix='Rejoinder:', answer_desc='a brief, factual answer'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with access to a vast repository of information, your task is to provide accurate, factual answers to the questions posed. The questions could be about any topic, so use your extensive knowledge to provide the most accurate response. Your answers should be succinct, typically consisting of 1-5 words.', question_prefix='Interrogation:', question_desc='${question}', answer_prefix='Repartee:', answer_desc='a brief, factual answer, demonstrating accuracy and breadth of knowledge'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast compendium of information, your task is to provide precise, factual responses to the questions posed. Your answers should be succinct, typically consisting of 1-5 words, and cover a broad spectrum of topics.', question_prefix='Probing:', question_desc='${question}', answer_prefix='Repartee:', answer_desc='a concise, factual answer'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast knowledge base, your task is to provide accurate, factual answers to a wide range of questions. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge and understanding.', question_prefix='Inquiry:', question_desc='${question}', answer_prefix='Retort:', answer_desc='a brief, factual answer demonstrating accuracy and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast knowledge base, your task is to provide accurate, factual answers to a wide range of questions, from general knowledge to specific facts. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge and understanding. Accuracy is paramount.', question_prefix='Interrogative:', question_desc='${question}', answer_prefix='Rejoinder:', answer_desc='a brief, factual answer demonstrating accuracy and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge repository, your task is to provide precise, factual responses to the questions posed. Your answers should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics.', question_prefix='Examination:', question_desc='${question}', answer_prefix='Rejoinder:', answer_desc='a brief, factual answer demonstrating precision and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast knowledge repository, your task is to provide accurate, factual responses to the questions asked. Your answers should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy and precision are paramount.', question_prefix='Interrogation:', question_desc='${question}', answer_prefix='Repartee:', answer_desc='a brief, factual answer demonstrating precision and breadth of knowledge'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast knowledge repository, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Accuracy and precision are paramount.', question_prefix='Interrogative:', question_desc='${question}', answer_prefix='Rejoinder:', answer_desc='a brief, factual answer demonstrating precision and breadth of knowledge'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast knowledge repository, your task is to provide precise, factual responses to the questions posed. Your answers should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Accuracy and precision are paramount.', question_prefix='Examination:', question_desc='${question}', answer_prefix='Rejoinder:', answer_desc='a brief, factual answer demonstrating precision and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast knowledge base, your task is to provide accurate, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount.', question_prefix='Interrogation:', question_desc='${question}', answer_prefix='Repartee:', answer_desc='a brief, factual answer demonstrating precision, brevity, and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast knowledge base, your task is to provide accurate, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount.', question_prefix='Interrogative:', question_desc='${question}', answer_prefix='Rejoinder:', answer_desc='a brief, factual answer demonstrating precision, brevity, and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide accurate, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Precision and brevity are key.', question_prefix='Interrogative Statement:', question_desc='${question}', answer_prefix='Concise Response:', answer_desc='a brief, factual answer demonstrating precision and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast knowledge base, your task is to provide accurate, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount.', question_prefix='Interrogative Query:', question_desc='${question}', answer_prefix='Concise Rejoinder:', answer_desc='a brief, factual answer demonstrating precision, brevity, and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide accurate, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Precision, brevity, and accuracy are paramount.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Rebuttal:', answer_desc='a brief, factual answer demonstrating precision, brevity, and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge repository, your task is to provide precise, factual responses to the inquiries posed. Your answers should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Accuracy, precision, and brevity are paramount.', question_prefix='Interrogative Examination:', question_desc='${question}', answer_prefix='Succinct Rejoinder:', answer_desc='a brief, factual answer demonstrating precision, brevity, and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge repository, your task is to provide precise, factual responses to the inquiries posed. Your answers should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Accuracy, precision, and brevity are paramount.', question_prefix='Interrogative Examination:', question_desc='${question}', answer_prefix='Succinct Rejoinder:', answer_desc='a brief, factual answer demonstrating precision, brevity, and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast knowledge repository, your task is to provide precise, factual responses to the questions posed. Your answers should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Accuracy, precision, and brevity are paramount.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Succinct Retort:', answer_desc='a brief, factual answer demonstrating precision, brevity, and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast knowledge repository, your task is to provide precise, factual responses to the inquiries posed. Your answers should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Accuracy, precision, and brevity are paramount.', question_prefix='Interrogative Examination:', question_desc='${question}', answer_prefix='Succinct Rejoinder:', answer_desc='a brief, factual answer demonstrating precision, brevity, and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual responses to the questions posed. Your answers should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Accuracy, precision, and brevity are paramount.', question_prefix='Interrogative Query:', question_desc='${question}', answer_prefix='Succinct Rebuttal:', answer_desc='a brief, factual answer demonstrating precision, brevity, and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge repository, your task is to provide precise, factual responses to the inquiries posed. Your answers should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Accuracy, precision, and brevity are paramount.', question_prefix='Interrogative Scrutiny:', question_desc='${question}', answer_prefix='Succinct Rejoinder:', answer_desc='a brief, factual answer demonstrating precision, brevity, and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge repository, your task is to provide precise, factual responses to the inquiries posed. Your answers should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Accuracy, precision, and brevity are paramount.', question_prefix='Interrogative Scrutiny:', question_desc='${question}', answer_prefix='Precise Retort:', answer_desc='a brief, factual answer demonstrating precision, brevity, and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Accuracy, precision, and brevity are paramount.', question_prefix='Interrogative Inquiry:', question_desc='${question}', answer_prefix='Succinct Riposte:', answer_desc='a brief, factual answer demonstrating precision, brevity, and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount.', question_prefix='Interrogative Assessment:', question_desc='${question}', answer_prefix='Concise Counterpart:', answer_desc='a brief, factual answer demonstrating precision, brevity, and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Remember, your goal is to provide the most accurate and concise answer possible.', question_prefix='Interrogative Assessment:', question_desc='${question}', answer_prefix='Concise Counterpoint:', answer_desc='a brief, factual answer demonstrating precision, brevity, and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast knowledge base, your task is to provide accurate, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context of the question to provide the most relevant answer.', question_prefix='Interrogative Assessment:', question_desc='${question}', answer_prefix='Concise Counterpoint:', answer_desc='a brief, factual answer demonstrating precision, brevity, and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Additionally, consider the context of the question to provide the most relevant and accurate answer.', question_prefix='Contextual Inquiry:', question_desc='${question}', answer_prefix='Contextual Response:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast knowledge base, your task is to provide accurate, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Analysis:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with an extensive knowledge base, your task is to provide accurate, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your wide-ranging knowledge across various topics. Accuracy, precision, and brevity are key. Consider the context of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Exploration:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast knowledge repository, your task is to provide precise, factual responses to the questions posed. Your answers should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Accuracy, precision, and brevity are paramount. Consider the context of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Scrutiny:', question_desc='${question}', answer_prefix='Precise Rejoinder:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast knowledge repository, your task is to provide precise, factual responses to the questions posed. Your answers should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Accuracy, precision, and brevity are paramount. Consider the context of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Exploration:', question_desc='${question}', answer_prefix='Precise Rejoinder:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast knowledge repository, your task is to provide precise, factual responses to the questions posed. Your answers should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Accuracy, precision, and brevity are paramount. Consider the context of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Scrutiny:', question_desc='${question}', answer_prefix='Precise Rejoinder:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast knowledge repository, your task is to provide precise, factual responses to the questions asked. Your answers should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Query:', question_desc='${question}', answer_prefix='Precise Response:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a vast knowledge repository, your task is to provide precise, factual responses to the questions asked. Your answers should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Dissection:', question_desc='${question}', answer_prefix='Precise Elucidation:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge repository, your task is to provide precise, factual responses to the questions posed. Your answers should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Dissection:', question_desc='${question}', answer_prefix='Precise Elucidation:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge repository, your task is to provide precise, factual responses to the questions posed. Your answers should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Dissection:', question_desc='${question}', answer_prefix='Precise Elucidation:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding'),\n",
- " SignatureInfo[BasicQA](instructions='As an AI with a comprehensive knowledge base, your task is to provide precise, factual answers to the questions posed. Your responses should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a broad spectrum of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.', question_prefix='Interrogative Probe:', question_desc='${question}', answer_prefix='Concise Clarification:', answer_desc='a brief, factual answer demonstrating precision, brevity, and contextual understanding')]}"
- ]
- },
- "execution_count": 21,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
"source": [
- "result.signatures"
+ "Plot the scores over time"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": 14,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "StringSignature(question -> answer\n",
- " instructions='You are highly intelligent. Please provide short, factual answers to the following questions.'\n",
- " question = Field(annotation=str required=True json_schema_extra={'__dspy_field_type': 'input', 'prefix': 'Inquiry:', 'desc': '${question}'})\n",
- " answer = Field(annotation=str required=True json_schema_extra={'desc': 'usually between 1 and 5 words', '__dspy_field_type': 'output', 'prefix': 'Reply:'})\n",
- ")\n"
- ]
- }
- ],
- "source": [
- "print(result.program.signature)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 26,
- "metadata": {},
"outputs": [
{
"data": {
"text/plain": [
- "[<matplotlib.lines.Line2D at 0x12323a510>]"
+ "[<matplotlib.lines.Line2D at 0x2b2f60310>]"
]
},
- "execution_count": 26,
+ "execution_count": 10,
"metadata": {},
"output_type": "execute_result"
},
@@ -2155,7 +814,7 @@
},
{
"cell_type": "code",
- "execution_count": 27,
+ "execution_count": null,
"metadata": {},
"outputs": [
{
@@ -2348,50 +1007,6 @@
"source": [
"gpt4.inspect_history(n=1)"
]
- },
- {
- "cell_type": "code",
- "execution_count": 29,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "42.0"
- ]
- },
- "execution_count": 29,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "result.scores[48]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 28,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "{'base': StringSignature(question -> answer\n",
- " instructions='As an AI with a comprehensive knowledge repository, your task is to provide precise, factual responses to the questions posed. Your answers should be succinct, typically consisting of 1-5 words, and demonstrate your extensive knowledge across a wide array of topics. Accuracy, precision, and brevity are paramount. Consider the context and nuances of the question to provide the most relevant and accurate answer.'\n",
- " question = Field(annotation=str required=True json_schema_extra={'__dspy_field_type': 'input', 'prefix': 'Interrogative Dissection:', 'desc': '${question}'})\n",
- " answer = Field(annotation=str required=True json_schema_extra={'desc': 'a brief, factual answer demonstrating precision, brevity, and contextual understanding', '__dspy_field_type': 'output', 'prefix': 'Precise Elucidation:'})\n",
- " )}"
- ]
- },
- "execution_count": 28,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "result.signatures[48]"
- ]
}
],
"metadata": {
diff --git a/examples/quiz/DSPy_QuizGen_Cache b/examples/quiz/DSPy_QuizGen_Cache
new file mode 160000
index 000000000..27d6d433e
--- /dev/null
+++ b/examples/quiz/DSPy_QuizGen_Cache
@@ -0,0 +1 @@
+Subproject commit 27d6d433e73b91d3cf677ecf1d757813fcbd611d
diff --git a/tests/functional/test_functional.py b/tests/functional/test_functional.py
index 2289ce697..2d680d3b9 100644
--- a/tests/functional/test_functional.py
+++ b/tests/functional/test_functional.py
@@ -635,3 +635,20 @@ def test_generic_signature():
dspy.settings.configure(lm=lm)
assert predictor().output == 23
+
+
+def test_field_validator_in_signature():
+ class ValidatedSignature(dspy.Signature):
+ a: str = dspy.OutputField()
+
+ @pydantic.field_validator("a")
+ @classmethod
+ def space_in_a(cls, a: str) -> str:
+ if not " " in a:
+ raise ValueError("a must contain a space")
+ return a
+
+ with pytest.raises(pydantic.ValidationError):
+ _ = ValidatedSignature(a="no-space")
+
+ _ = ValidatedSignature(a="with space")
diff --git a/tests/functional/test_signature_opt_typed.py b/tests/functional/test_signature_opt_typed.py
index 4f0124fcc..85c8c8d56 100644
--- a/tests/functional/test_signature_opt_typed.py
+++ b/tests/functional/test_signature_opt_typed.py
@@ -1,12 +1,10 @@
-import json
+from typing import Generic, TypeVar
+
+import pydantic
import dspy
from dspy.evaluate import Evaluate
from dspy.functional import TypedPredictor
-from dspy.teleprompt.signature_opt_typed import (
- GenerateSignature,
- make_info,
- optimize_signature,
-)
+from dspy.teleprompt.signature_opt_typed import optimize_signature, make_info
from dspy.utils import DummyLM
from dspy.evaluate import Evaluate
@@ -14,11 +12,6 @@ from dspy.evaluate.metrics import answer_exact_match
from dspy.functional import TypedPredictor
-class BasicQA(dspy.Signature):
- question: str = dspy.InputField()
- answer: str = dspy.OutputField()
-
-
hotpotqa = [
ex.with_inputs("question")
for ex in [
@@ -106,44 +99,11 @@ hotpotqa = [
]
-def old_test_signature_info():
- info = make_info(BasicQA)
- SignatureInfo = type(info)
-
- devset = [
- dspy.Example(
- instructions="Answer the following questions",
- question_desc="Some question to answer",
- question_prefix="Q: ",
- answer_desc="A short answer to the question",
- answer_prefix="A: ",
- ),
- ]
-
- lm = DummyLM(
- [
- json.dumps(dict(devset[0])), # Proposed signature
- ]
- )
- dspy.settings.configure(lm=lm)
-
- generator = TypedPredictor(GenerateInstructionGivenAttempts[SignatureInfo])
-
- res = generator(attempted_signatures=[ScoredSignature[SignatureInfo](signature=info, score=50)])
- assert res.proposed_signature == SignatureInfo(**devset[0])
-
- # Test the "to_signature" method
-
- class OutputSignature(dspy.Signature):
- """Answer the following questions"""
-
- question: str = dspy.InputField(desc="Some question to answer", prefix="Q: ")
- answer: str = dspy.OutputField(desc="A short answer to the question", prefix="A: ")
-
- assert res.proposed_signature.to_signature().equals(OutputSignature)
-
-
def test_opt():
+ class BasicQA(dspy.Signature):
+ question: str = dspy.InputField()
+ answer: str = dspy.OutputField()
+
qa_model = DummyLM([])
prompt_model = DummyLM(
[
@@ -175,3 +135,59 @@ def test_opt():
assert result.program.signature.equals(ExpectedSignature)
assert result.scores == [0, 0]
+
+
+def test_opt_composed():
+ class MyModule(dspy.Module):
+ def __init__(self):
+ self.p1 = TypedPredictor("question:str -> considerations:list[str]", max_retries=1)
+ self.p2 = TypedPredictor("considerations:list[str] -> answer:str", max_retries=1)
+
+ def forward(self, question):
+ considerations = self.p1(question=question).considerations
+ return self.p2(considerations=considerations)
+
+ class ExpectedSignature1(dspy.Signature):
+ "I1"
+
+ question: str = dspy.InputField(desc="$q", prefix="Q:")
+ considerations: list[str] = dspy.OutputField(desc="$c", prefix="C:")
+
+ info1 = make_info(ExpectedSignature1)
+
+ class ExpectedSignature2(dspy.Signature):
+ "I2"
+
+ considerations: list[str] = dspy.InputField(desc="$c", prefix="C:")
+ answer: str = dspy.OutputField(desc="$a", prefix="A:")
+
+ info2 = make_info(ExpectedSignature2)
+
+ T = TypeVar("T")
+
+ class OutputWrapper(pydantic.BaseModel, Generic[T]):
+ value: list[T]
+
+ qa_model = DummyLM([])
+ prompt_model = DummyLM(
+ [
+ "some thoughts",
+ OutputWrapper[type(info1)](value=[info1]).model_dump_json(),
+ "some thoughts",
+ OutputWrapper[type(info2)](value=[info2]).model_dump_json(),
+ ]
+ )
+ dspy.settings.configure(lm=qa_model)
+
+ result = optimize_signature(
+ student=MyModule(),
+ evaluator=lambda x: 0, # We don't care about the evaluator here
+ initial_prompts=1,
+ n_iterations=2,
+ verbose=True,
+ prompt_model=prompt_model,
+ strategy="last",
+ )
+
+ assert result.program.p1.signature.equals(ExpectedSignature1)
+ assert result.program.p2.signature.equals(ExpectedSignature2)