Use RΞASON with React with ease
tryreason-react
that is the recommend way to integrate with your backend RΞASON app.
tryreason-react
tryreason-react
provides two hooks:
useReason()
: calls RΞASON and returns the results for you (be that streaming or not);useChat()
: this is made for chat-like agents that use the default agent streaming behaviour. When interacting chat-like agents, this is the recommend hook to use.useReason()
hookdata
: The data your app returns;reason
: A function that actually makes the request to your app;onFinish
: A callback to handle when RΞASON stop streaming;onError
: A callback that’ll get called if RΞASON errors;isLoading
: Whenever a request is made but has no streaming response has arrived yet. This will be false
as soon as the first response comes;isStreaming
: This becomes true
when the first streaming byte comes. It remains true
while your app continues to stream more data.reason()
function that useReason()
returns accepts a parameter that can contain some options:
useChat()
hookuseChat()
hook:
MathAgent
we created in the Agents page.
Don't remember about the MathAgent?
sum()
, subtract()
, multiply()
and divide()
actions.Its objective is to use the available actions to solve basic math problems.useChat() in action
messages
: Array containing all the chat messages;input
: The input for the user to type its message;handleInputChange
: The function to pass to <input type="text" onChange={handleInputChange} value={input} />
;handleSubmit
: The function to call when the user wants to send its message;memoryID
: The memory ID of the chat;clear
: A function that when called will clear all messages in order for the user to start a new chat;onFinish
: A callback to handle when RΞASON stop streaming;onError
: A callback that’ll get called if RΞASON errors;isLoading
: Whenever a request is made but has no streaming response has arrived yet. This will be false
as soon as the first response comes;isStreaming
: This becomes true
when the first streaming byte comes. It remains true
while your app continues to stream more data.useReason()
you can also pass some request options to useChat()
:
useChat()
only support using POST
requests.