Skip to content

Commit

Permalink
refactor: Implement lazy loading for images in DashboardV2 and update…
Browse files Browse the repository at this point in the history
… chat route
  • Loading branch information
Arghya721 committed Aug 6, 2024
1 parent 08d7c07 commit a2fae7a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
13 changes: 4 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
from razorpay.resources.plan import Plan
import tiktoken
from anthropic import Anthropic
from transformers import AutoTokenizer
from vertexai.preview import tokenization


Expand Down Expand Up @@ -791,11 +790,7 @@ async def chat_title(request: ChatRequest, token_info: dict = Depends(verify_tok
"""Chat endpoint for the OpenAI chatbot."""
try:
# Get the chat model from the request and create the corresponding chat instance
chat_model = request.chat_model
chat_config = model_company_mapping.get(chat_model)

if not chat_config:
raise ValueError(f"Invalid chat model: {chat_model}")
chat_config = model_company_mapping.get("gpt-4o-mini")

if chat_config['premium']:
if not verify_active_subscription(token_info):
Expand All @@ -805,8 +800,8 @@ async def chat_title(request: ChatRequest, token_info: dict = Depends(verify_tok
)

chat = chat_config['model'](
model_name=chat_model,
model=chat_model,
model_name="gpt-4o-mini",
model="gpt-4o-mini",
temperature=request.temperature,
)

Expand All @@ -827,7 +822,7 @@ async def chat_title(request: ChatRequest, token_info: dict = Depends(verify_tok
memory.chat_memory.add_ai_message(chat_history.ai_message)

# Run the conversation.invoke method in a separate thread
response = conversation.invoke(input="Generate 5 words sentence title for the above chat. \n Note : do not show creativity")
response = conversation.invoke(input="Generate a concise and relevant 5-word title for the above chat based on the main topic discussed. Do not include any creative or ambiguous terms.")

# clean the response of extra "" or /
response["text"] = response["text"].replace('"', '').replace("/", "")
Expand Down
2 changes: 1 addition & 1 deletion web/src/options/modelOptions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions web/src/pages/DashboardV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const DashboardV2 = () => {
const chatWindowRef = useRef(null);
const { isOpen, onOpen, onClose } = useDisclosure();
const [isPlusSubscriber, setIsPlusSubscriber] = useState(false);
const [freshChat, setFreshChat] = useState(true);

const limitSentence = (sentence) => {
// limit chat title to 30 characters
Expand Down Expand Up @@ -158,6 +159,7 @@ export const DashboardV2 = () => {
'Authorization': `Bearer ${accessToken}`,
},
body: JSON.stringify(requestData),
openWhenHidden: true, // Opt out of visibility handling
onopen(response) {
if (response.ok) {
console.info("Event source connection established");
Expand Down Expand Up @@ -205,7 +207,8 @@ export const DashboardV2 = () => {
setIsStreaming(false);
setShowRetry(true);
setIsLoadingGeneratingChat(false);
if (messages.length === 0) {
if (freshChat) {
setFreshChat(false);
getTitle(userHistory, idChat);
}
},
Expand All @@ -215,6 +218,7 @@ export const DashboardV2 = () => {
setIsLoadingGeneratingChat(false);
setShowRetry(true);
setIsRequestFailed(true);
throw error;
}
});
} catch (error) {
Expand Down Expand Up @@ -616,6 +620,19 @@ export const DashboardV2 = () => {
</div>

<div className="flex justify-center items-center flex-none px-4 sticky bottom-0">
{isRequestFailed ? (
<div style={{ width: '30%' }}> {/* Container to control the width */}
<Button
color="danger"
variant="shadow"
onClick={() => handleRetry(false)}
className="w-full" // Make the button fill the container
startContent={<AiOutlineReload />}
>
Retry
</Button>
</div>
) : (
<InputBar
className="lg:max-w-3xl xl:max-w-4xl px-4 py-2"
userInput={userInput}
Expand All @@ -634,7 +651,7 @@ export const DashboardV2 = () => {
</Button>
}
onKeyDown={handleKeyPress}
/>
/> )}
</div>
</div>

Expand Down

0 comments on commit a2fae7a

Please sign in to comment.