Skip to content

Commit

Permalink
Merge pull request #14 from axelpey/readme_new_examples
Browse files Browse the repository at this point in the history
New examples
  • Loading branch information
axelpey authored Feb 9, 2024
2 parents dbebcb5 + fae9e1b commit bfc389d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
28 changes: 22 additions & 6 deletions examples/social_network/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@
app = NaturalFrontend(
app,
openai_api_key=creds["key"],
options=NaturalFrontendOptions(frontend_endpoint=""),
options=NaturalFrontendOptions(
frontend_endpoint="frontend",
personas=[
{
"persona": "Twitter Lover Reader",
"description": "User that loves reading posts on a Twitter-like platform",
},
{
"persona": "Administrator",
"description": "User that can see and change all posts and users",
},
],
),
)


Expand All @@ -35,13 +47,17 @@ class Post(BaseModel):

# Initial data
users = [
User(id=1, email="[email protected]", name="User One"),
User(id=2, email="[email protected]", name="User Two"),
User(id=1, email="[email protected]", name="Axel Peytavin"),
User(id=2, email="[email protected]", name="Pierre"),
User(id=3, email="[email protected]", name="Michelle"),
]
posts = [
Post(id=1, title="Post 1", content="Content of post 1", owner_id=1),
Post(id=2, title="Post 2", content="Content of post 2", owner_id=1),
Post(id=3, title="Post 3", content="Content of post 3", owner_id=2),
Post(id=1, title="I love my dog", content="I love my dog a lot", owner_id=1),
Post(id=2, title="I love my cat", content="He's so cute", owner_id=1),
Post(
id=3, title="Who left the door open?", content="I'm freezing here", owner_id=2
),
Post(id=4, title="I'm so happy", content="I just got a new job", owner_id=3),
]


Expand Down
2 changes: 1 addition & 1 deletion natural_frontend/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from natural_frontend.natural_frontend import NaturalFrontend # noqa
from natural_frontend.natural_frontend import NaturalFrontend # noqa
4 changes: 2 additions & 2 deletions natural_frontend/natural_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,14 @@ def parse_potential_personas(personas: str, retries=5):
"pink",
"lightblue",
], # Replace with your actual colors
"frontend_endpoint": f"gen_{frontend_endpoint}"
"frontend_endpoint": f"{frontend_endpoint}",
},
)

@app.post(f"/gen_{frontend_endpoint}", response_class=HTMLResponse)
async def handle_form(request: Request, persona: str = Form(...)):
scheme = request.url.scheme
server_host = request.headers.get('host')
server_host = request.headers.get("host")
full_url = f"{scheme}://{server_host}"

logging.info(f"Generating frontend for url: {full_url}")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "natural-frontend"
version = "0.0.4"
version = "0.0.5"
authors = [
{ name="Axel Peytavin", email="[email protected]" },
{ name="Pierre Collignon", email="[email protected]" },
Expand Down

0 comments on commit bfc389d

Please sign in to comment.