Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring YouRM .forward signature in-line with Retrieve child class .forward methods (add K kwarg) #453

Merged
merged 1 commit into from
Feb 25, 2024

Conversation

mgbvox
Copy link
Contributor

@mgbvox mgbvox commented Feb 25, 2024

The following code (snippet) follow the setup idiom currently used by dspy:

class WebRag(dspy.Module):
    NL_SEP = "\n----------\n"

    def __init__(self):
        super().__init__()
        # uses you_rm as declared below:
        self.you_rm = dspy.Retrieve(k=5)
        self.chain_of_thought = dspy.ChainOfThought(...irrelevant_signature...)

    def forward(self, question: str):
        web_context = self.NL_SEP.join(self.you_rm(question).passages)
        out = self.chain_of_thought(web_context=web_context, question=question)
        return out.answer
...

rm = YouRM(ydc_api_key=settings.YDC_API_KEY.get_secret_value())
lm = dspy.OpenAI(model=settings.LLM_MODEL, api_key=settings.OPENAI_API_KEY.get_secret_value())
dspy.settings.configure(lm=lm, rm=rm)

However, invoking this with a question string raises the following error:

web_rag = WebRag()

out = web_rag("What is the meaning of life (according to Douglas Adams)?")

# ERROR:
#  File "/Users/mgb/miniforge3/envs/nlu/lib/python3.9/site-packages/dspy/retrieve/retrieve.py", line 29, in __call__
#    return self.forward(*args, **kwargs)
# TypeError: forward() got an unexpected keyword argument 'k'

This is due to retrieveEnsemble in search.py invoking YouRM's .forward with an additional k kwarg.

Inspecting other modules in dspy/retrieve (e.g. chromadb.py) shows that k is desired as a kwarg to retrieve forward invocations; I therefore added this to YouRM's .forward and also to the parent .forward implementation in retrieve.py.

@CShorten
Copy link
Collaborator

Lgtm! Was thinking about doing this as well, super important!

@okhat okhat merged commit 2754378 into stanfordnlp:main Feb 25, 2024
1 check passed
@okhat
Copy link
Collaborator

okhat commented Feb 25, 2024

That was fast @mgbvox ! And thanks for the check @CShorten — I saw your comment and knew I should merge asap :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants