Reflex custom component chat
Project description
Chat Component
A Reflex custom component chat.
Installation
pip install reflex-chat
Usage
import reflex as rx
from reflex_chat import chat, api
@rx.page()
def index() -> rx.Component:
return rx.container(
rx.box(
chat(process=api.openai()),
height="100vh",
),
size="2",
)
app = rx.App()
- Import the
chat
component to your code.
from reflex_chat import chat
- Specify the
process
function that will be called every time the user submits a question on the chat box. Theprocess
function should be an async function that yields after appending parts of the streamed response.
We have a default process
function that uses the OpenAI API to get the response. You can use it by importing the api
module. Over time we will add more process
functions into the library.
To use the OpenAI API, you need to set the OPENAI_API_KEY
environment variable. You can specify the mdoel with the OPENAI_MODEL
environment variable or pass it as an argument to the api.openai()
function.
chat(process=api.openai(model="gpt-3.5-turbo")),
See below on how to specify your own process
function.
3. Add the `chat` component to your page.
By default the component takes up the full width and height of the parent container. You can specify the width and height of the component by passing the `width` and `height` arguments to the `chat` component.
```python
@rx.page()
def index() -> rx.Component:
return rx.container(
rx.box(
chat(process=api.openai(model="gpt-3.5-turbo")),
height="100vh",
),
size="2",
)
API
The chat component contains all the user interface and state needed for a chat interface. You can create multiple chat components on the same page.
processing
(bool): Whether the chat is processing a request.messages
(List[Dict[str, str]]): A list of messages in the chat in the format{"role": str, "content": str}
.last_user_message
(str): The last message sent by the user.append_to_response
(Callable[[str], None]):
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for reflex_chat-0.0.1a6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c57a6fea9da637687a9902c4a94c6e7afb64824374570e15712d409b92839e53 |
|
MD5 | e56942889f8529a0b95845efaee61483 |
|
BLAKE2b-256 | 3d914ad1fe9d608823004633e1b7bcacac9c2ea2a533038f20ec5af0b8f6077e |