Skip to content

Commit

Permalink
Merge pull request #33 from Significant-Gravitas/ntindle/agpt-258
Browse files Browse the repository at this point in the history
Add DB Block
  • Loading branch information
ntindle authored Feb 17, 2024
2 parents c11021b + d6651dd commit 0bdd515
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"name": "Py: Codex",
"type": "debugpy",
"request": "launch",
"module": "codex"
"module": "codex",
"args": ["serve"]
},
{
"name": "Py: Requirement Gen",
Expand Down
63 changes: 63 additions & 0 deletions codex/prompts/gpt-4-0125-preview/requirements/database/retry.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
Generate a Prisma schema file with the following product spec. Make sure it covers all requirements, roles, Q&A, and auth

Your product spec is as follows:
{{ product_spec }}

Your needed auth roles are:
{{ needed_auth_roles }}

The available modules are:
{{ modules }}


Relational data models will be needed to represent entities as well as defining relationships between them.


For all schemas I provide, you need to make sure they are full schemas with no removals nor shortenings.


Reply in the following format; do not add any extra information. Below is an explination of each section
```json
{
"think": "thoughts about the task, including things that should be included. Notate each model with what modules from the spec are relevant to it",
"anti_think": "thoughts about what shouldn't be included, bad plans and generally things that should be avoided",
"plan": "What do you plan to do focusing on the top-level models? Start with the required enums, then go to the models. Consider the key relationships and core entities. Then, break down each top-level model into relevant details about it. Notate each model with what modules from the spec are relevant to it",
"refine": "refine the plan, and point out issues and gaps. if there's functionality that can't be accomplished with the plan, outline it here. Anything omitted here won't be included in the final product, so it needs to be through. Keep an eye out for things that can be converted to enums or models that are needed",
"pre_answer": {
"tables": [
{
"name": "The name of a table",
"fields": "the, fields, of, the, table, split, by, commas",
"relationships": "ex: Many-to-Many with x, One-to-Many with y and z, etc"
},
... repeat for all needed tables
],
"enums": [
{
"name": "The name of the enum",
"values": "the, values, of, the, enum, split, by, commas"
},
... repeat for all needed enums
]
},
"pre_answer_issues": "list issues with pre_answer. add solutions to them in line",
"full_schema": "improve the schema from pre_answer to include any additional fields needed. output a whole prisma schema. Anything ommited here won't be included in the final product so it needs to be through. Write the combined and full schema here with comments not including the database and generator",
"database_schema": {
"name": "Name of the Schema",
"description": "Description of the Schema",
"tables": [
{
"name": "The name of the prisma table",
"description": "The description of the prisma table",
"definition": "The string prisma definition for the schema"
},
... repeat for all tables in full_schema making sure each is fully defined and valid prisma schemas
]
},
"conclusions": "any concluding thoughts"
}
```

You had an error whilst generating the response:

{{ error }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
You are an expert product owner. You have a deep understanding of the product and its users, and you are able to communicate this understanding to the team.

Respond in the following json format:

{{ json_format }}
59 changes: 59 additions & 0 deletions codex/prompts/gpt-4-0125-preview/requirements/database/user.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Generate a Prisma schema file with the following product spec. Make sure it covers all requirements, roles, Q&A, and auth

Your product spec is as follows:
{{ product_spec }}

Your needed auth roles are:
{{ needed_auth_roles }}

The available modules are:
{{ modules }}


Relational data models will be needed to represent entities as well as defining relationships between them.


For all schemas I provide, you need to make sure they are full schemas with no removals nor shortenings.


Reply in the following format; do not add any extra information. Below is an explination of each section
```json
{
"think": "thoughts about the task, including things that should be included. Notate each model with what modules from the spec are relevant to it",
"anti_think": "thoughts about what shouldn't be included, bad plans and generally things that should be avoided",
"plan": "What do you plan to do focusing on the top-level models? Start with the required enums, then go to the models. Consider the key relationships and core entities. Then, break down each top-level model into relevant details about it. Notate each model with what modules from the spec are relevant to it",
"refine": "refine the plan, and point out issues and gaps. if there's functionality that can't be accomplished with the plan, outline it here. Anything omitted here won't be included in the final product, so it needs to be through. Keep an eye out for things that can be converted to enums or models that are needed",
"pre_answer": {
"tables": [
{
"name": "The name of a table",
"fields": "the, fields, of, the, table, split, by, commas",
"relationships": "ex: Many-to-Many with x, One-to-Many with y and z, etc"
},
... repeat for all needed tables
],
"enums": [
{
"name": "The name of the enum",
"values": "the, values, of, the, enum, split, by, commas"
},
... repeat for all needed enums
]
},
"pre_answer_issues": "list issues with pre_answer. add solutions to them in line",
"full_schema": "improve the schema from pre_answer to include any additional fields needed. output a whole prisma schema. Anything ommited here won't be included in the final product so it needs to be through. Write the combined and full schema here with comments not including the database and generator",
"database_schema": {
"name": "Name of the Schema",
"description": "Description of the Schema",
"tables": [
{
"name": "The name of the prisma table",
"description": "The description of the prisma table",
"definition": "The string prisma definition for the schema"
},
... repeat for all tables in full_schema making sure each is fully defined and valid prisma schemas
]
},
"conclusions": "any concluding thoughts"
}
```
18 changes: 9 additions & 9 deletions codex/requirements/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
UserPersonaClarificationBlock,
UserSkillClarificationBlock,
)
from codex.requirements.blocks.ai_database import DatabaseGenerationBlock
from codex.requirements.blocks.ai_feature import FeatureGenerationBlock
from codex.requirements.blocks.ai_module import ModuleGenerationBlock
from codex.requirements.blocks.ai_requirements import (
Expand Down Expand Up @@ -203,7 +204,6 @@ async def generate_requirements(
)
)

print(requirements_func_nonfunc)
running_state_obj.requirements = requirements_func_nonfunc.answer

print("Requirements Done")
Expand Down Expand Up @@ -235,14 +235,14 @@ async def generate_requirements(
print("Modules 1st Step Done")

# Database Design
running_state_obj.database = None
db_response: DBResponse = complete_and_parse(
MODULE_INTO_INTO_DATABASE.format(
product_spec=running_state_obj.__str__(),
needed_auth_roles=running_state_obj.refined_requirement_q_a.authorization_roles,
modules={", ".join(module.name for module in running_state_obj.modules)},
),
return_model=DBResponse,
database_block = DatabaseGenerationBlock()
db_response: DBResponse = await database_block.invoke(
ids=ids,
invoke_params={
"product_spec": running_state_obj.__str__(),
"needed_auth_roles": running_state_obj.refined_requirement_q_a.authorization_roles,
"modules": ", ".join(module.name for module in running_state_obj.modules),
},
)
running_state_obj.database = unwrap_db_schema(db_response.database_schema)

Expand Down
130 changes: 130 additions & 0 deletions codex/requirements/blocks/ai_database.py

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions codex/requirements/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ def __str__(self) -> str:
return f"Thoughts: {self.think_general}\nAnti:{self.think_anti}\n{answer_str}"


class DBSchemaTableResponseWrapper(BaseModel):
table: DatabaseTable
# class DBSchemaTableResponseWrapper(BaseModel):
# table: DatabaseTable


class DBSchemaResponseWrapper(BaseModel):
Expand All @@ -337,15 +337,20 @@ class DBSchemaResponseWrapper(BaseModel):
# context on what the database schema is
description: str
# list of tables in the database schema
tables: List[DBSchemaTableResponseWrapper] | DBSchemaTableResponseWrapper
tables: List[DatabaseTable]


class PreAnswer(BaseModel):
tables: list[dict[str, str]]
enums: list[dict[str, str]]


class DBResponse(BaseModel):
think: str
anti_think: str
plan: str
refine: str
pre_answer: str
pre_answer: PreAnswer
pre_answer_issues: str
full_schema: str
database_schema: DBSchemaResponseWrapper
Expand Down
7 changes: 2 additions & 5 deletions codex/requirements/unwrap_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
DatabaseSchema,
DatabaseTable,
DBSchemaResponseWrapper,
DBSchemaTableResponseWrapper,
Endpoint,
EndpointDataModel,
EndpointSchemaRefinementResponse,
Expand All @@ -17,10 +16,8 @@
def unwrap_db_schema(input: DBSchemaResponseWrapper) -> DatabaseSchema:
name = input.name
description = input.description
tables: list[DBSchemaTableResponseWrapper] = (
input.tables if isinstance(input.tables, list) else [input.tables]
)
unwrapped_tables: list[DatabaseTable] = [table.table for table in tables]
tables = input.tables
unwrapped_tables: list[DatabaseTable] = [table for table in tables]
return DatabaseSchema(name=name, description=description, tables=unwrapped_tables)


Expand Down

0 comments on commit 0bdd515

Please sign in to comment.