DSPy: The framework for programming—not prompting—language models
Python
Save field metadata
Connor Shorten18125e0986c6
diff --git a/dspy/predict/predict.py b/dspy/predict/predict.pyindex b9827c446..5f86d5e26 100644--- a/dspy/predict/predict.py+++ b/dspy/predict/predict.py@@ -37,6 +37,17 @@ class Predict(Module, Parameter):state["demos"].append(demo)+ fields = []+ for field_key in self.signature.fields.keys():+ field_metadata = self.signature.fields[field_key]+ fields.append({+ "name": field_key,+ "field_type": field_metadata.json_schema_extra["__dspy_field_type"],+ "description": field_metadata.json_schema_extra["desc"],+ "prefix": field_metadata.json_schema_extra["prefix"]+ })+ state["fields"] = fields+# Cache the signature instructions and the last field's name.*_, last_key = self.signature.fields.keys()state["signature_instructions"] = self.signature.instructions@@ -196,10 +207,8 @@ def new_generate(lm, signature, example, max_depth=6, **kwargs):return completions--# TODO: get some defaults during init from the context window?# # TODO: FIXME: Hmm, I guess expected behavior is that contexts can# affect execution. Well, we need to determine whether context dominates, __init__ demoninates, or forward dominates.# Generally, unless overwritten, we'd see n=None, temperature=None.-# That will eventually mean we have to learn them.+# That will eventually mean we have to learn them.\ No newline at end of filediff --git a/dspy/primitives/module.py b/dspy/primitives/module.pyindex 9b723d351..ffdde36d0 100644--- a/dspy/primitives/module.py+++ b/dspy/primitives/module.py@@ -113,21 +113,8 @@ class BaseModule:return objdef dump_state(self):- state = {name: param.dump_state() for name, param in self.named_parameters()}-- # Add fields information- fields = getattr(self, 'fields', None)- if fields:- state['fields'] = [- {- "type": "InputField" if field.is_input else "OutputField",- "field_name": field.name,- "description": field.description- }- for field in fields- ]- state["intervention_test_flag"] = True- return state+ print(self.named_parameters())+ return {name: param.dump_state() for name, param in self.named_parameters()}def load_state(self, state):for name, param in self.named_parameters():@@ -160,4 +147,4 @@ def postprocess_parameter_name(name, value):if name == "_predict":return "self"- return name+ return name\ No newline at end of filediff --git a/dspy/primitives/program.py b/dspy/primitives/program.pyindex a31f9d08f..7a7b61161 100644--- a/dspy/primitives/program.py+++ b/dspy/primitives/program.py@@ -77,4 +77,4 @@ class Module(BaseModule, metaclass=ProgramMeta):def set_attribute_by_name(obj, name, value):magicattr.set(obj, name, value)-Program = Module+Program = Module\ No newline at end of filediff --git a/dspy/signatures/signature.py b/dspy/signatures/signature.pyindex 228a0a552..16c2dc66d 100644--- a/dspy/signatures/signature.py+++ b/dspy/signatures/signature.py@@ -423,4 +423,4 @@ def infer_prefix(attribute_name: str) -> str:else:title_cased_words.append(word.capitalize())- return " ".join(title_cased_words)+ return " ".join(title_cased_words)\ No newline at end of file