Skip to content

Commit

Permalink
fix(API) Make FastAPI actually stream results
Browse files Browse the repository at this point in the history
  • Loading branch information
VVoruganti committed Oct 22, 2024
1 parent 9d457d5 commit 0d1dcf1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
3 changes: 2 additions & 1 deletion api/routers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ async def stream(inp: schemas.ConversationInput):
try:
user = honcho.apps.users.get_or_create(app_id=app.id, name=inp.user_id)

async def convo_turn():
# Make method synchronous so it does not await the end of the calls
def convo_turn():
thought = ""
response = ""
try:
Expand Down
49 changes: 23 additions & 26 deletions www/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ export default function Home() {
while (true) {
const { done, value } = await reader.read();
if (done) {
console.log(thought);
setCanSend(true);
break;
}
Expand Down Expand Up @@ -286,9 +285,8 @@ export default function Home() {

return (
<main
className={`flex h-[100dvh] w-screen flex-col pb-[env(keyboard-inset-height)] text-sm lg:text-base overflow-hidden relative ${
isDarkMode ? 'dark' : ''
}`}
className={`flex h-[100dvh] w-screen flex-col pb-[env(keyboard-inset-height)] text-sm lg:text-base overflow-hidden relative ${isDarkMode ? 'dark' : ''
}`}
>
<Sidebar
conversations={conversations || []}
Expand Down Expand Up @@ -357,23 +355,23 @@ export default function Home() {
onReactionAdded={handleReactionAdded}
/>
)) || (
<MessageBox
isUser={false}
message={{
text: '',
id: '',
isUser: false,
metadata: { reaction: null },
}}
loading={true}
setThought={setThought}
setIsThoughtsOpen={setIsThoughtsOpen}
onReactionAdded={handleReactionAdded}
userId={userId}
URL={URL}
conversationId={conversationId}
/>
)}
<MessageBox
isUser={false}
message={{
text: '',
id: '',
isUser: false,
metadata: { reaction: null },
}}
loading={true}
setThought={setThought}
setIsThoughtsOpen={setIsThoughtsOpen}
onReactionAdded={handleReactionAdded}
userId={userId}
URL={URL}
conversationId={conversationId}
/>
)}
</section>
<form
id="send"
Expand All @@ -392,11 +390,10 @@ export default function Home() {
placeholder={
isSubscribed ? 'Type a message...' : 'Subscribe to send messages'
}
className={`flex-1 px-3 py-1 lg:px-5 lg:py-3 bg-gray-100 dark:bg-gray-800 text-gray-400 rounded-2xl border-2 resize-none ${
canSend && isSubscribed
? 'border-green-200'
: 'border-red-200 opacity-50'
}`}
className={`flex-1 px-3 py-1 lg:px-5 lg:py-3 bg-gray-100 dark:bg-gray-800 text-gray-400 rounded-2xl border-2 resize-none ${canSend && isSubscribed
? 'border-green-200'
: 'border-red-200 opacity-50'
}`}
rows={1}
disabled={!isSubscribed}
onKeyDown={(e) => {
Expand Down

0 comments on commit 0d1dcf1

Please sign in to comment.