Skip to content

Commit

Permalink
made to messageDraft to store base64 url instead of blob which is not…
Browse files Browse the repository at this point in the history
… serializable
  • Loading branch information
Royal-lobster committed Nov 26, 2023
1 parent c661cb4 commit 494d9e7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
Binary file modified artifacts/chrome.zip
Binary file not shown.
3 changes: 2 additions & 1 deletion src/components/Sidebar/chat/FilePreviewBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const FilePreviewBar = ({ files, removeFile }: FilePreviewBarProps) => {
return (
<div className="cdx-flex cdx-gap-2 cdx-m-2">
{files.map((file) => {
const imageUrl = URL.createObjectURL(file.blob)
const imageUrl = file.src

return (
<div key={file.id} className="cdx-flex cdx-relative">
<a
Expand Down
5 changes: 2 additions & 3 deletions src/hooks/useChatCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { ChatOpenAI } from 'langchain/chat_models/openai'
import { AIMessage, HumanMessage, SystemMessage } from 'langchain/schema'
import { useMemo, useState } from 'react'
import { AvailableModels, Mode } from '../config/settings'
import { ChatRole, useCurrentChat } from './useCurrentChat'
import { getMatchedContent } from '../lib/getMatchedContent'
import { ChatRole, useCurrentChat } from './useCurrentChat'
import { MessageDraft } from './useMessageDraft'
import { convertBlobToBase64 } from '../lib/convertBlobToBase64'

interface UseChatCompletionProps {
model: AvailableModels
Expand Down Expand Up @@ -108,7 +107,7 @@ export const useChatCompletion = ({
message.files.map(async (file) => {
return {
type: 'image_url',
image_url: await convertBlobToBase64(file.blob),
image_url: file.src,
} as const
}),
)
Expand Down
7 changes: 4 additions & 3 deletions src/hooks/useMessageDraft.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useState } from 'react'
import { getUUID } from '../lib/getUUID'
import { convertBlobToBase64 } from '../lib/convertBlobToBase64'

export interface MessageFile {
id: string
type: string
blob: Blob
src: string
}

export interface MessageDraft {
Expand All @@ -22,11 +23,11 @@ export const useMessageDraft = () => {
setMessageDraft((p) => ({ ...p, text }))
}

const addMessageDraftFile = (blob: Blob) => {
const addMessageDraftFile = async (blob: Blob) => {
const file = {
id: getUUID(),
type: blob.type,
blob,
src: await convertBlobToBase64(blob),
}
setMessageDraft((p) => ({ ...p, files: [...p.files, file] }))
}
Expand Down

0 comments on commit 494d9e7

Please sign in to comment.