-
Notifications
You must be signed in to change notification settings - Fork 183
feat: construct resource url from backend #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,22 @@ export function appendImageData(data: StreamData, imageUrl?: string) { | |
}); | ||
} | ||
|
||
function getNodeUrl(metadata: Metadata) { | ||
const url = metadata["URL"]; | ||
if (url) return url; | ||
const fileName = metadata["file_name"]; | ||
leehuwuj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!process.env.FILESERVER_URL_PREFIX) { | ||
console.warn( | ||
"FILESERVER_URL_PREFIX is not set. File URLs will not be generated.", | ||
); | ||
return undefined; | ||
} | ||
if (fileName) { | ||
return `${process.env.FILESERVER_URL_PREFIX}/data/${fileName}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here |
||
} | ||
return undefined; | ||
} | ||
|
||
export function appendSourceData( | ||
data: StreamData, | ||
sourceNodes?: NodeWithScore<Metadata>[], | ||
|
@@ -29,6 +45,7 @@ export function appendSourceData( | |
...node.node.toMutableJSON(), | ||
id: node.node.id_, | ||
score: node.score ?? null, | ||
url: getNodeUrl(node.node.metadata), | ||
})), | ||
}, | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import os | ||
import logging | ||
from pydantic import BaseModel | ||
from typing import List, Any, Optional, Dict, Tuple | ||
from fastapi import APIRouter, Depends, HTTPException, Request, status | ||
|
@@ -38,14 +40,28 @@ class _SourceNodes(BaseModel): | |
metadata: Dict[str, Any] | ||
score: Optional[float] | ||
text: str | ||
url: Optional[str] | ||
|
||
@classmethod | ||
def from_source_node(cls, source_node: NodeWithScore): | ||
metadata = source_node.node.metadata | ||
url = metadata.get("URL") | ||
leehuwuj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if not url: | ||
file_name = metadata.get("file_name") | ||
url_prefix = os.getenv("FILESERVER_URL_PREFIX") | ||
if not url_prefix: | ||
logger = logging.getLogger("uvicorn") | ||
logger.warning("Warning: FILESERVER_URL_PREFIX not set in environment variables") | ||
if file_name and url_prefix: | ||
url = f"{url_prefix}/data/{file_name}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @leehuwuj don't we have |
||
|
||
return cls( | ||
id=source_node.node.node_id, | ||
metadata=source_node.node.metadata, | ||
metadata=metadata, | ||
score=source_node.score, | ||
text=source_node.node.text, # type: ignore | ||
url=url | ||
) | ||
|
||
@classmethod | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,22 @@ export function appendImageData(data: StreamData, imageUrl?: string) { | |
}); | ||
} | ||
|
||
function getNodeUrl(metadata: Metadata) { | ||
const url = metadata["URL"]; | ||
leehuwuj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (url) return url; | ||
const fileName = metadata["file_name"]; | ||
if (!process.env.FILESERVER_URL_PREFIX) { | ||
console.warn( | ||
"FILESERVER_URL_PREFIX is not set. File URLs will not be generated.", | ||
); | ||
return undefined; | ||
} | ||
if (fileName) { | ||
return `${process.env.FILESERVER_URL_PREFIX}/data/${fileName}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here? |
||
} | ||
return undefined; | ||
} | ||
|
||
export function appendSourceData( | ||
data: StreamData, | ||
sourceNodes?: NodeWithScore<Metadata>[], | ||
|
@@ -29,6 +45,7 @@ export function appendSourceData( | |
...node.node.toMutableJSON(), | ||
id: node.node.id_, | ||
score: node.score ?? null, | ||
url: getNodeUrl(node.node.metadata), | ||
})), | ||
}, | ||
}); | ||
|
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.