dspy.Signature
to give instructions to the LLM.dspy.Module
to write a simple Text2SQL pipeline.dspy.teleprompt
to automatically optimize the prompt for better results.dspy.Evaluate
to evaluate the results.We used the following system prompt
lm
object and test it before moving forward.
Output
question
or answer
or sql_query
) defines that prompt variable and what the variable is about. More explained below in an example.For this example, we will try to understand class-based DSPy Signatures. You can learn more about Signatures in the official documentation.InputField
and OutputField
, which also describe the nature of those variables.
Output
lm.inspect
method. Here is how it looks like for the Emotion
class.
Output
SQL Output
torch.nn.Module
, which helps compose multiple layers to a single program. Similarly, in DSPy, various modules can be formed into more extensive modules (programs). Now, letβs create a simple module for our Text2SQL generator.
SQL Output
compare_sqls
compares two SQL statements through string manipulation. However, there are better approaches to determining the quality of LLM. A better metric is to run the generated SQL statements inside a database table and see whether the results match the ground truth. However, that is out of the scope of this tutorial.LabeledFewShot
optimizer. It simply constructs a few shot examples (which we call as demos) from provided labelled input and output data points. Letβs see it in action.
dspy.Evaluate
to evaluate our overall system. Here is how we do it: