Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples to json #10

Merged
merged 11 commits into from
Jun 24, 2024
267 changes: 267 additions & 0 deletions data/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
{
"Examples":
[
{
"Description": "Add two numbers",
"GrasshopperScriptModel":
{
"ChainOfThought": "To add two numbers we need to Add. There is an Addition component that performs this function. We need to create two numbers the user can edit, we can use the Number Slider for both numbers. And then we can Connections all of the components together",
"Advice": "Make sure to set the number sliders to the correct value",
"Components": [
{
"Name": "Number Slider",
"Id": 1,
"Value": "0..25..100"
},
{
"Name": "Number Slider",
"Id": 2,
"Value": "-50..25..100"
},
{
"Name": "Addition",
"Id": 3
}
],
"Connections": [
{
"From": {
"Id": 1,
"ParameterName": "Value"
},
"To": {
"Id": 3,
"ParameterName": "A"
}
},
{
"From": {
"Id": 2,
"ParameterName": "Value"
},
"To": {
"Id": 3,
"ParameterName": "B"
}
}
]
}
},

{
"Description": "Creates a cup shape in grasshopper",
"GrasshopperScriptModel":
{
"ChainOfThought": "To create a cup shape in Grasshopper, we'll first create a circle using a 'Circle CNR' component, which will act as the base of the cup. Then, we will use a 'Move' component to move the base circle vertically to create the upper rim of the cup. To create the body of the cup, we'll loft these two circles using a 'Loft' component.",
"Advice": "Remember, to properly define the cups dimensions using the number slider",
"Components": [
{
"Name": "Circle CNR",
"Id": 1
},
{
"Name": "Move",
"Id": 2
},
{
"Name": "Loft",
"Id": 3
}
],
"Connections": [
{
"From": {
"Id": 1,
"ParameterName": "Circle"
},
"To": {
"Id": 2,
"ParameterName": "Geometry"
}
},
{
"From": {
"Id": 1,
"ParameterName": "Circle"
},
"To": {
"Id": 3,
"ParameterName": "Curves"
}
},
{
"From": {
"Id": 2,
"ParameterName": "Geometry"
},
"To": {
"Id": 3,
"ParameterName": "Curves"
}
}
]
}
},

{
"Description": "creates a twisty skyscraper",
"GrasshopperScriptModel":
{
"ChainOfThought": "We can create the 'twist' using the twist component, so let's extrude a rectangle and twist it!",
"Advice": "Make sure to use reasonable inputs or the skyscraper will look weird",
"Components": [
{
"Name": "Rectangle",
"Id": 1
},
{
"Name": "Number Slider",
"Id": 2,
"Value": "0..50..100"
},
{
"Name": "Unit Z",
"Id": 3
},
{
"Name": "Extrude",
"Id": 4
},
{
"Name": "Number Slider",
"Id": 5,
"Value": "0..90..360"
},
{
"Name": "Line",
"Id": 6
},
{
"Name": "Point",
"Id": 7,
"Value": "{0,0,0}"
},
{
"Name": "Point",
"Id": 8,
"Value": "{0,0,250}"
},
{
"Name": "Twist",
"Id": 9
},
{
"Name": "Solid Union",
"Id": 10
},
{
"Name": "Brep Join",
"Id": 11
}
],
"Connections": [
{
"From": {
"Id": 1,
"ParameterName": "Rectangle"
},
"To": {
"Id": 4,
"ParameterName": "Base"
}
},
{
"From": {
"Id": 2,
"ParameterName": "Value"
},
"To": {
"Id": 3,
"ParameterName": "Factor"
}
},
{
"From": {
"Id": 5,
"ParameterName": "Value"
},
"To": {
"Id": 9,
"ParameterName": "Angle"
}
},
{
"From": {
"Id": 3,
"ParameterName": "Unit vector"
},
"To": {
"Id": 4,
"ParameterName": "Direction"
}
},
{
"From": {
"Id": 4,
"ParameterName": "Extrusion"
},
"To": {
"Id": 9,
"ParameterName": "Geometry"
}
},
{
"From": {
"Id": 7,
"ParameterName": "Point"
},
"To": {
"Id": 6,
"ParameterName": "Start Point"
}
},
{
"From": {
"Id": 8,
"ParameterName": "Point"
},
"To": {
"Id": 6,
"ParameterName": "End Point"
}
},
{
"From": {
"Id": 9,
"ParameterName": "Geometry"
},
"To": {
"Id": 10,
"ParameterName": "Breps"
}
},
{
"From": {
"Id": 10,
"ParameterName": "Result"
},
"To": {
"Id": 11,
"ParameterName": "Breps"
}
},
{
"From": {
"Id": 6,
"ParameterName": "Line"
},
"To": {
"Id": 9,
"ParameterName": "Axis"
}
}
]
}
}
]
}
13 changes: 13 additions & 0 deletions data/examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import json
import os
from models.models import Examples

def load_examples() -> Examples:
# file path needed to work with pytest
dir_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(dir_path, 'examples.json'), 'r') as f:
examples_json = json.load(f)
return Examples.model_validate(examples_json)



14 changes: 9 additions & 5 deletions models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Component(AbstractComponentWithId):
class NumberSlider(AbstractComponentWithId):
Name: Literal["Number Slider"]
Value: str = Field(
None,
"0..2..4",
alias='Value',
description="The range of values for the Number Slider. "
"In the format '<start>..<default>..<end>'. "
Expand All @@ -67,7 +67,7 @@ class NumberSlider(AbstractComponentWithId):
class Panel(AbstractComponentWithId):
Name: Literal["Panel"]
Value: str = Field(
None,
"0,0,0",
alias='Value',
description="The text for the Panel Component. "
"In the format '<text>'"
Expand Down Expand Up @@ -125,7 +125,8 @@ class Connection(BaseModel):

class Strategy(BaseModel):
"""
Detailed and concise Strategy for creating a grasshopper script
Detailed and concise Strategy for creating a grasshopper script.
Make sure to include number sliders for inputs where relevant.
"""
ChainOfThought: str = Field(
...,
Expand All @@ -134,7 +135,7 @@ class Strategy(BaseModel):
"Be specific, avoid making vague statements."
"This strategy needs to give specific instructions that can easily"
"be carried out by a novice grasshopper user, without the need to"
"infer any details"
"infer any details. Make sure to include number sliders for inputs where relevant."
)
Components: List[str] = Field(
...,
Expand Down Expand Up @@ -298,6 +299,9 @@ class Example(BaseModel):
GrasshopperScriptModel: GrasshopperScriptModel


class Examples(BaseModel):
Examples: List[Example]

def find_valid_component_by_name(
valid_components: ValidComponents,
name: str,
Expand Down Expand Up @@ -411,7 +415,7 @@ class StrategyRating(BaseModel):


class ProblemStatement(BaseModel):
inputs: List[str] = Field(
inputs: List[Union[Panel,NumberSlider,Point]] = Field(
...,
description="list of all inputs required for the script to function"
)
Expand Down
12 changes: 6 additions & 6 deletions models/test_gh_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_gh_model_pass():
"input to set the radius",
"Advice": "Adjust the radius of the sphere using a number slider for"
"desired size",
"Additions": [
"Components": [
{
"Name": "Sphere",
"Id": 1
Expand All @@ -28,7 +28,7 @@ def test_gh_model_pass():
},
"From": {
"Id": 2,
"ParameterName": "Number"
"ParameterName": "Value"
}
}
]
Expand All @@ -46,7 +46,7 @@ def test_gh_model_component_fail():
"input to set the radius",
"Advice": "Adjust the radius of the sphere using a number slider for"
"desired size",
"Additions": [
"Components": [
{
"Name": "Sphere",
"Id": 1
Expand All @@ -65,7 +65,7 @@ def test_gh_model_component_fail():
},
"From": {
"Id": 2,
"ParameterName": "Number"
"ParameterName": "Value"
}
}
]
Expand All @@ -82,7 +82,7 @@ def test_gh_model_value_fail():
"input to set the radius",
"Advice": "Adjust the radius of the sphere using a number slider for"
"desired size",
"Additions": [
"Components": [
{
"Name": "Sphere",
"Id": 1,
Expand All @@ -102,7 +102,7 @@ def test_gh_model_value_fail():
},
"From": {
"Id": 2,
"ParameterName": "Number"
"ParameterName": "Value"
}
}
]
Expand Down
Loading
Loading