Skip to content

Commit 165d910

Browse files
committed
Merge branch 'main' into lendemor/deploy_pipeline
2 parents da6e429 + a87c470 commit 165d910

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

ai_image_gen/ai_image_gen/backend/generation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class GeneratorState(rx.State):
3030
upscaled_image: str = ""
3131
is_downloading: bool = False
3232

33-
@rx.background
33+
@rx.event(background=True)
3434
async def generate_image(self):
3535
try:
3636
# Check if the env variable is set
@@ -102,7 +102,7 @@ async def generate_image(self):
102102
self._reset_state()
103103
yield rx.toast.error(f"Error, please try again: {e}")
104104

105-
@rx.background
105+
@rx.event(background=True)
106106
async def upscale_image(self):
107107
try:
108108
# Check if the env variable is set

sales/sales/backend/backend.py

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
_client = None
5151

52+
5253
def get_openai_client():
5354
global _client
5455
if _client is None:
@@ -63,7 +64,9 @@ class State(rx.State):
6364
current_user: Customer = Customer()
6465
users: list[Customer] = []
6566
products: dict[str, str] = {}
66-
email_content_data: str = "Click 'Generate Email' to generate a personalized sales email."
67+
email_content_data: str = (
68+
"Click 'Generate Email' to generate a personalized sales email."
69+
)
6770
gen_response = False
6871
tone: str = "😊 Formal"
6972
length: str = "1000"
@@ -89,11 +92,13 @@ def load_entries(self) -> list[Customer]:
8992
if self.sort_value:
9093
sort_column = getattr(Customer, self.sort_value)
9194
if self.sort_value == "salary":
92-
order = desc(sort_column) if self.sort_reverse else asc(
93-
sort_column)
95+
order = desc(sort_column) if self.sort_reverse else asc(sort_column)
9496
else:
95-
order = desc(func.lower(sort_column)) if self.sort_reverse else asc(
96-
func.lower(sort_column))
97+
order = (
98+
desc(func.lower(sort_column))
99+
if self.sort_reverse
100+
else asc(func.lower(sort_column))
101+
)
97102
query = query.order_by(order)
98103

99104
self.users = session.exec(query).all()
@@ -118,14 +123,16 @@ def add_customer_to_db(self, form_data: dict):
118123

119124
with rx.session() as session:
120125
if session.exec(
121-
select(Customer).where(
122-
Customer.email == self.current_user["email"])
126+
select(Customer).where(Customer.email == self.current_user["email"])
123127
).first():
124128
return rx.window_alert("User with this email already exists")
125129
session.add(Customer(**self.current_user))
126130
session.commit()
127131
self.load_entries()
128-
return rx.toast.info(f"User {self.current_user['customer_name']} has been added.", position="bottom-right")
132+
return rx.toast.info(
133+
f"User {self.current_user['customer_name']} has been added.",
134+
position="bottom-right",
135+
)
129136

130137
def update_customer_to_db(self, form_data: dict):
131138
self.current_user.update(form_data)
@@ -139,28 +146,38 @@ def update_customer_to_db(self, form_data: dict):
139146
session.add(customer)
140147
session.commit()
141148
self.load_entries()
142-
return rx.toast.info(f"User {self.current_user['customer_name']} has been modified.", position="bottom-right")
149+
return rx.toast.info(
150+
f"User {self.current_user['customer_name']} has been modified.",
151+
position="bottom-right",
152+
)
143153

144154
def delete_customer(self, id: int):
145155
"""Delete a customer from the database."""
146156
with rx.session() as session:
147-
customer = session.exec(
148-
select(Customer).where(Customer.id == id)).first()
157+
customer = session.exec(select(Customer).where(Customer.id == id)).first()
149158
session.delete(customer)
150159
session.commit()
151160
self.load_entries()
152-
return rx.toast.info(f"User {customer.customer_name} has been deleted.", position="bottom-right")
161+
return rx.toast.info(
162+
f"User {customer.customer_name} has been deleted.", position="bottom-right"
163+
)
153164

154-
@rx.background
165+
@rx.event(background=True)
155166
async def call_openai(self):
156167
session = get_openai_client().chat.completions.create(
157168
user=self.router.session.client_token,
158169
stream=True,
159170
model="gpt-3.5-turbo",
160171
messages=[
161-
{"role": "system", "content": f"You are a salesperson at Reflex, a company that sells clothing. You have a list of products and customer data. Your task is to write a sales email to a customer recommending one of the products. The email should be personalized and include a recommendation based on the customer's data. The email should be {self.tone} and {self.length} characters long."},
162-
{"role": "user", "content": f"Based on these {products} write a sales email to {self.current_user.customer_name} and email {self.current_user.email} who is {self.current_user.age} years old and a {self.current_user.gender} gender. {self.current_user.customer_name} lives in {self.current_user.location} and works as a {self.current_user.job} and earns {self.current_user.salary} per year. Make sure the email recommends one product only and is personalized to {self.current_user.customer_name}. The company is named Reflex its website is https://reflex.dev."},
163-
]
172+
{
173+
"role": "system",
174+
"content": f"You are a salesperson at Reflex, a company that sells clothing. You have a list of products and customer data. Your task is to write a sales email to a customer recommending one of the products. The email should be personalized and include a recommendation based on the customer's data. The email should be {self.tone} and {self.length} characters long.",
175+
},
176+
{
177+
"role": "user",
178+
"content": f"Based on these {products} write a sales email to {self.current_user.customer_name} and email {self.current_user.email} who is {self.current_user.age} years old and a {self.current_user.gender} gender. {self.current_user.customer_name} lives in {self.current_user.location} and works as a {self.current_user.job} and earns {self.current_user.salary} per year. Make sure the email recommends one product only and is personalized to {self.current_user.customer_name}. The company is named Reflex its website is https://reflex.dev.",
179+
},
180+
],
164181
)
165182
for item in session:
166183
if hasattr(item.choices[0].delta, "content"):

0 commit comments

Comments
 (0)