Skip to content

Commit

Permalink
rendering signatures and scraping challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchatmangpt committed Feb 21, 2024
1 parent b885a7a commit 0a6c2b3
Show file tree
Hide file tree
Showing 22 changed files with 609 additions and 38 deletions.
6 changes: 3 additions & 3 deletions src/experiments/actor/abstract_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typetemp.template.render_funcs import render_str

from rdddy.messages import EventStormModel
from rdddy.messages import EventStormingDomainSpecificationModel

base_class_mapping = {
"domain_event_classnames": "Event",
Expand Down Expand Up @@ -35,7 +35,7 @@ class {{ classname }}({{ base_class_name }}):



def generate_class_definitions(model: EventStormModel):
def generate_class_definitions(model: EventStormingDomainSpecificationModel):
for attr, base_class_name in base_class_mapping.items():
classnames = getattr(model, attr, [])
for classname in classnames:
Expand Down Expand Up @@ -64,7 +64,7 @@ def main():
"task_classnames": ["ValidateOrder", "CalculateShippingCosts", "SendOrderConfirmationEmail"],
}

event_storm_model = EventStormModel.model_validate(event_storm_model_data)
event_storm_model = EventStormingDomainSpecificationModel.model_validate(event_storm_model_data)

generate_class_definitions(event_storm_model)

Expand Down
8 changes: 4 additions & 4 deletions src/experiments/event_storm_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def gold_passages_retrieved(example, pred, trace=None):
with names that match the description and domain we are modeling. Class names are CamelCase and unique.
'''

esm = EventStormModel(
esm = EventStormingDomainSpecificationModel(
domain_event_classnames=[
"LanguageModelSetup",
"RetrievalModelSetup",
Expand Down Expand Up @@ -321,7 +321,7 @@ def gold_passages_retrieved(example, pred, trace=None):
def main():
import dspy
from rdddy.messages import (
EventStormModel,
EventStormingDomainSpecificationModel,
)

lm = dspy.OpenAI(max_tokens=3000)
Expand All @@ -332,11 +332,11 @@ def main():

print("Generating EventStorm")

event_storm_model = GenPydanticInstance(root_model=EventStormModel)(prompt=prompt)
event_storm_model = GenPydanticInstance(root_model=EventStormingDomainSpecificationModel)(prompt=prompt)

print(f"Event Storm Model {event_storm_model}")

event_storm_model = EventStormModel(
event_storm_model = EventStormingDomainSpecificationModel(
domain_event_classnames=[
"QuestionAsked",
"AnswerGenerated",
Expand Down
6 changes: 3 additions & 3 deletions src/experiments/example/abstract_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typetemp.template.render_funcs import render_str
import dspy

from rdddy.messages import EventStormModel
from rdddy.messages import EventStormingDomainSpecificationModel

base_class_mapping = {
"domain_event_classnames": "Event",
Expand Down Expand Up @@ -54,7 +54,7 @@ def forward(self, role, classname):
return prediction.description


def generate_verbose_class_definitions(model: EventStormModel, description_generator: VerboseDescriptionGenerator):
def generate_verbose_class_definitions(model: EventStormingDomainSpecificationModel, description_generator: VerboseDescriptionGenerator):

for attr, base_class_name in base_class_mapping.items():
role = attr.replace('_classnames', '') # Simplified role name, adjust as needed
Expand Down Expand Up @@ -86,7 +86,7 @@ def main():
"task_classnames": ["ValidateOrder", "CalculateShippingCosts", "SendOrderConfirmationEmail"],
}

event_storm_model = EventStormModel.model_validate(event_storm_model_data)
event_storm_model = EventStormingDomainSpecificationModel.model_validate(event_storm_model_data)

# generate_class_definitions(event_storm_model)

Expand Down
76 changes: 58 additions & 18 deletions src/experiments/gen_cli_from_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,74 @@ class TyperCLI(BaseModel):
cli_description = """
We are building a Typer CLI application named 'DSPyGenerator'. It should include the following commands:
DSPy Framework CLI v1.0.0
A Ruby on Rails-style framework CLI for streamlined AI application development.
1. Command Name: generate_module
Help: Generates a new DSPy module with a specified name.
USAGE:
dspy [SUBCOMMAND]
2. Command Name: generate_signature
Help: Creates a new signature class for defining input-output behavior in DSPy modules.
SUBCOMMANDS:
new Create a new DSPy project with a default directory structure and configuration.
generate Generate new components within your DSPy project (e.g., modules, datasets, models).
server Start a local server for developing and testing your DSPy application.
test Run tests on your DSPy application, including model evaluations and data validations.
deploy Deploy your DSPy application to various environments (development, testing, production).
db Database operations, such as migrations, seeding, and schema loading.
data Manage your datasets, including import, export, and version control.
eval Evaluate your models or entire pipelines with custom or predefined metrics.
help Displays help information about the available commands.
3. Command Name: generate_chainofthought
Help: Generates a ChainOfThought module with a standard question-answering signature.
EXAMPLES:
# Create a new DSPy project named MyAIApp
dspy new MyAIApp
4. Command Name: generate_retrieve
Help: Generates a Retrieve module for use in information retrieval tasks within DSPy.
# Generate a new data model within the project
dspy generate model MyNewModel
5. Command Name: generate_teleprompter
Help: Creates a teleprompter setup for optimizing DSPy programs.
# Run the development server
dspy server
# Run tests
dspy test
# Deploy your application to production
dspy deploy --environment=production
# Perform database migration
dspy db migrate
# Import a dataset from a file
dspy data import --source=./path/to/dataset.csv
# Evaluate a model with a specific metric
dspy eval --model=MyModel --metric=f1_score
# Display help for the 'generate' subcommand
dspy help generate
For more information on a specific command, use 'dspy [subcommand] --help'.
GLOBAL OPTIONS:
-h, --help Prints help information
-v, --version Prints version information
ENVIRONMENT VARIABLES:
DSPY_ENV Sets the environment for the DSPy CLI (default: development)
CONFIGURATION:
Configuration for the DSPy CLI and projects can be set in `.dspy.yml` within your project directory or global configuration files.
SUPPORT & DOCUMENTATION:
For more details, visit the official DSPy documentation at [DSPy Framework Documentation URL].
For support, reach out to the community forum or issue tracker on our GitHub repository.
6. Command Name: generate_example
Help: Generates an example structure for use in training and testing DSPy modules.
7. Command Name: generate_assertion
Help: Generates a template for creating LM Assertions in DSPy programs.
"""


def main():
lm = dspy.OpenAI(max_tokens=3000)
lm = dspy.OpenAI(max_tokens=3000, model="gpt-4")
dspy.settings.configure(lm=lm)

model = GenPydanticInstance(root_model=TyperCLI, child_models=[TyperCommand]).forward(
Expand Down Expand Up @@ -94,9 +134,9 @@ def test_{{ command.name }}():

# --- Render Templates ---
env = Environment(loader=FileSystemLoader("."))
env.from_string(cli_template).stream(cli_data=cli_data.model_dump()).dump("generated_cli.py")
env.from_string(cli_template).stream(cli_data=cli_data.model_dump()).dump("ror_dspy.py")
env.from_string(pytest_template).stream(cli_data=cli_data.model_dump()).dump(
"test_generated_cli.py"
"test_ror_dspy.py"
)

print("CLI application and tests generated.")
Expand Down
Loading

0 comments on commit 0a6c2b3

Please sign in to comment.