DSPy: The framework for programming—not prompting—language models
Python
miprov2 patch for proper parsing
Arnav Singhvi301b67bbedff
diff --git a/dspy/propose/grounded_proposer.py b/dspy/propose/grounded_proposer.pyindex 9edc35113..130c20ad8 100644--- a/dspy/propose/grounded_proposer.py+++ b/dspy/propose/grounded_proposer.py@@ -192,7 +192,7 @@ class GenerateModuleInstruction(dspy.Module):print(f"PROGRAM DESCRIPTION: {program_description}")# Identify all modules- init_pattern = r"def __init__.*?\):([\s\S]*?)(?=\n\s{4}def|\Z)"+ init_pattern = r"def __init__\(.*?\):([\s\S]*?)(?=^\s*def|\Z)"init_content_match = re.search(init_pattern, self.program_code_string)init_content = init_content_match.group(0)pattern = r"^(.*dspy\.(ChainOfThought|Predict).*)$" # TODO: make it so that this extends out to any dspy Modulediff --git a/dspy/teleprompt/utils.py b/dspy/teleprompt/utils.pyindex 15755e3ea..a4eef45a0 100644--- a/dspy/teleprompt/utils.py+++ b/dspy/teleprompt/utils.py@@ -391,7 +391,7 @@ def get_dspy_source_code(module):if item.signature is not None and item.signature.__pydantic_parent_namespace__['signature_name'] + "_sig" not in completed_set:try:header.append(inspect.getsource(item.signature))- except TypeError:+ except (TypeError, OSError):header.append(str(item.signature))completed_set.add(item.signature.__pydantic_parent_namespace__['signature_name'] + "_sig")if isinstance(item, dspy.Module):