diff --git a/README.md b/README.md index 29a805c..e69de29 100644 --- a/README.md +++ b/README.md @@ -1,2 +0,0 @@ -# simple_repo_with_compile - diff --git a/auto_classes.json b/auto_classes.json new file mode 100644 index 0000000..bd51156 --- /dev/null +++ b/auto_classes.json @@ -0,0 +1,4 @@ +{ + "AutoConfig": "program.program.ExampleConfig", + "AutoProgram": "program.program.ExampleProgram" +} \ No newline at end of file diff --git a/compile.py b/compile.py new file mode 100644 index 0000000..9fe1c50 --- /dev/null +++ b/compile.py @@ -0,0 +1,9 @@ +import sys + +from program.program import ExampleConfig, ExampleProgram + +if __name__ == "__main__": + username = sys.argv[1] # ← first arg after script name (username) + program = ExampleProgram(ExampleConfig(output_type="str"), runtime_param="hi") + repo_path = f"{username}/simple_repo_with_compile" + program.push_to_hub(repo_path, with_code=True) diff --git a/config.json b/config.json new file mode 100644 index 0000000..d7f9a15 --- /dev/null +++ b/config.json @@ -0,0 +1,6 @@ +{ + "model": null, + "output_type": "str", + "lm": "openai/gpt-4o", + "number": 1 +} \ No newline at end of file diff --git a/include_me_too.txt b/include_me_too.txt new file mode 100644 index 0000000..e69de29 diff --git a/program.json b/program.json new file mode 100644 index 0000000..3964eaf --- /dev/null +++ b/program.json @@ -0,0 +1,42 @@ +{ + "predictor": { + "traces": [], + "train": [], + "demos": [], + "signature": { + "instructions": "Given the fields `question`, `context`, produce the fields `answer`.", + "fields": [ + { + "prefix": "Question:", + "description": "${question}" + }, + { + "prefix": "Context:", + "description": "${context}" + }, + { + "prefix": "Answer:", + "description": "Answer to the question, based on the passage" + } + ] + }, + "lm": { + "model": "openai/gpt-4o", + "model_type": "chat", + "cache": true, + "num_retries": 3, + "finetuning_model": null, + "launch_kwargs": {}, + "train_kwargs": {}, + "temperature": null, + "max_tokens": null + } + }, + "metadata": { + "dependency_versions": { + "python": "3.13", + "dspy": "3.1.2", + "cloudpickle": "3.1" + } + } +} \ No newline at end of file diff --git a/program/__init__.py b/program/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/program/mod.py b/program/mod.py new file mode 100644 index 0000000..6f539dd --- /dev/null +++ b/program/mod.py @@ -0,0 +1,2 @@ +def function_from_mod() -> str: + return "function_from_mod" diff --git a/program/program.py b/program/program.py new file mode 100644 index 0000000..8684003 --- /dev/null +++ b/program/program.py @@ -0,0 +1,32 @@ +from typing import Literal + +import dspy + +from modaic import PrecompiledConfig, PrecompiledProgram + +from .mod import function_from_mod # noqa: F401 + + +class Summarize(dspy.Signature): + question = dspy.InputField() + context = dspy.InputField() + answer = dspy.OutputField(desc="Answer to the question, based on the passage") + + +class ExampleConfig(PrecompiledConfig): + output_type: Literal["bool", "str"] + lm: str = "openai/gpt-4o" + number: int = 1 + + +class ExampleProgram(PrecompiledProgram): + config: ExampleConfig + + def __init__(self, config: ExampleConfig, runtime_param: str, **kwargs): + super().__init__(config, **kwargs) + self.predictor = dspy.Predict(Summarize) + self.predictor.lm = dspy.LM(self.config.lm) + self.runtime_param = runtime_param + + def forward(self, question: str, context: str) -> str: + return self.predictor(question=question, context=context) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9295493 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,11 @@ +[project] +name = "simple_repo_with_compile" +version = "0.1.0" +description = "Add your description here" +readme = "README.md" +requires-python = ">=3.10" +dependencies = ["dspy", "modaic"] + +[tool.uv.sources] +modaic = { workspace = true } +