mirror of
https://github.com/mruwnik/memory.git
synced 2025-06-29 07:34:43 +02:00
render comics
This commit is contained in:
parent
510cfdf82f
commit
1276b83ffb
@ -9,7 +9,6 @@ const SearchResults = ({ results, isLoading }: { results: any[], isLoading: bool
|
|||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return <Loading message="Searching..." />
|
return <Loading message="Searching..." />
|
||||||
}
|
}
|
||||||
console.log("results",results)
|
|
||||||
return (
|
return (
|
||||||
<div className="search-results">
|
<div className="search-results">
|
||||||
{results.length > 0 && (
|
{results.length > 0 && (
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import { useState, useEffect } from 'react'
|
|
||||||
import ReactMarkdown from 'react-markdown'
|
import ReactMarkdown from 'react-markdown'
|
||||||
import { useMCP } from '@/hooks/useMCP'
|
|
||||||
import { SERVER_URL } from '@/hooks/useAuth'
|
import { SERVER_URL } from '@/hooks/useAuth'
|
||||||
|
|
||||||
export type SearchItem = {
|
export type SearchItem = {
|
||||||
@ -74,25 +72,14 @@ export const MarkdownResult = ({ filename, content, chunks, tags, metadata }: Se
|
|||||||
|
|
||||||
export const ImageResult = ({ filename, tags, metadata }: SearchItem) => {
|
export const ImageResult = ({ filename, tags, metadata }: SearchItem) => {
|
||||||
const title = metadata?.title || filename || 'Untitled'
|
const title = metadata?.title || filename || 'Untitled'
|
||||||
const { fetchFile } = useMCP()
|
|
||||||
const [mime_type, setMimeType] = useState<string>()
|
|
||||||
const [content, setContent] = useState<string>()
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchImage = async () => {
|
|
||||||
const files = await fetchFile(filename)
|
|
||||||
const {mime_type, content} = files[0]
|
|
||||||
setMimeType(mime_type)
|
|
||||||
setContent(content)
|
|
||||||
}
|
|
||||||
fetchImage()
|
|
||||||
}, [filename])
|
|
||||||
return (
|
return (
|
||||||
<div className="search-result-card">
|
<div className="search-result-card">
|
||||||
<h4>{title}</h4>
|
<h4>{title}</h4>
|
||||||
<Tag tags={tags} />
|
<Tag tags={tags} />
|
||||||
<Metadata metadata={metadata} />
|
<Metadata metadata={metadata} />
|
||||||
<div className="image-container">
|
<div className="image-container">
|
||||||
{mime_type && mime_type?.startsWith('image/') && <img src={`data:${mime_type};base64,${content}`} alt={title} className="search-result-image"/>}
|
<img src={`${SERVER_URL}/files/${filename}`} alt={title} className="search-result-image"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -351,11 +351,14 @@ def fetch_file(filename: str) -> dict:
|
|||||||
Text content as string, binary as base64.
|
Text content as string, binary as base64.
|
||||||
"""
|
"""
|
||||||
path = settings.FILE_STORAGE_DIR / filename.strip().lstrip("/")
|
path = settings.FILE_STORAGE_DIR / filename.strip().lstrip("/")
|
||||||
|
print("fetching file", path)
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
raise FileNotFoundError(f"File not found: {filename}")
|
raise FileNotFoundError(f"File not found: {filename}")
|
||||||
|
|
||||||
mime_type = extract.get_mime_type(path)
|
mime_type = extract.get_mime_type(path)
|
||||||
chunks = extract.extract_data_chunks(mime_type, path, skip_summary=True)
|
chunks = extract.extract_data_chunks(mime_type, path, skip_summary=True)
|
||||||
|
print("mime_type", mime_type)
|
||||||
|
print("chunks", chunks)
|
||||||
|
|
||||||
def serialize_chunk(
|
def serialize_chunk(
|
||||||
chunk: extract.DataChunk, data: extract.MulitmodalChunk
|
chunk: extract.DataChunk, data: extract.MulitmodalChunk
|
||||||
|
@ -104,4 +104,4 @@ async def search(
|
|||||||
|
|
||||||
sources = await search_sources(chunks, previews)
|
sources = await search_sources(chunks, previews)
|
||||||
sources.sort(key=lambda x: x.search_score or 0, reverse=True)
|
sources.sort(key=lambda x: x.search_score or 0, reverse=True)
|
||||||
return sources
|
return sources[:limit]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user