mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-30 19:20:01 +00:00
add check for interleavedContent
Signed-off-by: Kevin <kpostlet@redhat.com>
This commit is contained in:
parent
2976b5d992
commit
36de927fd6
1 changed files with 16 additions and 17 deletions
|
|
@ -118,27 +118,26 @@ async def content_from_doc(doc: RAGDocument) -> str:
|
||||||
if isinstance(doc.content, URL):
|
if isinstance(doc.content, URL):
|
||||||
if doc.content.uri.startswith("data:"):
|
if doc.content.uri.startswith("data:"):
|
||||||
return content_from_data(doc.content.uri)
|
return content_from_data(doc.content.uri)
|
||||||
else:
|
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
r = await client.get(doc.content.uri)
|
r = await client.get(doc.content.uri)
|
||||||
if doc.mime_type == "application/pdf":
|
if doc.mime_type == "application/pdf":
|
||||||
return parse_pdf(r.content)
|
return parse_pdf(r.content)
|
||||||
else:
|
|
||||||
return r.text
|
return r.text
|
||||||
|
elif isinstance(doc.content, str):
|
||||||
pattern = re.compile("^(https?://|file://|data:)")
|
pattern = re.compile("^(https?://|file://|data:)")
|
||||||
if pattern.match(doc.content):
|
if pattern.match(doc.content):
|
||||||
if doc.content.startswith("data:"):
|
if doc.content.startswith("data:"):
|
||||||
return content_from_data(doc.content)
|
return content_from_data(doc.content)
|
||||||
else:
|
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
r = await client.get(doc.content)
|
r = await client.get(doc.content)
|
||||||
if doc.mime_type == "application/pdf":
|
if doc.mime_type == "application/pdf":
|
||||||
return parse_pdf(r.content)
|
return parse_pdf(r.content)
|
||||||
else:
|
|
||||||
return r.text
|
return r.text
|
||||||
|
return doc.content
|
||||||
|
elif isinstance(doc.content, InterleavedContent):
|
||||||
return interleaved_content_as_str(doc.content)
|
return interleaved_content_as_str(doc.content)
|
||||||
|
else:
|
||||||
|
raise ValueError(f"{type(doc)} not supported document.")
|
||||||
|
|
||||||
|
|
||||||
def make_overlapped_chunks(document_id: str, text: str, window_len: int, overlap_len: int) -> List[Chunk]:
|
def make_overlapped_chunks(document_id: str, text: str, window_len: int, overlap_len: int) -> List[Chunk]:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue