diff --git a/chatroom/chatroom/chatroom.py b/chatroom/chatroom/chatroom.py index 26ea597d..1e3701e6 100644 --- a/chatroom/chatroom/chatroom.py +++ b/chatroom/chatroom/chatroom.py @@ -91,7 +91,6 @@ def index() -> rx.Component: async def broadcast_event(name: str, payload: t.Dict[str, t.Any] = {}) -> None: """Simulate frontend event with given name and payload from all clients.""" - event_ns = app.sio.namespace_handlers["/event"] responses = [] for state in app.state_manager.states.values(): async for update in state._process( @@ -104,7 +103,7 @@ async def broadcast_event(name: str, payload: t.Dict[str, t.Any] = {}) -> None: ): # Emit the event. responses.append( - event_ns.emit( + app.event_namespace.emit( str(rx.constants.SocketEvent.EVENT), update.json(), to=state.get_sid() ), ) diff --git a/dalle/dalle/dalle.py b/dalle/dalle/dalle.py index 420adb7a..a186ba47 100644 --- a/dalle/dalle/dalle.py +++ b/dalle/dalle/dalle.py @@ -1,8 +1,10 @@ """Welcome to Pynecone! This file outlines the steps to create a basic app.""" -import reflex as rx +import os + import openai +import reflex as rx -openai.api_key = "YOUR_API_KEY" +openai.api_key = os.environ["OPENAI_API_KEY"] class State(rx.State): diff --git a/gpt/gpt/gpt.py b/gpt/gpt/gpt.py index 73f82d66..12c9c604 100644 --- a/gpt/gpt/gpt.py +++ b/gpt/gpt/gpt.py @@ -1,10 +1,13 @@ """Welcome to Reflex! This app is a demonstration of OpenAI's GPT.""" +import datetime +import os + +import openai import reflex as rx + from .helpers import navbar -import openai -import datetime -openai.api_key = "YOUR_API_KEY" +openai.api_key = os.environ["OPENAI_API_KEY"] MAX_QUESTIONS = 10 diff --git a/sales/sales/models.py b/sales/sales/models.py new file mode 100644 index 00000000..2b383a50 --- /dev/null +++ b/sales/sales/models.py @@ -0,0 +1,13 @@ +import reflex as rx + + +class Customer(rx.Model, table=True): + """The customer model.""" + + customer_name: str + email: str + age: int + gender: str + location: str + job: str + salary: int diff --git a/sales/sales/sales.py b/sales/sales/sales.py index 9af46b27..45acdd3f 100644 --- a/sales/sales/sales.py +++ b/sales/sales/sales.py @@ -1,20 +1,12 @@ -import reflex as rx -import openai - -openai.api_key = "YOUR_OPENAI_API_KEY" -products = {'T-shirt': { 'description': 'A plain white t-shirt made of 100% cotton.', 'price': 10.99 }, 'Jeans': { 'description': 'A pair of blue denim jeans with a straight leg fit.', 'price': 24.99 }, 'Hoodie': { 'description': 'A black hoodie made of a cotton and polyester blend.', 'price': 34.99 }, 'Cardigan': { 'description': 'A grey cardigan with a V-neck and long sleeves.', 'price': 36.99 }, 'Joggers': { 'description': 'A pair of black joggers made of a cotton and polyester blend.', 'price': 44.99 }, 'Dress': { 'description': 'A black dress made of 100% polyester.', 'price': 49.99 }, 'Jacket': { 'description': 'A navy blue jacket made of 100% cotton.', 'price': 55.99 }, 'Skirt': { 'description': 'A brown skirt made of a cotton and polyester blend.', 'price': 29.99 }, 'Shorts': { 'description': 'A pair of black shorts made of a cotton and polyester blend.', 'price': 19.99 }, 'Sweater': { 'description': 'A white sweater with a crew neck and long sleeves.', 'price': 39.99}} +import os +import openai +import reflex as rx -class Customer(rx.Model, table=True): - """The customer model.""" +from .models import Customer - customer_name: str - email: str - age: int - gender: str - location: str - job: str - salary: int +openai.api_key = os.environ["OPENAI_API_KEY"] +products = {'T-shirt': { 'description': 'A plain white t-shirt made of 100% cotton.', 'price': 10.99 }, 'Jeans': { 'description': 'A pair of blue denim jeans with a straight leg fit.', 'price': 24.99 }, 'Hoodie': { 'description': 'A black hoodie made of a cotton and polyester blend.', 'price': 34.99 }, 'Cardigan': { 'description': 'A grey cardigan with a V-neck and long sleeves.', 'price': 36.99 }, 'Joggers': { 'description': 'A pair of black joggers made of a cotton and polyester blend.', 'price': 44.99 }, 'Dress': { 'description': 'A black dress made of 100% polyester.', 'price': 49.99 }, 'Jacket': { 'description': 'A navy blue jacket made of 100% cotton.', 'price': 55.99 }, 'Skirt': { 'description': 'A brown skirt made of a cotton and polyester blend.', 'price': 29.99 }, 'Shorts': { 'description': 'A pair of black shorts made of a cotton and polyester blend.', 'price': 19.99 }, 'Sweater': { 'description': 'A white sweater with a crew neck and long sleeves.', 'price': 39.99}} class State(rx.State): @@ -106,7 +98,7 @@ def generate_email( self.generate_email_data["salary"] = salary self.text_area_disabled = True self.gen_response = True - return self.call_openai + return State.call_openai @@ -308,7 +300,7 @@ def index(): # Add state and page to the app. -app = rx.App(state=State) +app = rx.App(state=State, admin_dash=rx.AdminDash(models=[Customer])) app.add_page(index) app.add_page(add_customer, "/onboarding") app.compile()