-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09b3589
commit 0396ff4
Showing
45 changed files
with
2,246 additions
and
339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
2024-02-09 16:20:32,273 - dspy.primitives.assertions - ERROR - AssertionError: You need to create a kwargs dict for HygenTemplateSpecificationCommand | ||
|
||
Validation error: | ||
1 validation error for HygenTemplateSpecificationCommand | ||
template_content | ||
String should have at least 200 characters [type=string_too_short, input_value='This is the template for...he dashboard generator.', input_type=str] | ||
For further information visit https://errors.pydantic.dev/2.5/v/string_too_short | ||
2024-02-09 16:20:34,397 - dspy.primitives.assertions - ERROR - AssertionError: You need to create a kwargs dict for HygenTemplateSpecificationCommand | ||
|
||
Validation error: | ||
invalid syntax. Perhaps you forgot a comma? (<unknown>, line 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
new action for about route |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import dspy | ||
|
||
lm = dspy.OpenAI(max_tokens=2000) | ||
dspy.settings.configure(lm=lm) | ||
|
||
|
||
class GenerateHygenTemplate(dspy.Signature): | ||
"""Generate a Hygen template based on specified requirements. | ||
--- | ||
to: app/emails/<%= name %>.html | ||
--- | ||
Hello <%= name %>, | ||
<%= message %> | ||
(version <%= version %>) | ||
""" | ||
|
||
requirements = dspy.InputField(desc="Specifications or requirements for the Hygen template") | ||
template = dspy.OutputField(desc="Generated Hygen template code") | ||
|
||
|
||
class HygenTemplateGenerator(dspy.Module): | ||
def __init__(self): | ||
super().__init__() | ||
self.generate_template = dspy.ChainOfThought(GenerateHygenTemplate) | ||
|
||
def forward(self, requirements): | ||
# The ChainOfThought could involve parsing the requirements, | ||
# determining the structure and variables needed for the Hygen template, | ||
# and then constructing the template code. | ||
template_code = self.generate_template(requirements=requirements).template | ||
return dspy.Prediction(template=template_code) | ||
|
||
|
||
def main(): | ||
# Example usage | ||
generator = HygenTemplateGenerator() | ||
|
||
# Define your requirements here. This should be a detailed description of what the Hygen template needs to do. | ||
|
||
requirements = """Generate a React component with props, state, and a basic render function. The component should be a functional | ||
component using React Hooks. """ | ||
|
||
# Generate the Hygen template | ||
pred = generator(requirements) | ||
|
||
# Output the generated template | ||
print(f"Generated Hygen Template:\n{pred.template}") | ||
|
||
# Write pred.template to disk | ||
|
||
with open("template.ejs.t", "w") as f: | ||
f.write(pred.template) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import dspy | ||
import os | ||
|
||
from pydantic import Field | ||
from loguru import logger | ||
|
||
from rdddy.actor import Actor | ||
from rdddy.actor_system import ActorSystem | ||
from rdddy.generators.gen_pydantic_instance import GenPydanticInstance | ||
from rdddy.messages import * | ||
|
||
template_content_desc = """ | ||
--- | ||
to: app/emails/<%= name %>.html | ||
--- | ||
Hello <%= name %>, | ||
<%= message %> | ||
(version <%= version %>) | ||
""" | ||
|
||
class HygenTemplateSpecificationCommand(Command): | ||
template_name: str = Field(..., description="The name of the template to generate.") | ||
template_path: str = Field(..., description="The path where the template should be created.") | ||
template_content: str = Field(..., description=template_content_desc, min_length=200) | ||
|
||
|
||
class TemplateGeneratedEvent(Event): | ||
template_name: str = Field(..., description="The name of the generated template.") | ||
success: bool = Field(..., description="Indicates whether the template was successfully generated.") | ||
|
||
|
||
class TemplateValidatedEvent(Event): | ||
template_name: str = Field(..., description="The name of the validated template.") | ||
is_valid: bool = Field(..., description="Indicates the validation result of the template.") | ||
|
||
|
||
class TemplateDeploymentStartedEvent(Event): | ||
template_name: str = Field(..., description="The name of the template being deployed.") | ||
|
||
|
||
class TemplateDeploymentCompletedEvent(Event): | ||
template_name: str = Field(..., description="The name of the deployed template.") | ||
success: bool = Field(..., description="Indicates whether the template was successfully deployed.") | ||
|
||
|
||
class HygenTemplateGeneratorActor(Actor): | ||
async def handle_hygen_template_specification_command(self, command: HygenTemplateSpecificationCommand): | ||
# Generate the Hygen template | ||
try: | ||
self.write_to_file(f"{command.template_path}/{command.template_name}.ejs.t", command.template_content) | ||
logger.debug(f"Hygen template {command.template_name} generated successfully.") | ||
await self.publish(TemplateGeneratedEvent(template_name=command.template_name, success=True)) | ||
except Exception as e: | ||
logger.debug(f"Failed to generate template {command.template_name}: {e}") | ||
await self.publish(TemplateGeneratedEvent(template_name=command.template_name, success=False)) | ||
|
||
def write_to_file(self, file_path: str, content: str): | ||
os.makedirs(os.path.dirname(file_path), exist_ok=True) | ||
with open(file_path, "w") as file: | ||
file.write(content) | ||
|
||
|
||
class TemplateValidationActor(Actor): | ||
async def handle_template_generated_event(self, event: TemplateGeneratedEvent): | ||
if event.success: | ||
# Simulate validation logic | ||
logger.debug(f"Validating template: {event.template_name}") | ||
# Assume validation passes for this example | ||
await self.publish(TemplateValidatedEvent(template_name=event.template_name, is_valid=True)) | ||
|
||
|
||
class TemplateDeploymentActor(Actor): | ||
async def handle_template_validated_event(self, event: TemplateValidatedEvent): | ||
if event.is_valid: | ||
logger.debug(f"Deploying template: {event.template_name}") | ||
# Simulate deployment logic | ||
# Assume deployment succeeds for this example | ||
await self.publish(TemplateDeploymentCompletedEvent(template_name=event.template_name, success=True)) | ||
|
||
|
||
async def setup_and_run(): | ||
actor_system = ActorSystem() | ||
# Initialize and register all actors | ||
await actor_system.actors_of([ | ||
HygenTemplateGeneratorActor, | ||
TemplateValidationActor, | ||
TemplateDeploymentActor | ||
]) | ||
|
||
module = GenPydanticInstance(root_model=HygenTemplateSpecificationCommand) | ||
hygen_inst = module.forward( | ||
"I need a hygen template to create an about page, use the dashboard generator. and the 'new' action. the route is about") | ||
|
||
await actor_system.publish(hygen_inst) | ||
# Trigger the template generation process | ||
# await actor_system.publish(HygenTemplateSpecificationCommand( | ||
# template_name="exampleTemplate", | ||
# template_path="_templates/example/new", | ||
# template_content="---\nto: app/example/<%= name %>.js\n---\nconsole.log('Hello, <%= name %>!')" | ||
# )) | ||
|
||
|
||
import asyncio | ||
|
||
|
||
async def main(): | ||
lm = dspy.OpenAI(max_tokens=2000) | ||
dspy.settings.configure(lm=lm) | ||
|
||
await setup_and_run() | ||
|
||
|
||
# if __name__ == '__main__': | ||
# asyncio.run(main()) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
to: src/components/<%= name %>.js | ||
--- | ||
|
||
import React, { useState } from 'react'; | ||
|
||
const <%= name %> = (props) => { | ||
const [state, setState] = useState(); | ||
|
||
return ( | ||
<div> | ||
{/* Component code here */} | ||
</div> | ||
); | ||
}; | ||
|
||
export default <%= name %>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.