DSPy: The framework for programming—not prompting—language models
Python
update you_rm to return an iterable of predictions, in line with other models in /retrieve
Matthew Billmanc19f96d05b07
diff --git a/dsp/primitives/search.py b/dsp/primitives/search.pyindex 833c91494..a2071327d 100644--- a/dsp/primitives/search.py+++ b/dsp/primitives/search.py@@ -1,4 +1,7 @@+from collections.abc import Iterable+import numpy as np+import dsp@@ -7,6 +10,10 @@ def retrieve(query: str, k: int, **kwargs) -> list[str]:if not dsp.settings.rm:raise AssertionError("No RM is loaded.")passages = dsp.settings.rm(query, k=k, **kwargs)+ if not isinstance(passages, Iterable):+ # it's not an iterable yet; make it one.+ # TODO: we should unify the type signatures of dspy.Retriever+ passages = [passages]passages = [psg.long_text for psg in passages]if dsp.settings.reranker:diff --git a/dspy/retrieve/you_rm.py b/dspy/retrieve/you_rm.pyindex a5f69d9f9..7321e67bd 100644--- a/dspy/retrieve/you_rm.py+++ b/dspy/retrieve/you_rm.py@@ -1,6 +1,7 @@import dspyimport osimport requests+from dsp.utils import dotdictfrom typing import Union, List, Optional@@ -43,4 +44,4 @@ class YouRM(dspy.Retrieve):for hit in results["hits"][:k]:for snippet in hit["snippets"]:docs.append(snippet)- return dspy.Prediction(passages=docs)+ return [dotdict({"long_text": document}) for document in docs]