DSPy: The framework for programming—not prompting—language models
Python
cr
Jerry Liu95547f374440
diff --git a/dspy/predict/__init__.py b/dspy/predict/__init__.pyindex b176d2a0e..2f6397bb6 100644--- a/dspy/predict/__init__.py+++ b/dspy/predict/__init__.py@@ -7,3 +7,4 @@ from .predict import Predictfrom .program_of_thought import ProgramOfThoughtfrom .react import ReActfrom .retry import Retry+from .llamaindex import LlamaIndexModulediff --git a/dspy/predict/llamaindex.py b/dspy/predict/llamaindex.pyindex d5c000250..6b120437e 100644--- a/dspy/predict/llamaindex.py+++ b/dspy/predict/llamaindex.py@@ -50,8 +50,8 @@ def _input_keys_from_template(template: dsp.Template) -> InputKeys:]def _output_keys_from_template(template: dsp.Template) -> InputKeys:- """Get input keys from template."""- # get only fields that are marked OldInputField and NOT OldOutputField+ """Get output keys from template."""+ # get only fields that are marked OldOutputField and NOT OldInputField# template_vars = list(template.kwargs.keys())return [k for k, v in template.kwargs.items() if isinstance(v, dspy.signatures.OldOutputField)diff --git a/examples/llamaindex/dspy_llamaindex_rag.ipynb b/examples/llamaindex/dspy_llamaindex_rag.ipynbindex 7bd1e2050..1dfb6aaef 100644--- a/examples/llamaindex/dspy_llamaindex_rag.ipynb+++ b/examples/llamaindex/dspy_llamaindex_rag.ipynb@@ -170,7 +170,7 @@"outputs": [],"source": ["from llama_index.core.query_pipeline import QueryPipeline as QP, InputComponent, FnComponent\n",- "from llamaindex import DSPyComponent, LlamaIndexModule\n",+ "from dspy.predict.llamaindex import DSPyComponent, LlamaIndexModule\n","\n","dspy_component = DSPyComponent(\n"," dspy.ChainOfThought(GenerateAnswer)\n",@@ -455,25 +455,6 @@"turbo.inspect_history(n=1)"]},- {- "cell_type": "code",- "execution_count": 25,- "id": "ab29598c-2bf5-4472-ab13-43772e678a9f",- "metadata": {- "tags": []- },- "outputs": [],- "source": [- "# from dspy.signatures.signature import signature_to_template\n",- "# from llamaindex import DSPyPromptTemplate\n",- "\n",- "# # tmpl = signature_to_template(compiled_dspy_qp.query_pipeline.module_dict[\"synthesizer\"].predict_module.signature)\n",- "\n",- "# # qa_prompt_tmpl = DSPyPromptTemplate(RAG().generate_answer)\n",- "# qa_prompt_tmpl = DSPyPromptTemplate(compiled_dspy_qp.query_pipeline.module_dict[\"synthesizer\"].predict_module)\n",- "# print(qa_prompt_tmpl.format(query_str=\"hello?\", context_str=\"this is my context\"))"- ]- },{"cell_type": "markdown","id": "9895ceff-5aeb-4285-8ede-99bb35a50a45",@@ -523,7 +504,7 @@"outputs": [],"source": ["from llama_index.core.query_pipeline import QueryPipeline as QP, InputComponent, FnComponent\n",- "from llamaindex import DSPyComponent, LlamaIndexModule\n",+ "from dspy.predict.llamaindex import DSPyComponent, LlamaIndexModule\n","\n","dspy_component = DSPyComponent.from_prompt(qa_prompt_template)\n","\n",@@ -761,7 +742,7 @@},"outputs": [],"source": [- "from llamaindex import DSPyPromptTemplate\n",+ "from dspy.predict.llamaindex import DSPyPromptTemplate\n","\n","# NOTE: you cannot do DSPyPromptTemplate(dspy_component.predict_module) - the predict_module is replaced.\n","qa_prompt_tmpl = DSPyPromptTemplate(compiled_dspy_qp.query_pipeline.module_dict[\"synthesizer\"].predict_module)"