Skip to content

Commit

Permalink
upload : critical path close to be done
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrotsmnrd committed Oct 18, 2023
1 parent c8b34b4 commit 3dccd3c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
24 changes: 24 additions & 0 deletions ragna/ui/api_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,30 @@ def upload_endpoints(self):
"upload_endpoint": f"{self.api_url}/document",
}

def start_chat(self, name, documents, source_storage, assistant, params={}):
response = self.client.post(
self.api_url + "/chats",
params={"user": self.user},
json={
"name": name,
"documents": documents,
"source_storage": source_storage,
"assistant": assistant,
"params": params,
},
)
return response.json()

def start_and_prepare(self, name, documents, source_storage, assistant, params={}):
chat = self.start_chat(name, documents, source_storage, assistant, params)

result = self.client.post(
self.api_url + f"/chats/{chat['id']}/prepare",
params={"user": self.user},
)

return result.json()

# Helpers

def replace_emoji_shortcodes_with_emoji(self, markdown_string):
Expand Down
11 changes: 9 additions & 2 deletions ragna/ui/left_sidebar.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import panel as pn
import param


class LeftSidebar(pn.viewable.Viewer):
refresh_counter = param.Integer(default=0)

def __init__(self, api_wrapper, **params):
super().__init__(**params)

Expand Down Expand Up @@ -51,6 +54,10 @@ def footer(self):
],
)

def refresh(self):
self.refresh_counter += 1

@pn.depends("refresh_counter")
def __panel__(self):
chats = self.api_wrapper.get_chats()

Expand All @@ -61,6 +68,7 @@ def __panel__(self):
except Exception:
pass

self.chat_buttons = []
for chat in chats:
button = pn.widgets.Button(
name=chat["metadata"]["name"], button_style="outline"
Expand Down Expand Up @@ -164,8 +172,7 @@ def __panel__(self):
background-color: white;
overflow-x: hidden;
height: 100%;
min-width: 220px;
width: 15%;
width:100%;
border-right: 1px solid #EEEEEE;
}
"""
Expand Down
11 changes: 11 additions & 0 deletions ragna/ui/main_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def open_modal(self, template):
def on_click_start_conv_button(self, event, template):
print("on_click_start_conv_button")

self.left_sidebar.refresh()
template.close_modal()

def on_click_cancel_button(self, event, template):
print("on_click_cancel_button")
template.close_modal()
Expand Down Expand Up @@ -111,6 +114,14 @@ def page(self):
height: 100%;
width: 100%;
}
/* Enforces the width of the LeftSidebarn
which is the "first of type" with this class
(first object in the row) */
.bk-panel-models-layout-Column:first-of-type {
min-width: 220px;
width: 15%;
}
"""
],
)
Expand Down
27 changes: 23 additions & 4 deletions ragna/ui/modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ def __init__(self, api_wrapper, **params):

upload_endpoints = self.api_wrapper.upload_endpoints()

informations_endpoint = upload_endpoints["informations_endpoint"]
upload_endpoint = upload_endpoints["upload_endpoint"]

self.document_uploader = FileUploader(
self.api_wrapper.user, informations_endpoint, upload_endpoint
self.api_wrapper.user,
upload_endpoints["informations_endpoint"],
upload_endpoints["upload_endpoint"],
)

# Most widgets (including those that use from_param) should be placed after the super init call
Expand Down Expand Up @@ -72,9 +71,29 @@ def __init__(self, api_wrapper, **params):
self.got_timezone = False

def did_click_on_start_chat_button(self, event):
self.upload_row.append(self.spinner_upload)
self.start_chat_button.disabled = True

def did_finish_upload(uploaded_documents):
# at this point, the UI has uploaded the files to the API.
# We can now start the chat
print("did finish upload", uploaded_documents)

start_chat_result = self.api_wrapper.start_and_prepare(
name=self.chat_name,
documents=uploaded_documents,
source_storage=self.source_storage_name,
assistant=self.assistant_name,
)

print("start_chat_result", start_chat_result)

self.upload_row.remove(self.spinner_upload)
self.start_chat_button.disabled = False

if self.start_button_callback is not None:
self.start_button_callback(event)

self.document_uploader.perform_upload(event, did_finish_upload)

async def model_section(self):
Expand Down

0 comments on commit 3dccd3c

Please sign in to comment.