Skip to content

Commit 060cd3e

Browse files
authored
clean up the repo (#53)
* clean up the repo * delete action * make test for export * what * run ruff * add pyright
1 parent 4f97ea1 commit 060cd3e

File tree

12 files changed

+200
-235
lines changed

12 files changed

+200
-235
lines changed

.github/workflows/ci.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: ci
2+
env:
3+
OPENAI_API_KEY: "dummy"
4+
on:
5+
push:
6+
branches: [main]
7+
pull_request:
8+
branches: [main]
9+
10+
jobs:
11+
check-pyright:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Install UV
16+
uses: astral-sh/setup-uv@v6
17+
with:
18+
python-version: "3.10"
19+
enable-cache: true
20+
activate-environment: true
21+
- name: Install Reflex
22+
run: uv pip install -r requirements.txt pyright
23+
- name: Run Pyright
24+
run: pyright .
25+
26+
check-ruff:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v4
30+
- name: Install UV
31+
uses: astral-sh/setup-uv@v6
32+
with:
33+
python-version: "3.10"
34+
enable-cache: true
35+
activate-environment: true
36+
- name: Install Reflex
37+
run: uv pip install -r requirements.txt
38+
- name: Run Ruff
39+
uses: astral-sh/ruff-action@v3
40+
41+
check-export:
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v4
45+
- name: Install UV
46+
uses: astral-sh/setup-uv@v6
47+
with:
48+
python-version: "3.10"
49+
enable-cache: true
50+
activate-environment: true
51+
- name: Install Reflex
52+
run: uv pip install -r requirements.txt
53+
54+
- name: Initialize Reflex
55+
run: reflex init
56+
57+
- name: Build frontend
58+
run: reflex export

.github/workflows/repository_dispatch.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.states
12
assets/external/
23
**/*.db
34
**/*.ipynb
@@ -19,3 +20,4 @@ dist/*
1920
frontend.zip
2021
poetry.lock
2122
venv/
23+
*.env

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ git clone https://github.com/reflex-dev/reflex-chat.git
2424

2525
To get started with Reflex, you'll need:
2626

27-
- Python 3.7+
28-
- Node.js 12.22.0+ \(No JavaScript knowledge required!\)
27+
- Python 3.10+
2928
- Pip dependencies: `reflex`, `openai`
3029

3130
Install `pip` dependencies with the provided `requirements.txt`:
@@ -48,15 +47,16 @@ reflex run
4847
- 100% Python-based, including the UI, using Reflex
4948
- Create and delete chat sessions
5049
- The application is fully customizable and no knowledge of web dev is required to use it.
51-
- See https://reflex.dev/docs/styling/overview for more details
50+
- See https://reflex.dev/docs/styling/overview for more details
5251
- Easily swap out any LLM
5352
- Responsive design for various devices
5453

5554
# Contributing
5655

57-
We welcome contributions to improve and extend the LLM Web UI.
56+
We welcome contributions to improve and extend the LLM Web UI.
5857
If you'd like to contribute, please do the following:
59-
- Fork the repository and make your changes.
58+
59+
- Fork the repository and make your changes.
6060
- Once you're ready, submit a pull request for review.
6161

6262
# License

chat/chat.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
"""The main Chat app."""
22

33
import reflex as rx
4-
import reflex_chakra as rc
54

65
from chat.components import chat, navbar
76

87

98
def index() -> rx.Component:
109
"""The main app."""
11-
return rc.vstack(
10+
return rx.vstack(
1211
navbar(),
1312
chat.chat(),
1413
chat.action_bar(),
1514
background_color=rx.color("mauve", 1),
1615
color=rx.color("mauve", 12),
17-
min_height="100vh",
16+
height="100dvh",
1817
align_items="stretch",
1918
spacing="0",
2019
)
@@ -24,7 +23,7 @@ def index() -> rx.Component:
2423
app = rx.App(
2524
theme=rx.theme(
2625
appearance="dark",
27-
accent_color="violet",
26+
accent_color="purple",
2827
),
2928
)
3029
app.add_page(index)

chat/components/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
from .loading_icon import loading_icon
2-
from .navbar import navbar
1+
from .navbar import navbar as navbar

chat/components/chat.py

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
import reflex as rx
2-
import reflex_chakra as rc
32

4-
from chat.components import loading_icon
53
from chat.state import QA, State
4+
from reflex.constants.colors import ColorType
65

76

8-
message_style = dict(display="inline-block", padding="1em", border_radius="8px", max_width=["30em", "30em", "50em", "50em", "50em", "50em"])
7+
def message_content(text: str, color: ColorType) -> rx.Component:
8+
"""Create a message content component.
9+
10+
Args:
11+
text: The text to display.
12+
color: The color of the message.
13+
14+
Returns:
15+
A component displaying the message.
16+
"""
17+
return rx.markdown(
18+
text,
19+
background_color=rx.color(color, 4),
20+
color=rx.color(color, 12),
21+
display="inline-block",
22+
padding_inline="1em",
23+
border_radius="8px",
24+
)
925

1026

1127
def message(qa: QA) -> rx.Component:
@@ -19,85 +35,72 @@ def message(qa: QA) -> rx.Component:
1935
"""
2036
return rx.box(
2137
rx.box(
22-
rx.markdown(
23-
qa.question,
24-
background_color=rx.color("mauve", 4),
25-
color=rx.color("mauve", 12),
26-
**message_style,
27-
),
38+
message_content(qa["question"], "mauve"),
2839
text_align="right",
29-
margin_top="1em",
40+
margin_bottom="8px",
3041
),
3142
rx.box(
32-
rx.markdown(
33-
qa.answer,
34-
background_color=rx.color("accent", 4),
35-
color=rx.color("accent", 12),
36-
**message_style,
37-
),
43+
message_content(qa["answer"], "accent"),
3844
text_align="left",
39-
padding_top="1em",
45+
margin_bottom="8px",
4046
),
41-
width="100%",
47+
max_width="50em",
48+
margin_inline="auto",
4249
)
4350

4451

4552
def chat() -> rx.Component:
4653
"""List all the messages in a single conversation."""
47-
return rx.vstack(
48-
rx.box(rx.foreach(State.chats[State.current_chat], message), width="100%"),
49-
py="8",
54+
return rx.auto_scroll(
55+
rx.foreach(
56+
State.chats[State.current_chat],
57+
message,
58+
),
5059
flex="1",
51-
width="100%",
52-
max_width="50em",
53-
padding_x="4px",
54-
align_self="center",
55-
overflow="hidden",
56-
padding_bottom="5em",
60+
padding="8px",
5761
)
5862

5963

6064
def action_bar() -> rx.Component:
6165
"""The action bar to send a new message."""
6266
return rx.center(
6367
rx.vstack(
64-
rc.form(
65-
rc.form_control(
66-
rx.hstack(
67-
rx.input(
68-
rx.input.slot(
69-
rx.tooltip(
70-
rx.icon("info", size=18),
71-
content="Enter a question to get a response.",
72-
)
73-
),
74-
placeholder="Type something...",
75-
id="question",
76-
width=["15em", "20em", "45em", "50em", "50em", "50em"],
77-
),
78-
rx.button(
79-
rx.cond(
80-
State.processing,
81-
loading_icon(height="1em"),
82-
rx.text("Send"),
83-
),
84-
type="submit",
68+
rx.form(
69+
rx.hstack(
70+
rx.input(
71+
rx.input.slot(
72+
rx.tooltip(
73+
rx.icon("info", size=18),
74+
content="Enter a question to get a response.",
75+
)
8576
),
86-
align_items="center",
77+
placeholder="Type something...",
78+
id="question",
79+
disabled=State.processing,
80+
flex="1",
81+
),
82+
rx.button(
83+
"Send",
84+
loading=State.processing,
85+
disabled=State.processing,
86+
type="submit",
8787
),
88-
is_disabled=State.processing,
88+
max_width="50em",
89+
margin="0 auto",
90+
align_items="center",
8991
),
90-
on_submit=State.process_question,
91-
reset_on_submit=True,
92+
on_submit=[State.process_question, rx.set_value("question", "")],
9293
),
9394
rx.text(
9495
"ReflexGPT may return factually incorrect or misleading responses. Use discretion.",
9596
text_align="center",
9697
font_size=".75em",
9798
color=rx.color("mauve", 10),
9899
),
99-
rx.logo(margin_top="-1em", margin_bottom="-1em"),
100-
align_items="center",
100+
rx.logo(margin_block="-1em"),
101+
width="100%",
102+
padding_x="16px",
103+
align="stretch",
101104
),
102105
position="sticky",
103106
bottom="0",
@@ -107,6 +110,6 @@ def action_bar() -> rx.Component:
107110
backdrop_blur="lg",
108111
border_top=f"1px solid {rx.color('mauve', 3)}",
109112
background_color=rx.color("mauve", 2),
110-
align_items="stretch",
113+
align="stretch",
111114
width="100%",
112115
)

chat/components/loading_icon.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

chat/components/modal.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)